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. linux 共享内存实现

    说起共享内存,一般来说会让人想起下面一些方法:1.多线程.线程之间的内存都是共享的.更确切的说,属于同一进程的线程使用的是同一个地址空间,而不是在不同地址空间之间进行内存共享:2.父子进程间的内存共享 ...

  2. MyEclipse8.5破解方法

    本文是转自其它博文,用以留着备份的~ Step: 1.建立一个任意名称的Java Project 2.在该工程中建立一个名文MyEclipseGen的Java文件(MyEclipseGen.java) ...

  3. supersr--NSURLConnection iOS2.0苹果原生请求

    get请求1:   NSURL*url = [NSURLURLWithString:@"http://127.0.0.1/demo.json"];        NSURLRequ ...

  4. [Android Pro] CountDownTimer倒计时

    定时执行在一段时候后停止的倒计时,在倒计时执行过程中会在固定间隔时间得到通知(译者:触发onTick方法),下面的例子显示在一个文本框中显示一个30s倒计时: new CountdownTimer(3 ...

  5. October 8th 2016 Week 41st Saturday

    When ambition ends, happiness begins. 野心消亡之日,正是快乐破茧之时. If I don't have the wish to be a useful man, ...

  6. css3属性flex弹性布局设置三列(四列)分布样式

    参考:阮一峰的网络日志 <!doctype html> <html lang="en"> <head> <meta charset=&qu ...

  7. 3DS MAX调慢摄像机动画

    在3ds max的右下角找到时间配置,然后出现该对话框,然后调整结束时间,将原来的时间翻倍,就能够是摄像机动画变慢. 下图的旋转速度比上图慢一半.

  8. Codeforces Round #344 (Div. 2)(按位或运算)

    Blake is a CEO of a large company called "Blake Technologies". He loves his company very m ...

  9. DB2 bind on z/os

    BIND and REBIND options for packages and plans There are several options you can use for binding or ...

  10. PHP数据库操作

    PHP实现数据库的增删改查 <?php $conn=mysql_connect('localhost','root','root'); if(!$conn){ echo "connec ...