HDU 4031 Attack
Attack
Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 1904 Accepted Submission(s): 560
a continuous range of the wall. American deployed N energy shield. Each one defends one unit length of the wall. However, after the shield defends one attack, it needs t seconds to cool down. If the shield defends an attack at kth second, it can’t defend any
attack between (k+1)th second and (k+t-1)th second, inclusive. The shield will defend automatically when it is under attack if it is ready.
During the war, it is very important to understand the situation of both self and the enemy. So the commanders of American want to know how much time some part of the wall is successfully attacked. Successfully attacked means that the attack is not defended
by the shield.
The first line of each test case is three integers, N, Q, t, the length of the wall, the number of attacks and queries, and the time each shield needs to cool down.
The next Q lines each describe one attack or one query. It may be one of the following formats
1. Attack si ti
Al Qaeda attack the wall from si to ti, inclusive. 1 ≤ si ≤ ti ≤ N
2. Query p
How many times the pth unit have been successfully attacked. 1 ≤ p ≤ N
The kth attack happened at the kth second. Queries don’t take time.
1 ≤ N, Q ≤ 20000
1 ≤ t ≤ 50
2
3 7 2
Attack 1 2
Query 2
Attack 2 3
Query 2
Attack 1 3
Query 1
Query 3
9 7 3
Attack 5 5
Attack 4 6
Attack 3 7
Attack 2 8
Attack 1 9
Query 5
Query 3
Case 1:
0
1
0
1
Case 2:
3
2
#include<iostream>
#include<cstdio>
#include<cstring>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define Max 20005
int N,Q,t;
struct
{
int atk;
int cover;
}tree[Max<<2];
void push_up(int rt)
{
tree[rt].atk=tree[rt<<1].atk+tree[rt<<1|1].atk;
}
void push_down(int rt,int m)
{
if(tree[rt].cover)
{
tree[rt<<1].cover+=tree[rt].cover;
tree[rt<<1|1].cover+=tree[rt].cover;
tree[rt<<1].atk+=(m-(m>>1))*tree[rt].cover;
tree[rt<<1|1].atk+=(m>>1)*tree[rt].cover;
tree[rt].cover=0;
}
}
void update(int L,int R,int l,int r,int rt)
{
if(L<=l&&R>=r)
{
tree[rt].cover++;
tree[rt].atk+=r-l+1;
return ;
}
push_down(rt,r-l+1);
int m=(l+r)>>1;
if(L<=m)
update(L,R,lson);
if(R>m)
update(L,R,rson);
push_up(rt);
}
int query(int pos,int l,int r,int rt)
{
if(l==r)
return tree[rt].atk;
push_down(rt,r-l+1);
int m=(l+r)>>1;
if(pos<=m)
return query(pos,lson);
else
return query(pos,rson);
}
int main()
{
int i,T,time,a,b,atk[Max][2],pre[Max],def[Max],ncase=1;
char op[10];
scanf("%d",&T);
while(T--)
{
time=0;
memset(tree,0,sizeof(tree));
scanf("%d%d%d",&N,&Q,&t);
memset(atk,0,sizeof(atk));
memset(def,0,sizeof(def));
for(i=1;i<=N;i++)
pre[i]=1;
printf("Case %d:\n",ncase++);
while(Q--)
{
scanf("%s",op);
if(op[0]=='A')
{
scanf("%d%d",&a,&b);
atk[++time][0]=a;atk[time][1]=b;
update(a,b,1,N,1);
}
else
{
scanf("%d",&a);
if(t==0)
{
printf("0\n");
continue;
}
for(i=pre[a];i<=time;i++)
{
if(atk[i][0]<=a&&atk[i][1]>=a)
{
def[a]++;
pre[a]=i+t;
i+=t-1;
}
}
printf("%d\n",query(a,1,N,1)-def[a]);
}
}
}
return 0;
}
HDU 4031 Attack的更多相关文章
- hdu 4031 attack 线段树区间更新
Attack Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)Total Subm ...
- HDU 4031 Attack(线段树/树状数组区间更新单点查询+暴力)
Attack Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others) Total Sub ...
- HDU 4031 Attack(离线+线段树)(The 36th ACM/ICPC Asia Regional Chengdu Site —— Online Contest)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4031 Problem Description Today is the 10th Annual of ...
- 【树状数组区间修改单点查询】HDU 4031 Attack
http://acm.hdu.edu.cn/showproblem.php?pid=4031 [题意] 有一个长为n的长城,进行q次操作,d为防护罩的冷却时间,Attack表示区间a-b的墙将在1秒后 ...
- hdu 4031 Attack 线段树
题目链接 Attack Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)Total ...
- HDU 4031 Attack (线段树)
成功袭击次数=所有袭击次数-成功防守次数 需要一个辅助pre来记录上一次袭击成功什么时候,对于每个查询,从上一次袭击成功开始,每隔t更新一次. 感觉这样做最坏时间复杂度是O(n^2),这里 说是O(q ...
- hdu 4031(树状数组+辅助数组)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4031 Attack Time Limit: 5000/3000 MS (Java/Others) ...
- hdu 4031 2011成都赛区网络赛A题 线段树 ***
就是不知道时间该怎么处理,想了好久,看了别人的题解发现原来是暴力,暴力也很巧妙啊,想不出来的那种 -_-! #include<cstdio> #include<iostream&g ...
- HDU 5091---Beam Cannon(线段树+扫描线)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5091 Problem Description Recently, the γ galaxies bro ...
随机推荐
- BZOJ1009 GT考试
1009: [HNOI2008]GT考试 Time Limit: 1 Sec Memory Limit: 162 MB Description 阿申准备报名参加GT考试,准考证号为N位数X1X2.. ...
- 【转】用CornerStone配置SVN,HTTP及svn简单使用说明
已经安装了的小伙伴请直接看三步骤 一.下载地址 CornerStoneV2.6:http://pan.baidu.com/s/1qWEsEbM密码:www.macx.cn 二.安装破解方法 1.安装之 ...
- 2017/05/20 java 基础 随笔
static 关键字的特点 1.随着类的加载而加载 2.优先于对象存在 3.被类的所有对象共享 如果某个成员变量是被所有对象共享的,那么他就应该定义为静态的 4.可以通过类名调用 其实它本身也可以通过 ...
- Linux下select&poll&epoll的实现原理(一)【转】
转自:http://www.cnblogs.com/lanyuliuyun/p/5011526.html 最近简单看了一把 linux-3.10.25 kernel中select/poll/epoll ...
- Linux获取/dev/input目录下的event对应的设备【转】
转自:https://blog.csdn.net/qq_21792169/article/details/51458855 当我们在Linux操作系统下使用input子系统时,当我们先插鼠标,在插上摄 ...
- Linux 抽象网络设备简介
Linux 抽象网络设备简介 和磁盘设备类似,Linux 用户想要使用网络功能,不能通过直接操作硬件完成,而需要直接或间接的操作一个 Linux 为我们抽象出来的设备,既通用的 Linux 网络设备来 ...
- 002_JavaSE笔记:单例模式
一.应用杨景 在计算机系统中,线程池.缓存.日志对象.对话框.打印机.显卡的驱动程序对象常被设计成单例.这些应用都或多或少具有资源管理器的功能.每台计算机可以有若干个打印机,但只能有一个Printer ...
- ***linux下安装xampp,XAMPP目录结构(阿里云安装xampp)
XAMPP目录结构 重要的文件和目录 文件/目录 用途 /opt/lampp/bin/ XAMPP 命令库.例如 /opt/lampp/bin ...
- 【Eclipse】Eclipse常用操作
[文章索引] (1)POJO类自动生成Getter和Setter方法 (2)自动生成构造方法(构造函数) (3)通过类自动生成它的接口 (4)自动生成Junit测试类 (5)定制视图 (6) ...
- 【转载】Java是传值还是传引用
1. 简单类型是按值传递的 Java 方法的参数是简单类型的时候,是按值传递的 (pass by value).这一点我们可以通过一个简单的例子来说明: /* 例 1 */ /** * @(#) Te ...