2016北京网络赛 hihocoder 1391 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 树状数组的更多相关文章
- 2016 大连网赛---Weak Pair(dfs+树状数组)
题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=5877 Problem Description You are given a rooted ...
- 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 ...
- HDU 6203 2017沈阳网络赛 LCA,DFS+树状数组
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6203 题意:n+1 个点 n 条边的树(点标号 0 ~ n),有若干个点无法通行,导致 p 组 U V ...
- 2016 10 28考试 dp 乱搞 树状数组
2016 10 28 考试 时间 7:50 AM to 11:15 AM 下载链接: 试题 考试包 这次考试对自己的表现非常不满意!! T1看出来是dp题目,但是在考试过程中并没有推出转移方程,考虑了 ...
- 2016 Multi-University Training Contest 4 Bubble Sort(树状数组模板)
Bubble Sort 题意: 给你一个1~n的排列,问冒泡排序过程中,数字i(1<=i<=n)所到达的最左位置与最右位置的差值的绝对值是多少 题解: 数字i多能到达的最左位置为min(s ...
- 第十二届湖南省赛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 ...
- luogu3250 网络 (整体二分+树上差分+树状数组)
首先整体二分,问题变成是否存在经过一个点的满足条件的路径 那么我对于每个路径(a,b,lca),在树状数组的dfn[a]++,dfn[b]++,dfn[lca]--,dfn[fa[lca]--] 然后 ...
- 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 ...
- ACM-ICPC 2018 徐州赛区网络预赛 G. Trace【树状数组维护区间最大值】
任意门:https://nanti.jisuanke.com/t/31459 There's a beach in the first quadrant. And from time to time, ...
随机推荐
- Find celebrity
Suppose you are at a party with n people (labeled from 0 to n - 1) and among them, there may exist o ...
- select count(*)和select count(1)的区别
一般情况下,Select Count (*)和Select Count(1)两着返回结果是一样的 假如表沒有主键(Primary key), 那么count(1)比count(*)快, 如果有主键的話 ...
- 关于Intent ,Task, Activity的理解
看到一篇好文章,待加工 http://hi.baidu.com/jieme1989/item/6e5f41d3f65be848ddf9beb9 第三篇 http://blog.csdn.net/luo ...
- HBase集成Zookeeper集群部署
大数据集群为了保证故障转移,一般通过zookeeper来整体协调管理,当节点数大于等于6个时推荐使用,接下来描述一下Hbase集群部署在zookeeper上的过程: 安装Hbase之前首先系统应该做通 ...
- [NSURLConnection]分别用Post和Get方式获取网络数据并把数据显示到表格
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate> { UIButton* getButton; ...
- [转载]Masonry介绍与使用实践(快速上手Autolayout)
原博地址 http://adad184.com/2014/09/28/use-masonry-to-quick-solve-autolayout/ 前言 1 MagicNumber -> aut ...
- DP:Cow Exhibition(POJ 2184)(二维问题转01背包)
牛的展览会 题目大意:Bessie要选一些牛参加展览,这些牛有两个属性,funness和smartness,现在要你求出怎么选,可以使所有牛的smartness和funness的最大,并且这两 ...
- 【jquery】一个简单的单选、多选、全选、反选、删除的小功能
对表格内容进行单行删除.单行选中.多行选中.全选.反选.删除选中行等操作 HTML代码 <table class="table table-bordered border-shadow ...
- Windows Form 中快捷键设置
在Windows Form程序中使用带下划线的快捷键只需要进行设置: 就能够工作.
- !对c++类的理解
c++的类可以分为两类,一种是entity的类(i.e.,实体类),一种是function的类(i.e.,功能类). 对于构造entity的类,包括这种entity的属性已经它本身具备的功能: 而fu ...