首页 > 代码库 > hdu 4031 Attack
hdu 4031 Attack
Attack
Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 1734 Accepted Submission(s): 506
Problem Description
Today is the 10th Annual of “September 11 attacks”, the Al Qaeda is about to attack American again. However, American is protected by a high wall this time, which can be treating as a segment with length N. Al Qaeda has a super weapon, every second it can attack 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.
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.
Input
The beginning of the data is an integer T (T ≤ 20), the number of test case.
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
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
Output
For the ith case, output one line “Case i: ” at first. Then for each query, output one line containing one integer, the number of time the pth unit was successfully attacked when asked.
Sample Input
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
Sample Output
Case 1:
0
1
0
1
Case 2:
3
2
1 #include<iostream> 2 #include<string> 3 #include<cstdio> 4 #include<vector> 5 #include<queue> 6 #include<stack> 7 #include<algorithm> 8 #include<cstring> 9 #include<stdlib.h>10 #include<string>11 #include<cmath>12 #include<map>13 using namespace std;14 #define pb push_back15 #define mmax 10000016 int p[21000],First[21000],cx_love[21000][2],now[21000],ans[21000];17 int n,m,t;18 void update(int pos,int num){19 while(pos<=20000){20 p[pos]+=num;21 pos+=pos&(-pos);22 }23 }24 int getnum(int pos){25 int sum=0;26 while(pos>=1){27 sum+=p[pos];28 pos-=pos&(-pos);29 }30 return sum;31 }32 int main(){33 #ifndef ONLINE_JUDGE34 freopen("input.txt","r" ,stdin);35 #endif // ONLINE_JUDGE36 int cas,so=0,cnt;cin>>cas;37 while(cas--){38 memset(p,0,sizeof(p));39 for(int i=1;i<=n;i++) now[i]=1;40 memset(ans,0,sizeof(ans));41 cin>>n>>m>>t;42 char love[10];43 int a,b;44 cnt=0;45 printf("Case %d:\n",++so);46 for(int j=1;j<=m;j++){47 scanf("%s",love);48 if(love[0]==‘A‘){49 scanf("%d%d",&a,&b);50 cnt++;51 cx_love[cnt][0]=a,cx_love[cnt][1]=b;52 update(a,1);53 update(b+1,-1);54 }55 else{56 scanf("%d",&a);57 int sum=getnum(a);58 while(now[a]<=cnt){59 if(cx_love[now[a]][0]<=a&&a<=cx_love[now[a]][1]){60 now[a]+=t;61 ans[a]++;62 }63 else now[a]++;64 }65 //ans[a] 记录的是a抵挡攻击的次数66 //now[a] 记录的是a最后抵挡攻击的时间67 printf("%d\n",sum-ans[a]);68 }69 }70 }71 }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。