/ tabris /

记录详情

Accepted

/in/foo.cc: In function 'void pushdown(int, int, int)':
/in/foo.cc:15:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int m = l+r>>1,lson=ls(rt),rson=rs(rt);
                 ~^~
/in/foo.cc:23:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int m = l+r>>1,lson=ls(rt),rson=rs(rt);
                 ~^~
/in/foo.cc: In function 'void build(int, int, int)':
/in/foo.cc:39:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int m = l+r>>1;
             ~^~
/in/foo.cc: In function 'void update(int, int, int, int, int, int)':
/in/foo.cc:52:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int m = l+r>>1,lson= ls(rt),rson=rs(rt);
             ~^~
/in/foo.cc: In function 'void update2(int, int, int, int, int, int)':
/in/foo.cc:66:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int m = l+r>>1,lson= ls(rt),rson=rs(rt);
             ~^~
/in/foo.cc: In function 'll query(int, int, int, int, int)':
/in/foo.cc:73:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int m=l+r>>1;
           ~^~
# 状态 耗时 内存占用
#1 Accepted 2ms 532.0 KiB
#2 Accepted 2ms 840.0 KiB
#3 Accepted 2ms 348.0 KiB
#4 Accepted 3ms 340.0 KiB
#5 Accepted 101ms 7.816 MiB
#6 Accepted 90ms 4.02 MiB
#7 Accepted 47ms 6.91 MiB
#8 Accepted 108ms 7.242 MiB
#9 Accepted 186ms 7.777 MiB
#10 Accepted 142ms 4.141 MiB

代码

#include<bits/stdc++.h>
#define ls(x) x<<1
#define rs(x) x<<1|1
using namespace std;
typedef long long ll;
    int n,m,k;
    const int N= 1e5+5;
int le[N],ri[N];
ll a[N],tr[N<<2];
ll ad[N<<2];
ll va[N<<2];

void pushdown(int l,int r,int rt){
    if(va[rt] != -1){
        int m = l+r>>1,lson=ls(rt),rson=rs(rt);
        va[lson] = va[rson] =rt;
        ad[lson] = ad[rson] =0;
        tr[lson] =  va[rt]*(m-l+1);
        tr[rson] = va[rt]*(r-m);
         va[rt] =-1;
    }
    if(ad[rt]){
        int m = l+r>>1,lson=ls(rt),rson=rs(rt);
        ad[lson]+=ad[rt];
        ad[rson]+=ad[rt];

        tr[lson]+=ad[rt]*(m-l+1);
        tr[rson]+=ad[rt]*(r-m);
        ad[rt]=0;
    }
}
void build(int l,int r,int rt){
    ad[rt]=0;
    va[rt] = -1;
    if(l == r){
        tr[rt] = a[l];
        return;
    }
    int m = l+r>>1;
    int lson = ls(rt),rson=rs(rt);
    build(l,m,lson);
    build(m+1,r,rson);
    tr[rt] = tr[lson]+tr[rson];
}
void update(int L,int R,int c,int l,int r,int rt){
    if(L<=l && r<=R){
        tr[rt] += 1ll*c*(r-l+1);
        ad[rt] += c;
        return;
    }
    pushdown(l,r,rt);
    int m = l+r>>1,lson= ls(rt),rson=rs(rt);
    if(L<=m)update(L,R,c,l,m,lson);
    if(R>m)update(L,R,c,m+1,r,rson);
    tr[rt] = tr[lson]+tr[rson];
}
void update2(int L,int R,int c,int l,int r,int rt){
    if(L<=l && r<=R){
        tr[rt] = 1ll*c*(r-l+1);
        va[rt] = c;
        ad[rt] = 0;
        return;
    }
    pushdown(l,r,rt);

    int m = l+r>>1,lson= ls(rt),rson=rs(rt);
    if(L<=m)update2(L,R,c,l,m,lson);
    if(R>m)update2(L,R,c,m+1,r,rson);
    tr[rt] = tr[lson]+tr[rson];
}
ll query(int L,int R,int l,int r,int rt){
    if(L<=l && r<=R)return tr[rt];
    int m=l+r>>1;
    pushdown(l,r,rt);
    ll ans = 0 ;
    int lson = ls(rt),rson = rs(rt);
    if(L<=m)ans+=query(L,R,l,m,lson);
    if(R>m)ans+=query(L,R,m+1,r,rson);
    return ans;
}

int main(){
//    freopen("in.txt","r",stdin);
    int kase=1;
    while(~scanf("%d%d%d",&n,&m,&k)){
            printf("Case #%d:\n",kase++);
        for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
        for(int i=1;i<=m;i++)scanf("%d%d",&le[i],&ri[i]);
        build(1,n,1);
        int op,x,y;
        for(int i=1;i<=k;i++){
            scanf("%d%d%d",&op,&x,&y);
            if(op == 1){
                update(x,x,y,1,n,1);
            }else if(op == 2){
                update(x,x,-y,1,n,1);
            }else if(op == 3){
                update2(x,x,y,1,n,1);
            }else{
                int l1 = le[x],r1 = ri[x],l2 = le[y],r2 = ri[y];
                ll ans;
                if(min(r1,r2) < max(l1,l2))
                    ans = query(l1,r1,1,n,1) + query(l2,r2,1,n,1);
                else  ans = query(min(l1,l2),max(r1,r2),1,n,1);
                printf("%lld\n",ans);
            }
        }
    }




    return 0;
}

信息

递交者
类型
递交
语言
C++
递交时间
2019-06-13 11:24:34
评测时间
2019-06-13 11:24:34
评测机
分数
100
总耗时
687ms
峰值内存
7.816 MiB