Submission #965738

# Submission time Handle Problem Language Result Execution time Memory
965738 2024-04-19T06:38:03 Z Tuanlinh123 Bitaro, who Leaps through Time (JOI19_timeleap) C++17
0 / 100
1723 ms 524288 KB
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ld long double
#define sz(a) ((ll)(a).size())
using namespace std;

const ll maxn=300005, inf=1e10;
ll l[maxn], r[maxn];

namespace SegTree
{
    struct seg
    {
        ll l, r, a, b, c, d;
        seg(){}
        seg(ll l, ll r, ll a, ll b, ll c, ll d): l(l), r(r), a(a), b(b), c(c), d(d){}
        bool operator < (const seg &o) {return l<o.l;}
        bool operator == (const seg &o) {return tie(a, b, c, d)==tie(o.a, o.b, o.c, o.d);}
        bool operator != (const seg &o) {return !((*this)==o);}
        seg operator + (const seg &o)
        {
            seg ans;
            if (a==0 && o.l<=b && b<=o.r) ans.l=l, ans.r=r;
            else if (!a) ans.l=1, ans.r=0;
            else ans.l=max(l, o.l-b), ans.r=min(r, o.r-b);
            ans.a=a*o.a, ans.b=b*o.a+o.b;
            ans.c=c+a*o.c, ans.d=d+o.d+b*o.c;
            return ans;
        }
    };

    struct Node
    {
        vector <seg> S;
        Node(){}
        Node(ll L, ll R)
        {
            S.pb({0, L, 0, L+1, 0, 0});
            S.pb({L+1, R-1, 1, 1, 0, 0});
            S.pb({R, inf, 0, R, 1, -R+1});
        }
        Node operator + (const Node &o)
        {
            if (!sz(S)) return o;
            if (!sz(o.S)) return *this;
            Node ans;
            vector <seg> s;
            for (seg &i:S) for (const seg &j:o.S)
            {
                seg m=i+j;
                if (m.l<=m.r) s.pb(m);
            }
            assert(sz(s));
            sort(s.begin(), s.end());
            seg crr=s[0];
            for (ll i=1; i<sz(s); i++)
            {
                if (s[i]!=crr) ans.S.pb(crr), crr=s[i];
                else crr.r=max(crr.r, s[i].r);
            }
            ans.S.pb(crr);
            return ans;
        }
    };

    ll n;
    Node pre[maxn*4], suf[maxn*4];

    void build(ll i, ll Start, ll End)
    {
        if (Start==End) {pre[i]=suf[i]=Node(l[Start], r[Start]); return;}
        ll mid=(Start+End)/2;
        build(i*2, Start, mid), build(i*2+1, mid+1, End);
        pre[i]=pre[i*2]+pre[i*2+1], suf[i]=suf[i*2+1]+suf[i*2];
    }
    void init(ll sz){n=sz, build(1, 1, n);}

    void update(ll i, ll Start, ll End, ll idx)
    {
        if (Start==End) {pre[i]=suf[i]=Node(l[idx], r[idx]); return;}
        ll mid=(Start+End)/2;
        if (mid>=idx) update(i*2, Start, mid, idx);
        else update(i*2+1, mid+1, End, idx);
        pre[i]=pre[i*2]+pre[i*2+1], suf[i]=suf[i*2+1]+suf[i*2];
    }
    void update(ll idx){update(1, 1, n, idx);}

    Node query(ll i, ll Start, ll End, ll l, ll r, bool s)
    {
        if (Start>=l && End<=r) return s?suf[i]:pre[i];
        ll mid=(Start+End)/2;
        if (mid<l) return query(i*2+1, mid+1, End, l, r, s);
        if (mid+1>r) return query(i*2, Start, mid, l, r, s);
        return s?query(i*2+1, mid+1, End, l, r, s)+query(i*2, Start, mid, l, r, s)
        :query(i*2, Start, mid, l, r, s)+query(i*2+1, mid+1, End, l, r, s);
    }

