• hdu 4031 2011成都赛区网络赛A题 线段树 ***


    就是不知道时间该怎么处理,想了好久,看了别人的题解发现原来是暴力,暴力也很巧妙啊,想不出来的那种  -_-!

      1 #include<cstdio>
      2 #include<iostream>
      3 #include<algorithm>
      4 #include<cstring>
      5 #include<cmath>
      6 #include<queue>
      7 #include<map>
      8 using namespace std;
      9 #define MOD 1000000007
     10 const int INF=0x3f3f3f3f;
     11 const double eps=1e-5;
     12 #define cl(a) memset(a,0,sizeof(a))
     13 #define ts printf("*****
    ");
     14 #define lson l,mid,rt<<1
     15 #define rson mid+1,r,rt<<1|1
     16 #define root 1,n,1
     17 #define mid ((l+r)>>1)
     18 const int MAXN=200005;
     19 int n,m,t,Min;
     20 int sum[MAXN<<2],col[MAXN<<2];
     21 void pushup(int rt){
     22     sum[rt]=sum[rt<<1]+sum[rt<<1|1];
     23 }
     24 void pushdown(int rt,int m)
     25 {
     26     if(col[rt]!=0)
     27     {
     28         sum[rt<<1]+=(m-(m>>1))*col[rt];  //位运算一定要带括号
     29         sum[rt<<1|1]+=(m>>1)*col[rt];
     30         col[rt<<1]+=col[rt];
     31         col[rt<<1|1]+=col[rt];
     32         col[rt]=0;
     33     }
     34 }
     35 void build(int l,int r,int rt){
     36     col[rt]=0;
     37     sum[rt]=0;
     38     if(l==r)    return;
     39     build(lson);
     40     build(rson);
     41     pushup(rt);
     42 }
     43 void update(int L,int R,int val,int l,int r,int rt)
     44 {
     45     if(l>=L&&r<=R)
     46     {
     47         col[rt]+=val;
     48         sum[rt]+=(r-l+1)*val;
     49         return;
     50     }
     51     pushdown(rt,r-l+1);
     52     if(L<=mid)  update(L,R,val,lson);
     53     if(R>mid)  update(L,R,val,rson);
     54     pushup(rt);
     55 }
     56 int query(int pos,int l,int r,int rt)
     57 {
     58     if(l==r)
     59     {
     60         return sum[rt];
     61     }
     62     pushdown(rt,r-l+1);
     63     if(pos<=mid)  return query(pos,lson);
     64     else return query(pos,rson);
     65 }
     66 struct Node
     67 {
     68     int l,r;
     69     Node(){}
     70     Node(int ll,int rr)
     71     {
     72         l=ll,r=rr;
     73     }
     74 }node[MAXN];
     75 int cnt[MAXN],last[MAXN];
     76 int main()
     77 {
     78     int i,j,k;
     79     #ifndef ONLINE_JUDGE
     80     freopen("1.in","r",stdin);
     81     #endif
     82     int u,v,tt,x,q,l;
     83     scanf("%d",&tt);
     84     int ca=1;
     85     while(tt--)
     86     {
     87         scanf("%d%d%d",&n,&q,&t);
     88         build(root);
     89         cl(last);
     90         cl(cnt);
     91         int tot=0;
     92         printf("Case %d:
    ",ca++);
     93         while(q--)
     94         {
     95             char s[10];
     96             scanf("%s",s);
     97             if(s[0]=='A')
     98             {
     99                 scanf("%d%d",&u,&v);
    100                 update(u,v,1,root);
    101                 node[tot++]=Node(u,v);
    102             }
    103             else
    104             {
    105                 scanf("%d",&x);
    106                 if(t==1){puts("0");continue;}
    107                 for(i=last[x];i<tot;i++)    //i是改点冷却好的时间点
    108                 {
    109                     if(x>=node[i].l&&x<=node[i].r)  //防御成功
    110                     {
    111                         cnt[x]++;
    112                         last[x]=i+t;
    113                         i+=t-1;
    114                     }
    115                 }
    116                 //printf("***%d %d***
    ",query(x,root),cnt[x]);
    117                 printf("%d
    ",query(x,root)-cnt[x]);
    118             }
    119         }
    120     }
    121 }
  • 相关阅读:
    CCF CSP 201709-1 打酱油 (贪心)
    CCF CSP 201712-1 最小差值
    CCF CSP 201612-1 中间数
    CCF CSP 201609-1 最大波动
    CCF CSP 201604-1 折点计数
    CCF CSP 201512-1 数位之和
    CCF CSP 201509-1 数列分段
    CCF CSP 201503-1 图像旋转 (降维)
    CCF CSP 201412-1 门禁系统
    CCF CSP 201409-1 相邻数对
  • 原文地址:https://www.cnblogs.com/cnblogs321114287/p/4709433.html
Copyright © 2020-2023  润新知