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. Shell数组相关操作

    参考:http://www.cnblogs.com/chengmo/archive/2010/09/30/1839632.html 创建数组 a=( ) 获得数组长度 ${#a[@]} #${#变量} ...

  2. 查看Android应用包名package和入口activity名称

    使用android自动化测试工具启动应用时,需要填写被测程序的包名和启动的Activity,以下有两种查看应用包名package和入口activity名称的方法: 方法一:使用aapt    //aa ...

  3. zpf 获取表单等数据的用法

    2015年4月12日 12:25:35 星期日 zpf框架中获取表单数据的方法 //获得get,post,url中的数据 private function setData() { $this-> ...

  4. Python字符编码

    http://www.runoob.com/python/python-strings.html ASCII Unicode UTF-8 # -*- coding: utf-8 -*- 格式化 %运算 ...

  5. HDU 4870 Rating(概率、期望、推公式) && ZOJ 3415 Zhou Yu

    其实zoj 3415不是应该叫Yu Zhou吗...碰到ZOJ 3415之后用了第二个参考网址的方法去求通项,然后这次碰到4870不会搞.参考了chanme的,然后重新把周瑜跟排名都反复推导(不是推倒 ...

  6. 【C语言】二维指针做形参

    转自:http://hi.baidu.com/gpmzccqceabimqq/item/f499f057aa1520404eff208b 关键: 传入时强制类型转换 + 使用时自己手工寻址 今天写程序 ...

  7. 【网络】VPN和代理服务器的区别

    来自:http://www.zhihujingxuan.com/19311.html [scotttony的回答(41票)]: VPN和ssh哪个比较好, 要看你怎么定义是“好”. ssh作为一个创建 ...

  8. 51nod 1605 棋盘问题 (博弈)

    题目:传送门. 题意:中文题.T组数据,每组给定一个n*m的棋盘,棋盘中的1代表黑色,0代表白色,每次可以将1或者非2质数的全黑色方形区域变为白色,不能操作者输,问谁能赢. 题解:每次可以将1或者非2 ...

  9. 【XLL 框架库函数】 Excel/Excel12f

    Excel/Excel12f 这两个库函数分别包装了 C API 中的 Excel4 和 Excel12 函数,它们会检查函数没有参数时是否为零,它将表明创建临时的 XLOPER 或 XLOPER12 ...

  10. curl命令 抓取网络数据相应头

    curl --verbose  --data "Password=123&Username=158101068&url=http://m.vancl.com/" & ...