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. ACM/ICPC 之 DP-基因相似度(POJ1080-ZOJ1027)

    题意:两端基因片段,各有明确的碱基序列,现有一个碱基匹配的相似度数组,设计程序使得该相似度最大. //POJ1080-ZOJ1027 //题解:将s1碱基和s2碱基看做等长,添加一个碱基为'-',即每 ...

  2. Java for LeetCode 207 Course Schedule【Medium】

    There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prer ...

  3. Effective C++ -----条款40:明智而审慎地使用多重继承

    多重继承比单一继承复杂.它可能导致新的歧义性,以及对virtual继承的需要. virtual继承会增加大小.速度.初始化(及赋值)复杂度等等成本.如果virtual base classes不带任何 ...

  4. jboss服务器修改端口说明

    如果一台机器安装多个jboss服务器,就需要修改服务器的端口号,否则各个服务器之间会有冲突.目前确认需要修改的配置如下一.vi $JBOSS_HOME/server/default/conf/jbos ...

  5. Android异步加载访问网络图片-解析json

    来自:http://www.imooc.com/video/7871 推荐大家去学习这个视频,讲解的很不错. 慕课网提供了一个json网址可以用来学习:http://www.imooc.com/api ...

  6. 【linux】英文显示乱码解决

    在linux环境中中文显示正常,而英文却显示乱码 用 echo $LANG 显示编码为 zh_CN.GB18030 解决方法: 输入 export LC_ALL=POSIX 即可

  7. CodeSign error: code signing is required for product type Application in SDK iOS

    在真机测试的时候往往会突然出现这样一个错误,code signing is required for product type 'Application' in SDK 'iOS 7.0'  ,就是说 ...

  8. Elo rating system 模拟

    package org.cc.foo_008; import java.util.ArrayList; import java.util.List; import java.util.Random; ...

  9. Html和CSS的关系

    1. HTML是网页内容的载体.内容就是网页制作者放在页面上想要让用户浏览的信息,可以包含文字.图片.视频等. 2. CSS样式是表现.就像网页的外衣.比如,标题字体.颜色变化,或为标题加入背景图片. ...

  10. Clr Via C#读书笔记---计算限制的异步操作

    线程池基础 1,线程的创建和销毁是一个昂贵的操作,线程调度以及上下文切换耗费时间和内存资源. 2,线程池是一个线程集合,供应你的用程序使用. 3,每个CLR有一个自己的线程池,线程池由CLR控制的所有 ...