题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4031
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 <stdio.h>
#include <string.h>
#include <string>
#include <cstdio>
#include <cmath>
const int N=20200;
using namespace std;
int c[N],n,m,t,T;
int shield[N],pos[N];
struct node
{
int l,r;
}attack[N];
int lowbit(int x)
{
return x&(-x);
}
void update(int x,int d)
{
while(x<=n)
{
c[x]+=d;
x+=lowbit(x);
}
}
int getsum(int x)
{
int ans=0;
while(x>0)
{
ans+=c[x];
x-=lowbit(x);
}
return ans;
}
void Init()
{
scanf("%d%d%d",&n,&m,&t);
memset(c,0,sizeof(c));
memset(shield,0,sizeof(shield));
memset(pos,0,sizeof(pos));
}
int main()
{
char s[10];
int test=1;
scanf("%d",&T);
while(T--)
{
Init();
int cnt=0;
printf("Case %d:\n",test++);
while(m--)
{
scanf("%s",s);
if(s[0]==‘A‘)
{
cnt++;
int si,ti;
scanf("%d%d",&si,&ti);
attack[cnt].l=si;
attack[cnt].r=ti;
update(si,1);
update(ti+1,-1);
}
else
{
int a;
scanf("%d",&a);
for(int i=pos[a];i<=cnt;)
{
if(a>=attack[i].l&&a<=attack[i].r)
{
pos[a]=i+t;
shield[a]++;
i=i+t;
}
else i++;
}
printf("%d\n",getsum(a)-shield[a]);
}
}
}
return 0;
}
原文:http://www.cnblogs.com/gavanwanggw/p/6702822.html