hdu 4031

//这 题我是用树状 数组写的

//表示 对于我这种 数据结构都用没 学过的菜鸟 来说还是有一定难度的

//不多说直接 附代 

 


#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
struct node
{
    int num,count;
}d[20005];
int c[20005],n,str[20005][2];//str存每次攻击的范围;
int lowbit(int x)
{
    return x&(-x);
}
void update(int i,int j)
{
    while(i<=n)
    {
        c[i]+=j;
        i+=lowbit(i);
    }
}
int getsum(int x)
{
    int sum=0;
    while(x>0)
    {
        sum+=c[x];
        x-=lowbit(x);
    }
    return sum;
}
int main()
{
    int t,f=0;
    scanf("%d",&t);
    while(t--)
    {
        memset(c,0,sizeof(c));
        int i;
        for(i=0;i<20005;i++)
        {
            d[i].num=0;//未成功防御的次数
            d[i].count=1;
        }
        int m,t;
        scanf("%d%d%d",&n,&m,&t);
        char s[8];
        i=0;
        printf("Case %d:\n",++f);
        while(m--)
        {
            scanf("%s",s);
            if(s[0]=='A')
            {
                i++;
                int tmp1,tmp2;
                scanf("%d%d",&tmp1,&tmp2);
                str[i][0]=tmp1;
                str[i][1]=tmp2;
         //更新; update(tmp1,
1); update(tmp2+1,-1); } else { int tmp; scanf("%d",&tmp); for(int j=d[tmp].count;j<=i;) { if(tmp<=str[j][1]&&tmp>=str[j][0]) { j=j+t; d[tmp].count=j; d[tmp].num++; } else { j++; d[tmp].count=j; } } printf("%d\n",getsum(tmp)-d[tmp].num); } } } return 0; }

 

 

 


 

posted on 2013-08-21 10:32  看见的是....  阅读(184)  评论(0)    收藏  举报