# hdu 4031 问题分解+线段树+暴力

/*区间有两种情况


上面想的做法应该不对233

*/
#include<algorithm>
#include<cstdio>
#include<string.h>
using namespace std;
const int maxn = 20050;
int tree[maxn];
int protect[maxn];
int left[maxn];
int right[maxn];
int time1[maxn];
int n;
int lowbit(int x)
{
return x & -x;
}

int sum(int x)
{
int ret = 0;
while(x > 0){
ret += tree[x];
x -= lowbit(x);
}
return ret;
}

while(x <= n){
tree[x] += d;
x += lowbit(x);
}
}

int build()
{
memset(tree,0,sizeof(tree));
memset(protect,0,sizeof(protect));
memset(left,0,sizeof(left));
memset(right,0,sizeof(right));
memset(time1,0,sizeof(time1));
}

int main()
{
int t;
scanf("%d",&t);
for(int test = 1; test <= t; test++){
printf("Case %d:\n",test);
int N,Q,CD;
scanf("%d %d %d",&N,&Q,&CD);
n = N;
build();
int cnt = 0;
for(int i = 1; i <= Q; i++){
char s[20];
scanf("%s",s);
if (s[0] == 'A'){
scanf("%d %d",&left[cnt],&right[cnt]);
cnt++;
}
else{

int where;
scanf("%d",&where);
for(int j = time1[where]; j < cnt; j++){
if (where >= left[j] && where <= right[j]){
protect[where]++;
time1[where] = j + CD;
j = time1[where] - 1;
}
}
printf("%d\n",sum(where)- protect[where]);
}
}

}
return 0;
}

• 本文已收录于以下专栏：

举报原因： 您举报文章：hdu 4031 问题分解+线段树+暴力 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)