Countries  

描述

There are two antagonistic countries, country A and country B. They are in a war, and keep launching missiles towards each other.

It is known that country A will launch N missiles. The i-th missile will be launched at time Tai. It flies uniformly and take time Taci from one country to the other. Its damage capability is Dai.

It is known that country B will launch M missiles. The i-th missile will be launched at time Tbi.

It flies uniformly and takes time Tbci from one country to the other. Its damage capability is Dbi.

Both of the countries can activate their own defending system.

The defending system of country A can last for time TA, while The defending system of country B can last for time TB.

When the defending system is activated, all missiles reaching the country will turn around and fly back at the same speed as they come.

At other time, the missiles reaching the country will do damages to the country.
(Note that the defending system is still considered active at the exact moment it fails)

Country B will activate its defending system at time X.

When is the best time for country A to activate its defending system? Please calculate the minimal damage country A will suffer.

输入

There are no more than 50 test cases.

For each test case:

The first line contains two integers TA and TB, indicating the lasting time of the defending system of two countries.

The second line contains one integer X, indicating the time that country B will active its defending system.

The third line contains two integers N and M, indicating the number of missiles country A and country B will launch.

Then N lines follow. Each line contains three integers Tai, Taci and Dai, indicating the launching time, flying time and damage capability of the i-th missiles country A launches.

Then M lines follow. Each line contains three integers Tbi, Tbci and Dbi, indicating the launching time, flying time and damage capability of the i-th missiles country B launches.

0 <= TA, TB, X, Tai, Tbi<= 100000000

1 <= Taci, Tbci <= 100000000

0 <= N, M <= 10000

1 <= Dai, Dbi <= 10000

输出

For each test case, output the minimal damage country A will suffer.

提示

In the first case, country A should active its defending system at time 3.

Time 1: the missile is launched by country A.

Time 2: the missile reaches country B, and country B actives its defending system, then the missile turns around.

Time 3: the missile reaches country A, and country A actives its defending system, then the missile turn around.

Time 4: the missile reaches country B and turns around.

Time 5: the missile reaches country A and turns around.

Time 6: the missile reaches country B, causes damages to country B.

样例输入
2 2
2
1 0
1 1 10
4 5
3
2 2
1 2 10
1 5 7
1 3 2
0 4 8
样例输出
0
17
 题意:
     

题解:

  关键点就在于要:假设出A时刻处于防御状态

  那么我们可以O(1)处理出 每一个导弹最开始砸向A,最后一次砸向A 形成些许个区间段,当防御系统完全覆盖这段的时候 才可以避免这只导弹

  那么就等于 确定一个长度K的 使得 这个避免的 导弹伤害最大

  这个可以前缀和做出来

  队友提示了 树状数组做法

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
using namespace std; #pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define mid ((ll+rr)>>1)
#define pii pair<int,int>
#define MP make_pair typedef long long LL;
const long long INF = 1e18;
const double Pi = acos(-1.0);
const int N = 1e6+, M = 1e2+, mod = 1e9+, inf = 2e9; LL n,m,end_b,C[N],star_b,ans,sum[N],san[N];
LL V[N]; int all;
int numa,numb;
struct node {
LL fi,se,d;
node() {}
node(LL fi,LL se,LL d) {
this->fi=fi;this->se=se;this->d=d;
}
bool operator < (const node &r) const {
return se<r.se;
}
};
vector< node > G;
vector< pii > E[N];
map< LL , int > mp; LL haxi(LL x) {
return lower_bound(san+,san+all+,x) - san;
}
LL ask(int x) {
LL S = ;
if(x <= ) return ;
for(int i = x; i; i-=i&(-i)) S += C[i];
return S;
}
void update(int x,LL c) {
for(int i = x; i< N; i+=i&(-i)) C[i] += c;
}
int main() {
while(scanf("%lld%lld",&n,&m)!=EOF) {
scanf("%lld",&star_b);
end_b = star_b+m; ans = ;G.clear();mp.clear();
memset(C,,sizeof(C));
for(int i = ; i< N; ++i) E[i].clear(); scanf("%d%d",&numa,&numb);
for(int i = ; i <= numa; ++i) {
LL s,t,d;
scanf("%lld%lld%lld",&s,&t,&d);
if(s+t < star_b) {
ans += ;
} else if(s+t > end_b) ans+=;
else {
LL fi = s+*t,se;
if(end_b <= fi) se = fi;
else {
LL mo = (end_b - fi)% (*t);
LL md = (end_b - fi)/(*t);
if(mo < t) {
se = md*(*t) + fi;
} else {
se = (md+)*(t*) + fi;
}
}
G.push_back(node{fi,se,d});//cout<<fi<<" "<<se<<endl;
}
} for(int i = ; i <= numb; ++i) {
LL s,t,d;
scanf("%lld%lld%lld",&s,&t,&d);
LL fi = s+t;
if(s+t+t < star_b) {
G.push_back(node{fi,fi,d});
} else if(s+t+t > end_b) {
G.push_back(node{fi,fi,d});
}
else {
LL se;
if(end_b <= fi) se = fi;
else {
LL mo = (end_b - fi)% (*t);
LL md = (end_b - fi)/(*t);
if(mo < t) {
se = md*(*t) + fi;
} else {
se = (md+)*(t*) + fi;
}
}
G.push_back(node{fi,se,d});
}
}
all = ;
LL sumall = ;
for(int i = ; i < G.size(); ++i) {
san[++all] = G[i].fi;
san[++all] = G[i].se;
san[++all] = G[i].se - n;
sumall += G[i].d;
}
sort(san+,san+all+);
all = unique(san+,san+all+) - san - ;
LL ans2 = ;
sort(G.begin(),G.end());
for(int i = ; i < G.size(); ++i) {
int pos = haxi(G[i].se);
update(haxi(G[i].fi),G[i].d);
ans2 = max(ans2,ask(pos) - ask(haxi(G[i].se-n)-));
}
printf("%lld\n",ans + sumall - ans2); }
return ;
} /* 0 0
1
0 2
5 1 100
6 1 100 0 0
3
1 1
1 2 10
2 3 8
0 0
4
1 1
1 2 10
2 3 8
2 2
2
1 0
1 1 10
4 5
3
2 2
1 2 10
1 5 7
1 3 2
0 4 8
*/

