/ tabris /

记录详情

Wrong Answer

/in/foo.cc: In function 'void pushdown(int, int, int)':
/in/foo.cc:14: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:28: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:41: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:52: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:59:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int m=l+r>>1;
           ~^~
# 状态 耗时 内存占用
#1 Accepted 2ms 476.0 KiB
#2 Accepted 2ms 892.0 KiB
#3 Wrong Answer 2ms 312.0 KiB
#4 Wrong Answer 2ms 312.0 KiB
#5 Accepted 118ms 5.836 MiB
#6 Accepted 103ms 5.016 MiB
#7 Wrong Answer 49ms 6.172 MiB
#8 Wrong Answer 102ms 7.477 MiB
#9 Wrong Answer 165ms 7.727 MiB
#10 Accepted 122ms 5.148 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];

void pushdown(int l,int r,int rt){
    if(ad[rt]!=-1){
        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]=-1;
    }
}
void build(int l,int r,int rt){
    if(l == r){
        tr[rt] = a[l];
        ad[rt] = -1;
        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){
    pushdown(l,r,rt);
    if(L<=l && r<=R){
        tr[rt] = 1ll*c*(r-l+1);
        return;
    }
    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:04:56
评测时间
2019-06-13 11:04:56
评测机
分数
50
总耗时
672ms
峰值内存
7.727 MiB