/ tabris /

记录详情

Accepted


  
# 状态 耗时 内存占用
#1 Accepted 2ms 1.074 MiB
#2 Accepted 1ms 984.0 KiB
#3 Accepted 2ms 984.0 KiB
#4 Accepted 3ms 1.082 MiB
#5 Accepted 64ms 2.113 MiB
#6 Accepted 50ms 1.578 MiB
#7 Accepted 27ms 1.32 MiB
#8 Accepted 57ms 1.691 MiB
#9 Accepted 122ms 2.168 MiB
#10 Accepted 77ms 1.574 MiB

代码

#include <bits/stdc++.h>
typedef long long int LL;
using namespace std;

const int N = 1e5+7;
const int MOD = 1e9+7;

#define DEBUG true
#define DATA 1
#define STD 2
#define VALID 3

int random(int x){
    return (LL)rand()%rand()%x;
}


void stdinout(int k, int status){
    string file_in  = "testcase/" + to_string(k) + ".in";
    string file_out = "testcase/" + to_string(k) + ".out";
    if(1==status){
        freopen(file_in.c_str(), "w" ,stdout);
    }
    else if(2==status){
        freopen(file_in.c_str(), "r", stdin);
        freopen(file_out.c_str(), "w", stdout);
    }
    else if(3==status){
        freopen(file_in.c_str(), "r", stdin);
    }
}

int a[N];
int L[N],R[N];
LL sum[N];

#define lowbit(op) ((op)&(-op))
void update(int i,int v){
    for(;i<N;i+=lowbit(i)) sum[i]+=v;
}

LL getSum(int i){
    LL ans = 0;
    for(;i;i-=lowbit(i)) ans+=sum[i];
    return ans;
}

void run(){
    int n,m,k;
    int kcase = 0;
    while(~scanf("%d%d%d",&n,&m,&k)){
        memset(sum, 0, sizeof(sum));
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
            update(i, a[i]);
        }

        for(int i=1;i<=m;i++){
            scanf("%d%d", &L[i], &R[i]);
        }
        printf("Case #%d:\n",++kcase);
        for(int i=1, op, x, y, tmp;i<=k;i++){
            scanf("%d%d%d", &op, &x, &y);
            if(1 == op){
                a[x]+=y;
                update(x, y);
            }
            else if(2 == op){
                a[x]-=y;
                update(x, -y);
            }
            else if(3 == op){
                tmp = y-a[x];
                a[x] = y;
                update(x, tmp);
            }
            else if(4 == op){
                // L[x],R[x],L[y],R[y];
                LL ans = 0;
                int l1 = L[x], r1= R[x], l2 = L[y], r2 = R[y];
                if(l1>l2) swap(l1,l2),swap(r1,r2);
                //if(l1 == l2){
                //    ans = getSum(max(r1,r2))-getSum(l1-1);
                //}
                //else 
                if(r1 < l2){ // l1 < l2
                    ans = getSum(r1)-getSum(l1-1);
                    ans+= getSum(r2)-getSum(l2-1);
                }
                else {
                    ans = getSum(max(r1,r2))-getSum(l1-1);
                }
                printf("%lld\n",ans);
            }
        }
    }
}
// *****
//          *****
//
// *****
//    *******
//
// *****
// ***
//
// *****
//   ***
void work(){
    for(int i=1;i<=10;i++){
        stdinout(i, STD);
        run();
    }
}

int main(){
    srand((unsigned)time(NULL));
//    work();
    run();
    return 0;
}

信息

递交者
类型
递交
语言
C++
递交时间
2019-06-10 22:39:54
评测时间
2019-06-10 22:41:11
评测机
分数
100
总耗时
410ms
峰值内存
2.168 MiB