2016北京网络赛 hihocoder 1391 Countries 树状数组的更多相关文章

  1. 2016 大连网赛---Weak Pair(dfs+树状数组)

    题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=5877 Problem Description You are given a rooted ...

  2. 2018 CCPC网络赛 1010 hdu 6447 ( 树状数组优化dp)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=6447 思路:很容易推得dp转移公式:dp[i][j] = max(dp[i][j-1],dp[i-1][j ...

  3. HDU 6203 2017沈阳网络赛 LCA,DFS+树状数组

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6203 题意:n+1 个点 n 条边的树(点标号 0 ~ n),有若干个点无法通行,导致 p 组 U V ...

  4. 2016 10 28考试 dp 乱搞 树状数组

    2016 10 28 考试 时间 7:50 AM to 11:15 AM 下载链接: 试题 考试包 这次考试对自己的表现非常不满意!! T1看出来是dp题目,但是在考试过程中并没有推出转移方程,考虑了 ...

  5. 2016 Multi-University Training Contest 4 Bubble Sort(树状数组模板)

    Bubble Sort 题意: 给你一个1~n的排列,问冒泡排序过程中,数字i(1<=i<=n)所到达的最左位置与最右位置的差值的绝对值是多少 题解: 数字i多能到达的最左位置为min(s ...

  6. 第十二届湖南省赛G - Parenthesis (树状数组维护)

    Bobo has a balanced parenthesis sequence P=p 1 p 2…p n of length n and q questions. The i-th questio ...

  7. luogu3250 网络 (整体二分+树上差分+树状数组)

    首先整体二分,问题变成是否存在经过一个点的满足条件的路径 那么我对于每个路径(a,b,lca),在树状数组的dfn[a]++,dfn[b]++,dfn[lca]--,dfn[fa[lca]--] 然后 ...

  8. ACM-ICPC 2018 沈阳赛区网络预赛 J. Ka Chang(树状数组+分块)

    Given a rooted tree ( the root is node 1 ) of N nodes. Initially, each node has zero point. Then, yo ...

  9. ACM-ICPC 2018 徐州赛区网络预赛 G. Trace【树状数组维护区间最大值】

    任意门:https://nanti.jisuanke.com/t/31459 There's a beach in the first quadrant. And from time to time, ...

随机推荐

  1. 关于 strcpy 段错误

    int main(){ char * s = "hello,world" ; char *t = "happy"; strcpy(s,t) ; // error ...

  2. How to take partial screenshot with Selenium WebDriver in python

    from selenium import webdriver from PIL import Image fox = webdriver.Firefox() fox.get('http://stack ...

  3. spring + myBatis 常见错误:@Autowired注解失败

    今天配置spring+myBatis的时候,使用注解@Autowired把持久层dao注入service层的时候总是报错. 查了好久才发现,居然是配置文件路径写错了.basepackge的路径一定要正 ...

  4. ACM/ICPC 之 并查集-食物链(POJ1182)

    并查集的经典题型,POJ上题目还是中文= =,一般看到中文题都会感觉不太简单,这道题的数学归纳用得比较多,可以简化代码,挺有意思的. 同类型的题目还有POJ1703,比这个要简单,想了解并查集基本介绍 ...

  5. ffmpeg-20160726-bin.7z

    ESC 退出 0 进度条开关 1 屏幕原始大小 2 屏幕1/2大小 3 屏幕1/3大小 4 屏幕1/4大小 S 下一帧 [ -2秒 ] +2秒 ; -1秒 ' +1秒 下一个帧 -> -5秒 f ...

  6. hiho一下第一周 最长回文子串

    题目链接:http://hihocoder.com/contest/hiho1/problem/1 #include <iostream> #include <cstdio> ...

  7. codeforces 490C. Hacking Cypher 解题报告

    题目链接:http://codeforces.com/problemset/problem/490/C 题目意思:给出一个可能有10^6 位长的字符串且没有前导0的整数,问能否一分为二,使得前面的一部 ...

  8. C#实现MD5加密

    摘自:http://blog.csdn.net/shenghui188/archive/2010/03/28/5423959.aspx 方法一 首先,先简单介绍一下MD5 MD5的全称是message ...

  9. LeetCode 263 Ugly Number

    Problem: Write a program to check whether a given number is an ugly number. Ugly numbers are positiv ...

  10. ODBC连接发生错误:未发现数据源名称并且未指定默认驱动程序

    程序在使用ODBC方式连接数据库时发生错误: ERROR [IM002] [Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序. 什么原因造成的呢? 本人使用&l ...