QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#132466#3857. Single-track railwayadwsaefWA 2ms7548kbC++171.5kb2023-07-29 23:57:432023-07-29 23:57:45

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 23:57:45]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:7548kb
  • [2023-07-29 23:57:43]
  • 提交

answer

#include <iostream>
#include <vector>
#include <string>
constexpr long long SIZE=524288, max_N=200010;
long long tree[SIZE];
long long t[max_N];

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

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

long long solve (long long s){
    long long 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;
        }
    }
    long long 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);
    long long n;
    std::cin>>n;
    long long s=0;
    for (long long i=1; i<n; ++i){
        std::cin>>t[i];
        tree[SIZE/2+i-1]=t[i];
        s+=t[i];
    }
    for (long long i=SIZE/2-1; i>=1; --i)tree[i]=tree[2*i]+tree[2*i+1];
    long long res=solve(s);
    std::vector<long long> R;
    R.push_back(res);
    std::cout<<res<<"\n";
    long long k;
    std::cin>>k;
    long long a, b;
    for (long long i=0; i<k; ++i){
        std::cin>>a>>b;
        tree[SIZE/2+a-1]=b;
        update((SIZE/2+a-1)/2);
        s+=b-t[a];
        t[a]=b;
        res=solve(s);
        R.push_back(res);
    }
    for (auto a:R)std::cout<<a<<'\n';
}

详细

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 7548kb

input:

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

output:

39
39
20
70
56
37
37
37
91

result:

wrong answer 2nd lines differ - expected: '20', found: '39'