QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#194759#3857. Single-track railwayrealcomplex0#WA 1ms5684kbC++142.5kb2023-09-30 22:12:182023-09-30 22:12:18

Judging History

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

  • [2023-09-30 22:12:18]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5684kb
  • [2023-09-30 22:12:18]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)2e5 + 10;
ll d[N];

struct Node{
    ll d1;
    ll d2;
    ll lazy1;
    ll lazy2;
};

Node T[N * 4];

void push(int node, int cl, int cr){
    T[node].d1 += T[node].lazy1;
    T[node].d2 += T[node].lazy2;
    if(cl != cr){
        T[node * 2].lazy1 += T[node].lazy1;
        T[node * 2 + 1].lazy1 += T[node].lazy1;
        T[node * 2].lazy2 += T[node].lazy2;
        T[node * 2 + 1].lazy2 += T[node].lazy2;
    }
    T[node].lazy1 = T[node].lazy2 = 0;
}

void update(int node, int cl, int cr, int tl, int tr, int typ, ll w){
    push(node, cl, cr);
    if(cr < tl || cl > tr) return;
    if(cl >= tl && cr <= tr){
        if(typ == 0) T[node].lazy1 = w;
        else T[node].lazy2 = w;
        push(node, cl, cr);
        return;
    }
    int mid = (cl + cr) / 2;
    update(node * 2, cl, mid, tl, tr, typ, w);
    update(node * 2 + 1, mid + 1, cr, tl, tr, typ, w);
}

pii get(int node, int cl, int cr, int id){
    push(node, cl, cr);
    if(cl == cr){
        return mp(T[node].d1, T[node].d2);
    }
    int mid = (cl + cr) / 2;
    if(mid >= id)
        return get(node * 2, cl, mid, id);
    else
        return get(node * 2 + 1, mid + 1, cr, id);
}

int n;

ll diff(ll x){
    return max(x,-x);
}

ll calc(){
    int l = 1;
    int r = n - 1;
    while(l < r){
        int mid = (l + r) / 2;
        pii ff = get(1, 1, n, mid + 1);
        if(ff.fi >= ff.se) r = mid;
        else l = mid + 1;
    }
    // l, l + 1
    pii A = get(1, 1, n, l);
    pii B = get(1, 1, n, l + 1);
    if(A.fi == A.se || B.fi == B.se) return 0ll;
    return diff(A.fi - B.se - d[l]);
}

int main(){
    fastIO;
    //freopen("in.txt", "r", stdin);
    cin >> n;
    for(int i = 1; i <= n - 1; i ++ ){
        cin >> d[i];
        update(1, 1, n, i + 1, n, 0, d[i]);
        update(1, 1, n, 1, i, 1, d[i]);
    }
    cout << calc() << "\n";
    int q;
    cin >> q;
    int id;
    ll dd;
    for(int iq = 1; iq <= q; iq ++ ){
        cin >> id >> dd;
        update(1, 1, n, id + 1, n, 0, -d[id]);
        update(1, 1, n, 1, id, 1, -d[id]);
        d[id] = dd;
        update(1, 1, n, id + 1, n, 0, d[id]);
        update(1, 1, n, 1, id, 1, d[id]);
        cout << calc() << "\n";
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5664kb

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: 1ms
memory: 5684kb

input:

3
8 41
0

output:

33

result:

ok single line: '33'

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 5664kb

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'