#1391 : Countries

时间限制:1000ms
单点时限:1000ms
内存限制:256MB

描述

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
/*
hihocoder 1391 树状数组 problem:
A,B两个敌对国分别有1W个导弹,每个导弹有各自的发射时间、飞行时间、造成伤害。两国各有一个防御系统,
且分别有各自的持续时间(相当于防御一个时间区间?),开启防御系统时,所有到达该国的导弹按原速度反向。
已知B国在X时间点开启防御系统,问A国最少会受多少的伤害。(以上数值伤害1e4,其余1e8) solve:
昨天比赛心态爆炸.......Orz
因为导弹可以在两个国家之间互相弹来弹去. 我们可以计算出这个导弹最早攻击到A的时间l和最晚到达A的时间r(假设A防御时间无限)
如果开启防御后无法覆盖[l,r]那么这个导弹总会攻击到A.
然后问题就成了已知很多个区间的价值,完全覆盖是能够得到价值.求长度为len的区间最多能得到多少价值.
所以可以通过树状数组来解决了.
如果从小到大枚举r,找出以当前点为右端点能覆盖多少的值.
那么每次就要将区间的值赋予l,因为只有左端点小于等于l时才覆盖这个区间. //比赛时少了个判断, 而且求k值错了...卒 hhh-2016-09-25 15:22:55
*/
#pragma comment(linker,"/STACK:124000000,124000000")
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <math.h>
#define lson i<<1
#define rson i<<1|1
#define ll long long
#define clr(a,b) memset(a,b,sizeof(a))
#define key_val ch[ch[root][1]][0]
using namespace std;
#define mod 1004535809LL const int maxn = 5e5;
int n,m,k;
ll ta,tb,x;
ll u,v,w,y,tot; map<ll,ll> mp;
ll sum;
ll mis[100010];
struct node
{
ll l,r;
ll w;
} pnode[maxn * 10]; bool cmp(node a,node b)
{
return a.r< b.r;
} ll s[maxn*5];
int lowbit(int x)
{
return x&(-x);
} void add(int pos,ll val)
{
if(pos <= 0)
return ;
while(pos <= tot)
{
s[pos] += val;
pos += lowbit(pos);
}
} ll cal(int pos)
{
ll cnt = 0;
if(pos <= 0)
return 0;
while(pos > 0)
{
cnt += s[pos];
pos -= lowbit(pos);
}
return cnt;
} int cnt ;
int main()
{
while(scanf("%lld %lld",&ta,&tb)!=EOF)
{
mp.clear();
sum=0;
tot=1;
cnt=1;
scanf("%lld",&x);
y=x+tb;
memset(s,0,sizeof(s));
scanf("%d %d",&n,&m);
for(int i=0; i<n; i++)
{
scanf("%lld %lld %lld",&u,&v,&w);
if(u+v>y||u+v<x) continue;
sum+=w; k = (y - u) / v;
if(k % 2LL == 0LL)
k-=3LL;
while(k*v + u <= y) k +=2LL; //k=3;
//while(u+k*v<=y) k+=2;
pnode[cnt].l = u+2LL*v;
pnode[cnt].r = u+(k-1LL)*v;
// cout << pnode[cnt].l << " " <<pnode[cnt].r <<endl;
mis[tot ++] = u+2LL*v, mis[tot++] = u+(k-1LL)*v;
pnode[cnt++].w= w;
}
for(int i=0; i<m; i++)
{
scanf("%lld %lld %lld",&u,&v,&w);
sum+=w; k = (y - u) / v;
if(k % 2LL == 1LL)
k-=3LL;
while(u+k*v<=y) k +=2LL; pnode[cnt].l = u+v;
// if(u + 2*v > y || u+ 2*v < x)
// pnode[cnt].r = pnode[cnt].l;
// else{
pnode[cnt].r =u+(k-1LL)*v;
mis[tot++] = u+(k-1LL)*v;
// }
mis[tot ++] = u+v;
pnode[cnt++].w= w;
} sort(mis+1,mis+tot);
int t = unique(mis+1,mis+tot) - mis;
sort(pnode+1,pnode + cnt,cmp);
for(int i= 1; i < t; i++)
{
mp[mis[i]] = i;
} int cur = 1;
ll Max = 0; for(int i = 1; i < t; i++)
{
ll ed = mis[i];
ll from = ed - ta; while(mp[pnode[cur].r] == i && cur < cnt)
{
add(mp[pnode[cur].l],pnode[cur].w);
cur ++;
}
int pos = lower_bound(mis+1,mis+t,from) - mis;
Max =max(Max,cal(i) - cal(pos-1));
}
// cout <<Max <<endl;
printf("%lld\n",sum - Max);
}
return 0;
}

  

