Description |
Leyni被人掳走,身在水深火热之中...
现在小奈叶专心战斗,Leyni昏迷,他们无法得知小护盾遭受的有效攻击次数,他们需要你的帮助。
只要能帮到他们,Leyni就会赠送出一份小奈叶写真集。 |
Input |
第一行是一个整数T,表示有多少组测试数据。 |
Output |
每一组测试数据,先输出一行"Case i:",i表示第i组测试数据,从1开始计数。 |
Sample Input |
1 |
Sample Output |
Case 1: |
code:
#include<stdio.h>
#include<string.h>
int tcase,n;
int tree[100001];
int lowbit(int x)
{
return (x)&(-x);
}
void attack(int pos)
{
while(pos<=n)
{
tree[pos]+=1;
pos+=lowbit(pos);
}
}
int getsum(int x)
{
int sum=0;
while(x>0)
{
sum+=tree[x];
x-=lowbit(x);
}
return sum;
}
int main()
{
char str[20];
int te[100001];
int i,j,t,ci,k=0;
int x,y,tot;
scanf("%d",&tcase);
{
for(j=1;j<=tcase;j++)
{
tot=0;
memset(tree,0,sizeof(tree));
memset(te,0,sizeof(te));
scanf("%d%d%d",&n,&ci,&t);
printf("Case %d:\n",j);
for(i=1;i<=ci;i++)
{
scanf("%s",str);
if(*str=='A')
{
tot++;
scanf("%d",&y);
if(te[y]==0)
te[y]=tot;
else if(tot-te[y]>=1&&tot-te[y]<t)
attack(y);
else if(tot-te[y]>=t)
te[y]=tot;
}
else if(*str=='Q')
{
scanf("%d%d",&x,&y);
printf("%d\n",getsum(y)-getsum(x-1));
}
}
}
}
return 0;
}