QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#131922#3857. Single-track railwayadwsaefWA 2ms7512kbC++171.5kb2023-07-28 22:50:022023-07-28 22:50:04

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-28 22:50:04]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:7512kb
  • [2023-07-28 22:50:02]
  • 提交

answer

#include <iostream>
constexpr int SIZE=524288, max_N=200001;
long long tree[SIZE];
int t[max_N];

long long read (int L, int R, int cl=0, int cr=SIZE/2-1, int x=1){
    if (cl>=L and cr<=R){
        return tree[x];
    }
    if (cl>R or cr<L)return 0;
    return read(L,R,cl,(cl+cr)/2,x*2)+read(L,R,(cl+cr)/2+1,cr,x*2+1);
}

void update (int x){
    while (x!=0){
        tree[x]=tree[2*x]+tree[2*x+1];
        x/=2;
    }
}

long long result (long long station, long long s, int* t){
    long long o1=read(0,station-1);
    long long o2=s-o1;
    return s-2*std::min(o1,o2);
}

long long solve (long long s, int* t){
    int cr=1;
    long long taken=0;
    while (cr<SIZE/2){
        if ((taken+tree[cr*2])*2<=s){
            taken+=tree[cr*2];
            cr=cr*2+1;
        }else{
            cr*=2;
        }
    }
    int station=cr-SIZE/2;
    return result(station,s,t);
}

int main(){
    std::ios_base::sync_with_stdio(false);
    std::cout.tie(0);
    std::cout.tie(0);
    int n;
    std::cin>>n;
    long long s=0;
    for (int i=1; i<n; ++i){
        std::cin>>t[i];
        tree[SIZE/2+i-1]=t[i];
        s+=t[i];
    }
    for (int i=SIZE/2-1; i>=1; --i)tree[i]=tree[2*i]+tree[2*i+1];
    std::cout<<solve(s,t)<<'\n';
    int k;
    std::cin>>k;
    for (int i=0; i<k; ++i){
        int a, b;
        std::cin>>a>>b;
        tree[SIZE/2+a-1]=b;
        update((SIZE/2+a-1)/2);
        s+=b-t[a];
        t[a]=b;
        std::cout<<solve(s,t)<<'\n';
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 6680kb

input:

2
39
7
1 20
1 70
1 56
1 37
1 37
1 37
1 91

output:

39
20
70
56
37
37
37
91

result:

ok 8 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 5468kb

input:

3
8 41
0

output:

33

result:

ok single line: '33'

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 7512kb

input:

30
86 100 80 30 23 17 90 98 20 3 43 31 49 14 14 47 13 44 7 30 50 29 67 68 56 69 28 61 81
10
21 23
7 99
16 70
3 50
4 17
26 42
7 37
10 43
26 83
13 96

output:

8
79
70
93
25
10
11
17
5
18
27

result:

wrong answer 2nd lines differ - expected: '19', found: '79'