• hdu6315 Naive Operations


    传送门

    (分析见正睿10.1笔记)

    代码

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<algorithm>
    #include<cctype>
    #include<cmath>
    #include<cstdlib>
    #include<queue>
    #include<ctime>
    #include<vector>
    #include<set>
    #include<map>
    #include<stack>
    using namespace std;
    int c[440000],d[440000],a[110000],col[440000];
    char s[100];
    inline void build(int le,int ri,int wh,int pl,int k){
          c[wh]=col[wh]=0;
          d[wh]=min(d[wh],k);
          if(le==ri)return;
          int mid=(le+ri)>>1;
          if(mid>=pl)build(le,mid,wh<<1,pl,k);
            else build(mid+1,ri,wh<<1|1,pl,k);
          return;
    }
    inline void pd(int wh){
           col[wh<<1]+=col[wh];
           col[wh<<1|1]+=col[wh];
           d[wh<<1]-=col[wh];
           d[wh<<1|1]-=col[wh];
           col[wh]=0;
           return;
    }
    inline void update(int le,int ri,int wh,int x,int y){
          if(le>=x&&ri<=y){
              if(d[wh]>1){
                d[wh]--;
                col[wh]++;
                return;
              }else {
                if(le==ri){
                    d[wh]=a[le];
                    col[wh]=0;
                    c[wh]++;
                    return;
                }
                pd(wh);
                int mid=(le+ri)>>1;
                update(le,mid,wh<<1,x,y);
                update(mid+1,ri,wh<<1|1,x,y);
                d[wh]=min(d[wh<<1],d[wh<<1|1]);
                c[wh]=c[wh<<1]+c[wh<<1|1];
                return;
              }
          }
          int mid=(le+ri)>>1;
          pd(wh);
          if(mid>=x)update(le,mid,wh<<1,x,y);
          if(mid<y)update(mid+1,ri,wh<<1|1,x,y);
          d[wh]=min(d[wh<<1],d[wh<<1|1]);
          c[wh]=c[wh<<1]+c[wh<<1|1];
          return;
    }
    inline int q(int le,int ri,int wh,int x,int y){
          if(le>=x&&ri<=y)return c[wh];
          int mid=(le+ri)>>1,ans=0;
          if(mid>=x)ans+=q(le,mid,wh<<1,x,y);
          if(mid<y)ans+=q(mid+1,ri,wh<<1|1,x,y);
          return ans;
    } 
    int main(){
          int n,m,i,j,k;
          while(scanf("%d%d",&n,&m)!=EOF){
            memset(d,0x3f,sizeof(d));
            for(i=1;i<=n;i++){
                scanf("%d",&a[i]);
                build(1,n,1,i,a[i]);
            }
            for(i=1;i<=m;i++){
                scanf("%s",s);
                if(s[0]=='a'){
                  int x,y;
                  scanf("%d%d",&x,&y);
                  update(1,n,1,x,y);
                }else {
                  int x,y;
                  scanf("%d%d",&x,&y);
                  printf("%d
    ",q(1,n,1,x,y));
                }
            }
          }
          return 0;
    }
  • 相关阅读:
    C# 自定义配置文件
    Mysql JSON字段提取某一个属性值的函数
    linux查看Java线程
    Idea书签管理器的使用
    springboot寻找property的顺序
    SpringBoot的spring-boot-starter有哪些(官方)
    SpringBoot打成jar包的配置方式
    netstat 常用参数总结
    Sentinel统计线程,QPS,RT的方式
    16. kubernetes RBAC
  • 原文地址:https://www.cnblogs.com/yzxverygood/p/9738117.html
Copyright © 2020-2023  润新知