hihocoder 1391 树状数组的更多相关文章

  1. 2015 北京网络赛 E Border Length hihoCoder 1231 树状数组 (2015-11-05 09:30)

    #1231 : Border Length 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Garlic-Counting Chicken is a special spe ...

  2. 2015 北京网络赛 C Protecting Homeless Cats hihoCoder 1229 树状数组

    题意:求在平面上 任意两点连线,原点到这个点的距离小于d的点对有多少个,n=200000; 解: 以原点为圆心做一个半径为d的圆,我们知道圆内的点和园内以外的点的连线都是小于d的还有,圆内和园内的点联 ...

  3. 离线树状数组 hihocoder 1391 Countries

    官方题解: // 离线树状数组 hihocoder 1391 Countries #include <iostream> #include <cstdio> #include ...

  4. 2016北京网络赛 hihocoder 1391 Countries 树状数组

    Countries   描述 There are two antagonistic countries, country A and country B. They are in a war, and ...

  5. hihoCoder 1145 幻想乡的日常(树状数组 + 离线处理)

    http://hihocoder.com/problemset/problem/1145?sid=1244164 题意: 幻想乡一共有n处居所,编号从1到n.这些居所被n-1条边连起来,形成了一个树形 ...

  6. 【Hihocoder 1167】 高等理论计算机科学 (树链的交,线段树或树状数组维护区间和)

    [题意] 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 少女幽香这几天正在学习高等理论计算机科学,然而她什么也没有学会,非常痛苦.所以她出去晃了一晃,做起了一些没什么意 ...

  7. HihoCoder 1488 : 排队接水(莫队+树状数组)

    描述 有n个小朋友需要接水,其中第i个小朋友接水需要ai分钟. 由于水龙头有限,小Hi需要知道如果为第l个到第r个小朋友分配一个水龙头,如何安排他们的接水顺序才能使得他们等待加接水的时间总和最小. 小 ...

  8. 北京网赛I题 hiho1391 (树状数组、区间覆盖最大值问题)

    题目链接:http://hihocoder.com/problemset/problem/1391 题意:A国和B国向对方分别投射N枚和M枚导弹(发射时间,飞行时间,伤害值),同时两国各自都有防御系统 ...

  9. BZOJ 1103: [POI2007]大都市meg [DFS序 树状数组]

    1103: [POI2007]大都市meg Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2221  Solved: 1179[Submit][Sta ...

随机推荐

  1. Beta版本敏捷冲刺每日报告——Day2

    1.情况简述 Beta阶段第二次Scrum Meeting 敏捷开发起止时间 2017.11.3 08:00 -- 2017.11.3 22:00 讨论时间地点 2017.11.3晚9:00,软工所实 ...

  2. C程序第一次作业

    1-1 计算两数的和与差 1 设计思路 (1)主要描述题目算法 第一步:利用指针psum接收sum的地址,指针pdiff接收diff的地址,因此 * psum为sum, * pdiff为diff. 第 ...

  3. Linux下ip配置与网络重启

    ip配置 //以下ip配置重启失效 sudo ifconfig 192.168.1.1 sudo ifconfig 192.168.1.1 netmask 255.255.255.0 网络重启 //关 ...

  4. 卡尔曼滤波法C编程

    float Angle = 0.0;//卡尔曼滤波器的输出值,最优估计的角度 //float Gyro_x = 0.0;//卡尔曼滤波器的输出值,最优估计的角速度 float Q_angle = 0. ...

  5. 谈谈ASP.NET Core中的ResponseCaching

    前言 前面的博客谈的大多数都是针对数据的缓存,今天我们来换换口味.来谈谈在ASP.NET Core中的ResponseCaching,与ResponseCaching关联密切的也就是常说的HTTP缓存 ...

  6. MyEclipse的多模块Maven web(ssm框架整合)

    Maven的多模块可以让项目结构更明确,提高功能的内聚,降低项目的耦合度,真正的体现出分层这一概念. 我们在操作中,要明白为什么这样做,要了解到更深的层次,这样,我们就不限于个别软件了. 话不多说,直 ...

  7. 【WebGL入门】画一个旋转的cube

    最近搜罗了各种资料,发现WebGL中文网特别好用,很适合新手入门:http://www.hewebgl.com/article/getarticle/50 只需要下载好需要的所有包,然后用notepa ...

  8. 用js来实现那些数据结构(数组篇03)

    终于,这是有关于数组的最后一篇,下一篇会真真切切给大家带来数据结构在js中的实现方式.那么这篇文章还是得啰嗦一下数组的相关知识,因为数组真的太重要了!不要怀疑数组在JS中的重要性与实用性.这篇文章分为 ...

  9. shell:正则表达式和文本处理器

    1.什么是正则 正则就是用一些具有特殊含义的符号组合到一起(称为正则表达式)来描述字符或者字符串的方法.或者说:正则就是用来描述一类事物的规则. 生活中处处都是正则: 比如我们描述:4条腿 你可能会想 ...

  10. IIS进行URL重写

    一.Why? 1.先来讲一讲为什么我们要使用url重写这个东西 2.因为我学习的后端是nodejs,然后我发现nodejs一个非常让人难受的事,就是它监听端口不是80和443时,你访问网页需要输入端口 ...