QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#132415#3857. Single-track railwayadwsaefWA 0ms4560kbC++171.3kb2023-07-29 20:37:052023-07-29 20:37:09

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-29 20:37:09]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4560kb
  • [2023-07-29 20:37:05]
  • 提交

answer

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

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

int result (int station, int s, int pref){
    int o1=pref;
    int o2=s-o1;
    return s-2*std::min(o1,o2);
}

int solve (int s){
    int cr=1;
    int 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 std::min(result(station,s,taken),result(station+1,s,taken+tree[cr]));
}

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

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 4560kb

input:

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

output:

78
20
70
56
37
37
37
91

result:

wrong answer 1st lines differ - expected: '39', found: '78'