    ll query(ll a, ll b, ll c, ll d)
    {
        if (a==c) return max(0ll, b-d);
        Node ans;
        if (a>c) ans=query(1, 1, n, c, a-1, true);
        else ans=query(1, 1, n, a, c-1, false);
        for (seg &i:ans.S)
            if (i.l<=b && b<=i.r)
                return (b*i.c+i.d)+max(0ll, b*i.a+i.b-d);
        assert(0); return 0;
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n, q; cin >> n >> q;
    for (ll i=1; i<n; i++) cin >> l[i] >> r[i];
    SegTree::init(n-1);
    for (ll i=1; i<=q; i++)
    {
        ll t; cin >> t;
        if (t==1) {ll p; cin >> p >> l[p] >> r[p], SegTree::update(p);}
        else {ll a, b, c, d; cin >> a >> b >> c >> d; cout << SegTree::query(a, b, c, d) << "\n";}
    }
}
# Verdict Execution time Memory Grader output
1 Correct 32 ms 59988 KB Output is correct
2 Correct 15 ms 59992 KB Output is correct
3 Correct 16 ms 59996 KB Output is correct
4 Correct 14 ms 59996 KB Output is correct
5 Correct 14 ms 59996 KB Output is correct
6 Correct 13 ms 59996 KB Output is correct
7 Correct 14 ms 60080 KB Output is correct
8 Correct 14 ms 60080 KB Output is correct
9 Correct 17 ms 59996 KB Output is correct
10 Correct 13 ms 59996 KB Output is correct
11 Correct 17 ms 60508 KB Output is correct
12 Correct 17 ms 60660 KB Output is correct
13 Correct 17 ms 60504 KB Output is correct
14 Correct 18 ms 60504 KB Output is correct
15 Correct 17 ms 60764 KB Output is correct
16 Correct 17 ms 60760 KB Output is correct
17 Correct 21 ms 60608 KB Output is correct
18 Correct 19 ms 60764 KB Output is correct
19 Correct 19 ms 60696 KB Output is correct
20 Correct 17 ms 60764 KB Output is correct
21 Correct 18 ms 60508 KB Output is correct
22 Correct 17 ms 60504 KB Output is correct
23 Correct 17 ms 60700 KB Output is correct
24 Correct 16 ms 60508 KB Output is correct
25 Correct 17 ms 60504 KB Output is correct
26 Correct 17 ms 60508 KB Output is correct
27 Correct 17 ms 60636 KB Output is correct
28 Correct 17 ms 60608 KB Output is correct
29 Correct 20 ms 60508 KB Output is correct
30 Correct 17 ms 60764 KB Output is correct
31 Correct 17 ms 60696 KB Output is correct
32 Correct 17 ms 60764 KB Output is correct
33 Correct 17 ms 60764 KB Output is correct
34 Correct 17 ms 60764 KB Output is correct
35 Correct 16 ms 60660 KB Output is correct
36 Correct 17 ms 60764 KB Output is correct
37 Correct 17 ms 60764 KB Output is correct
38 Correct 17 ms 60764 KB Output is correct
39 Correct 18 ms 60764 KB Output is correct
40 Correct 19 ms 60764 KB Output is correct
41 Runtime error 299 ms 524288 KB Execution killed with signal 9
42 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1616 ms 252528 KB Output is correct
2 Correct 1575 ms 241872 KB Output is correct
3 Correct 1582 ms 244256 KB Output is correct
4 Correct 1626 ms 238220 KB Output is correct
5 Correct 1601 ms 252380 KB Output is correct
6 Correct 1572 ms 248792 KB Output is correct
7 Correct 1617 ms 236188 KB Output is correct
8 Correct 1572 ms 243392 KB Output is correct
9 Correct 1507 ms 222288 KB Output is correct
10 Correct 1723 ms 254320 KB Output is correct
11 Correct 1700 ms 252572 KB Output is correct
12 Correct 1685 ms 266244 KB Output is correct
13 Correct 1671 ms 269316 KB Output is correct
14 Runtime error 276 ms 524288 KB Execution killed with signal 9
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 32 ms 59988 KB Output is correct
2 Correct 15 ms 59992 KB Output is correct
3 Correct 16 ms 59996 KB Output is correct
4 Correct 14 ms 59996 KB Output is correct
5 Correct 14 ms 59996 KB Output is correct
6 Correct 13 ms 59996 KB Output is correct
7 Correct 14 ms 60080 KB Output is correct
8 Correct 14 ms 60080 KB Output is correct
9 Correct 17 ms 59996 KB Output is correct
10 Correct 13 ms 59996 KB Output is correct
11 Correct 17 ms 60508 KB Output is correct
12 Correct 17 ms 60660 KB Output is correct
13 Correct 17 ms 60504 KB Output is correct
14 Correct 18 ms 60504 KB Output is correct
15 Correct 17 ms 60764 KB Output is correct
16 Correct 17 ms 60760 KB Output is correct
17 Correct 21 ms 60608 KB Output is correct
18 Correct 19 ms 60764 KB Output is correct
19 Correct 19 ms 60696 KB Output is correct
20 Correct 17 ms 60764 KB Output is correct
21 Correct 18 ms 60508 KB Output is correct
22 Correct 17 ms 60504 KB Output is correct
23 Correct 17 ms 60700 KB Output is correct
24 Correct 16 ms 60508 KB Output is correct
25 Correct 17 ms 60504 KB Output is correct
26 Correct 17 ms 60508 KB Output is correct
27 Correct 17 ms 60636 KB Output is correct
28 Correct 17 ms 60608 KB Output is correct
29 Correct 20 ms 60508 KB Output is correct
30 Correct 17 ms 60764 KB Output is correct
31 Correct 17 ms 60696 KB Output is correct
32 Correct 17 ms 60764 KB Output is correct
33 Correct 17 ms 60764 KB Output is correct
34 Correct 17 ms 60764 KB Output is correct
35 Correct 16 ms 60660 KB Output is correct
36 Correct 17 ms 60764 KB Output is correct
37 Correct 17 ms 60764 KB Output is correct
38 Correct 17 ms 60764 KB Output is correct
39 Correct 18 ms 60764 KB Output is correct
40 Correct 19 ms 60764 KB Output is correct
41 Runtime error 299 ms 524288 KB Execution killed with signal 9
42 Halted 0 ms 0 KB -