답안 #965739

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
965739 2024-04-19T06:42:19 Z Tuanlinh123 Bitaro, who Leaps through Time (JOI19_timeleap) C++17
100 / 100
2558 ms 283612 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=1e9;
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)
        {
            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);
            }
            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) return;
        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";}
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 60072 KB Output is correct
2 Correct 14 ms 59996 KB Output is correct
3 Correct 14 ms 59996 KB Output is correct
4 Correct 15 ms 60080 KB Output is correct
5 Correct 14 ms 60120 KB Output is correct
6 Correct 13 ms 59992 KB Output is correct
7 Correct 13 ms 59996 KB Output is correct
8 Correct 13 ms 60068 KB Output is correct
9 Correct 14 ms 59996 KB Output is correct
10 Correct 14 ms 59996 KB Output is correct
11 Correct 16 ms 60608 KB Output is correct
12 Correct 17 ms 60764 KB Output is correct
13 Correct 18 ms 60508 KB Output is correct
14 Correct 17 ms 60508 KB Output is correct
15 Correct 17 ms 60760 KB Output is correct
16 Correct 16 ms 60508 KB Output is correct
17 Correct 16 ms 60764 KB Output is correct
18 Correct 18 ms 60508 KB Output is correct
19 Correct 17 ms 60508 KB Output is correct
20 Correct 17 ms 60764 KB Output is correct
21 Correct 16 ms 60508 KB Output is correct
22 Correct 17 ms 60508 KB Output is correct
23 Correct 17 ms 60508 KB Output is correct
24 Correct 16 ms 60672 KB Output is correct
25 Correct 16 ms 60508 KB Output is correct
26 Correct 17 ms 60508 KB Output is correct
27 Correct 16 ms 60508 KB Output is correct
28 Correct 17 ms 60508 KB Output is correct
29 Correct 18 ms 60508 KB Output is correct
30 Correct 17 ms 60508 KB Output is correct
31 Correct 17 ms 60628 KB Output is correct
32 Correct 16 ms 60764 KB Output is correct
33 Correct 17 ms 60508 KB Output is correct
34 Correct 16 ms 60756 KB Output is correct
35 Correct 17 ms 60760 KB Output is correct
36 Correct 18 ms 60800 KB Output is correct
37 Correct 17 ms 60764 KB Output is correct
38 Correct 17 ms 60508 KB Output is correct
39 Correct 16 ms 60508 KB Output is correct
40 Correct 17 ms 60740 KB Output is correct
41 Correct 13 ms 57948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1610 ms 244420 KB Output is correct
2 Correct 1618 ms 234116 KB Output is correct
3 Correct 1540 ms 236152 KB Output is correct
4 Correct 1554 ms 230244 KB Output is correct
5 Correct 1622 ms 243972 KB Output is correct
6 Correct 1640 ms 240504 KB Output is correct
7 Correct 1536 ms 228484 KB Output is correct
8 Correct 1564 ms 235272 KB Output is correct
9 Correct 1498 ms 214396 KB Output is correct
10 Correct 1634 ms 245892 KB Output is correct
11 Correct 1582 ms 244428 KB Output is correct
12 Correct 1690 ms 257560 KB Output is correct
13 Correct 1655 ms 260832 KB Output is correct
14 Correct 13 ms 57960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 60072 KB Output is correct
2 Correct 14 ms 59996 KB Output is correct
3 Correct 14 ms 59996 KB Output is correct
4 Correct 15 ms 60080 KB Output is correct
5 Correct 14 ms 60120 KB Output is correct
6 Correct 13 ms 59992 KB Output is correct
7 Correct 13 ms 59996 KB Output is correct
8 Correct 13 ms 60068 KB Output is correct
9 Correct 14 ms 59996 KB Output is correct
10 Correct 14 ms 59996 KB Output is correct
11 Correct 16 ms 60608 KB Output is correct
12 Correct 17 ms 60764 KB Output is correct
13 Correct 18 ms 60508 KB Output is correct
14 Correct 17 ms 60508 KB Output is correct
15 Correct 17 ms 60760 KB Output is correct
16 Correct 16 ms 60508 KB Output is correct
17 Correct 16 ms 60764 KB Output is correct
18 Correct 18 ms 60508 KB Output is correct
19 Correct 17 ms 60508 KB Output is correct
20 Correct 17 ms 60764 KB Output is correct
21 Correct 16 ms 60508 KB Output is correct
22 Correct 17 ms 60508 KB Output is correct
23 Correct 17 ms 60508 KB Output is correct
24 Correct 16 ms 60672 KB Output is correct
25 Correct 16 ms 60508 KB Output is correct
26 Correct 17 ms 60508 KB Output is correct
27 Correct 16 ms 60508 KB Output is correct
28 Correct 17 ms 60508 KB Output is correct
29 Correct 18 ms 60508 KB Output is correct
30 Correct 17 ms 60508 KB Output is correct
31 Correct 17 ms 60628 KB Output is correct
32 Correct 16 ms 60764 KB Output is correct
33 Correct 17 ms 60508 KB Output is correct
34 Correct 16 ms 60756 KB Output is correct
35 Correct 17 ms 60760 KB Output is correct
36 Correct 18 ms 60800 KB Output is correct
37 Correct 17 ms 60764 KB Output is correct
38 Correct 17 ms 60508 KB Output is correct
39 Correct 16 ms 60508 KB Output is correct
40 Correct 17 ms 60740 KB Output is correct
41 Correct 13 ms 57948 KB Output is correct
42 Correct 1610 ms 244420 KB Output is correct
43 Correct 1618 ms 234116 KB Output is correct
44 Correct 1540 ms 236152 KB Output is correct
45 Correct 1554 ms 230244 KB Output is correct
46 Correct 1622 ms 243972 KB Output is correct
47 Correct 1640 ms 240504 KB Output is correct
48 Correct 1536 ms 228484 KB Output is correct
49 Correct 1564 ms 235272 KB Output is correct
50 Correct 1498 ms 214396 KB Output is correct
51 Correct 1634 ms 245892 KB Output is correct
52 Correct 1582 ms 244428 KB Output is correct
53 Correct 1690 ms 257560 KB Output is correct
54 Correct 1655 ms 260832 KB Output is correct
55 Correct 13 ms 57960 KB Output is correct
56 Correct 2329 ms 254580 KB Output is correct
57 Correct 2419 ms 241696 KB Output is correct
58 Correct 2389 ms 260288 KB Output is correct
59 Correct 2369 ms 261508 KB Output is correct
60 Correct 2325 ms 247232 KB Output is correct
61 Correct 2437 ms 267808 KB Output is correct
62 Correct 2387 ms 266568 KB Output is correct
63 Correct 2426 ms 266116 KB Output is correct
64 Correct 2428 ms 268196 KB Output is correct
65 Correct 2359 ms 257228 KB Output is correct
66 Correct 2223 ms 240108 KB Output is correct
67 Correct 2198 ms 247964 KB Output is correct
68 Correct 2342 ms 232000 KB Output is correct
69 Correct 2357 ms 253036 KB Output is correct
70 Correct 2230 ms 230584 KB Output is correct
71 Correct 2354 ms 252140 KB Output is correct
72 Correct 2445 ms 259480 KB Output is correct
73 Correct 2496 ms 279100 KB Output is correct
74 Correct 2454 ms 280656 KB Output is correct
75 Correct 2558 ms 283612 KB Output is correct
76 Correct 2501 ms 273920 KB Output is correct
77 Correct 14 ms 57948 KB Output is correct