可以根据是否被攻击过设置当前结点一直到下一次可用的时候的时间
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
#define SIZE 100050
static int C[SIZE];
static int n,q,t;
static int bAttack[SIZE];//可攻击时间
static int lowbit(int x)
{
return x&(-x);
}
static void add(int i)
{
while(i<SIZE)
{
C[i]++;
i+=lowbit(i);
}
}
static long long sum(int k)
{
int i = k;
long long ret = 0;
while(i>0)
{
ret+=C[i];
i-=lowbit(i);
}
return ret;
}
int main()
{
int T;
scanf("%d",&T);
int ncase = 1;
while(T--)
{
scanf("%d %d %d",&n,&q,&t);
char str[20];
memset(C,0,sizeof(C));
memset(bAttack,0,sizeof(bAttack));
int k = 0;
int a,b;
printf("Case %d:\n",ncase);
for (int i=0;i<q;++i)
{
scanf("%s",str);
if (str[0]=='A')
{
k++;
scanf("%d",&a);
if (k<bAttack[a])//被攻击过
{
add(a);
}
else
{
bAttack[a] = k+t;
}
}
else//查询
{
scanf("%d %d",&a,&b);
if(a>b){
int te;
te=a;
a=b;
b=te;
}
long long ans = sum(b)-sum(a-1);
printf("%lld\n",ans);
}
}
ncase++;
}
return 0;
}