Submission #537986

# Submission time Handle Problem Language Result Execution time Memory
537986 2022-03-16T02:04:01 Z czhang2718 Bitaro, who Leaps through Time (JOI19_timeleap) C++17
0 / 100
599 ms 524288 KB
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;

struct P{
    int l, r;
    ll k;

    inline P(){}
    inline P(int l, int r, ll k): l(l), r(r), k(k) {}

    inline friend P operator + (P a, P b){
        if(a.k==-1 && b.k==-1){
            if(max(a.l, b.l)<=min(a.r, b.r)) return P(max(a.l, b.l), min(a.r, b.r), -1);
            if(a.l>b.r) return P(a.l, b.r, a.l-b.r);
            if(a.r<b.l) return P(a.r, b.l, 0);
        }
        if(a.k==-1){
            if(b.l>a.r) return P(a.r, b.r, b.k);
            if(b.l<a.l) return P(a.l, b.r, b.k+a.l-b.l);
            return b;
        }
        if(b.k==-1){
            if(b.l>a.r) return P(a.l, b.l, a.k);
            if(b.r<a.r) return P(a.l, b.r, a.k+a.r-b.r);
            return a;
        }
        return P(a.l, b.r, a.k+b.k+max(0, a.r-b.l));
    }
};

const int N=300000;
int n, q;

struct segtree{
    vector<P> seg;

    segtree(){
        seg.resize(4*n);
    }

    void build(vector<P> &v, int x, int lx, int rx){
        if(rx-lx==1){
            seg[x]=v[lx];
            return;
        }
        int m=(lx+rx)/2;
        build(v, 2*x+1, lx, m);
        build(v, 2*x+2, m, rx);
        seg[x]=seg[2*x+1]+seg[2*x+2];
        // cout << "seg " << lx << " " << rx << " " << seg[x].l << " " << seg[x].r << " " << seg[x].k << "\n";
    }

    void build(vector<P> v){ build(v, 0, 0, n-1); }

    void upd(int i, P p, int x, int lx, int rx){
        if(rx-lx==1){
            seg[x]=p; 
            return;
        }
        int m=(lx+rx)/2;
        if(i<m) upd(i, p, 2*x+1, lx, m);
        else upd(i, p, 2*x+2, m, rx);
        seg[x]=seg[2*x+1]+seg[2*x+2];
    }

    void upd(int i, P p){ upd(i, p, 0, 0, n-1); }

    P query(int l, int r, int x, int lx, int rx){
        if(lx>=l && rx<=r) return seg[x];
        if(lx>=r || rx<=l) return P(-1e9, 1e9, -1);
        int m=(lx+rx)/2;
        return query(l, r, 2*x+1, lx, m)+query(l, r, 2*x+2, m, rx);
    }

    P query(int l, int r){ return query(l, r, 0, 0, n-1); }
};


int main(){
    cin.tie(0)->sync_with_stdio(0);

    cin >> n >> q;

    vector<P> path1, path2;
    segtree st1, st2;
    for(int i=0; i<n-1; i++){
        int a, b; cin >> a >> b;
        path1.push_back(P(a-i, b-i-1, -1));
        path2.push_back(P(a-(n-2-i), b-(n-2-i)-1, -1));
    }
    if(n){
        st1.build(path1);
        reverse(path2.begin(), path2.end());
        st2.build(path2);
    }
    

    auto solve=[&](int a, int b, int c, int d, P p)->ll{
        b-=a, d-=c;
        if(p.k==-1){
            int x=b;
            x=max(x, p.l); x=min(x, p.r);
            return (ll)max(0, b-x)+max(0, x-d);
        }
        else return (ll)max(0, b-p.l)+p.k+max(0, p.r-d);
    };

    while(q--){
        int op; cin >> op;
        if(op==1){
            int i, a, b; cin >> i >> a >> b;
            --i;
            st1.upd(i, P(a-i, b-i-1, -1));
            st2.upd(n-2-i, P(a-(n-2-i), b-(n-2-i)-1, -1));
        }
        else{
            int a, b, c, d; cin >> a >> b >> c >> d;
            --a, --c;
            if(n==1){
                cout << "0\n"; continue;
            }
            if(a==c) cout << max(0, b-d) << "\n";
            if(a<c) cout << solve(a, b, c, d, st1.query(a, c)) << "\n";
            if(a>c) cout << solve(n-1-a, b, n-1-c, d, st2.query(n-1-a, n-1-c)) << '\n';
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 2 ms 388 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 456 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 2 ms 388 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 2 ms 460 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 2 ms 388 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 2 ms 460 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 2 ms 468 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 2 ms 452 KB Output is correct
39 Correct 2 ms 460 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Runtime error 285 ms 524288 KB Execution killed with signal 9
42 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 468 ms 51508 KB Output is correct
2 Correct 505 ms 34432 KB Output is correct
3 Correct 531 ms 34668 KB Output is correct
4 Correct 513 ms 34152 KB Output is correct
5 Correct 467 ms 51520 KB Output is correct
6 Correct 447 ms 51304 KB Output is correct
7 Correct 519 ms 51816 KB Output is correct
8 Correct 548 ms 52468 KB Output is correct
9 Correct 430 ms 34464 KB Output is correct
10 Correct 479 ms 51704 KB Output is correct
11 Correct 482 ms 51536 KB Output is correct
12 Correct 599 ms 52580 KB Output is correct
13 Correct 570 ms 52796 KB Output is correct
14 Runtime error 304 ms 524288 KB Execution killed with signal 9
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 2 ms 388 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 456 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 2 ms 388 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 2 ms 460 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 2 ms 388 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 2 ms 460 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 2 ms 468 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 2 ms 452 KB Output is correct
39 Correct 2 ms 460 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Runtime error 285 ms 524288 KB Execution killed with signal 9
42 Halted 0 ms 0 KB -