Submission #736807

# Submission time Handle Problem Language Result Execution time Memory
736807 2023-05-06T08:48:24 Z Ronin13 Progression (NOI20_progression) C++14
100 / 100
1183 ms 153976 KB
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
#define ull unsigned ll
using namespace std;

const int nmax = 500001;

struct node{
    ll x, y;
    ll pr, suf;
    ll sum, lazy, lazy1;
    bool good = false;
    ll ans = 0;
    node(){
        x = y = 0;
        pr = suf = 0;
        sum = lazy1 = 0;
        lazy = -9e18;
        ans = 0;
    }
}t[4 * nmax];

node merg(node a, node b){
    node c;
    c.sum = a.sum + b.sum;
    c.pr = a.pr;
    c.suf = b.suf;
    c.x = a.x;
    c.y = b.y;
    if(a.good){
        if(b.x == a.x) c.pr += b.pr;
    }
    if(b.good){
        if(a.y == b.y) c.suf += a.suf;
    }
    if(a.good && b.good && a.x == b.x)
        c.good = true;
    c.ans = max(a.ans, b.ans);
    if(a.y == b.x){
        c.ans = max(c.ans, a.suf + b.pr);
    }
    return c;
}
//lazy minichebis lazy1 damatebis
void push1(int v, int l, int r){
    if(t[v].lazy == -9e18)return;
    t[v * 2].lazy = t[v].lazy;
    t[v * 2].lazy1 = 0;
    t[v * 2 + 1].lazy = t[v].lazy;
    t[v * 2 + 1].lazy1 = 0;
    int m = (l + r) /2;
    t[v * 2].sum = (ll)(m - l + 1) * t[v].lazy;
    t[v * 2 + 1].sum = (ll)(r - m) * t[v].lazy;
    t[v * 2].good = true;
    t[v * 2].pr = t[v * 2].suf = t[v * 2].ans = m - l + 1;
    t[v * 2].x = t[v * 2].y = t[v].lazy;
    t[v * 2 + 1].good = true;
    t[v * 2 + 1].pr = t[v * 2 + 1].suf = t[v * 2 + 1].ans = r - m;
    t[v * 2 + 1].x = t[v * 2 + 1].y = t[v].lazy;
    t[v].lazy = -9e18;
    t[v].lazy1 = 0;
}

void push2(int v, int l, int r){
    if(t[v].lazy1 == 0) return;
    ll m = (l + r) / 2;
    if(t[v * 2].lazy != -9e18) t[v * 2].lazy += t[v].lazy1;
    if(t[v * 2 + 1].lazy != -9e18) t[v * 2 + 1].lazy += t[v].lazy1;
    t[v * 2].lazy1 += t[v].lazy1;
    t[v * 2 + 1].lazy1 += t[v].lazy1;
    t[v * 2].x += t[v].lazy1;
    t[v * 2].y += t[v].lazy1;
    t[v * 2 + 1].x += t[v].lazy1;
    t[v * 2 + 1].y += t[v].lazy1;
    t[v * 2].sum += t[v].lazy1 * (ll)(m - l + 1);
    t[v * 2 + 1].sum += t[v].lazy1 * (ll)(r - m);
    t[v].lazy1 = 0;
}

void updran1(int v, int l, int r, int st, int fin, ll val){//minicheba intervalze
    if(l > fin || r < st)
        return;
    if(l >= st && r <= fin){
        t[v].sum = val * (ll)(r - l + 1);
        t[v].x = t[v].y = val;
        t[v].pr = t[v].suf = r - l + 1;
        t[v].lazy = val;
        t[v].lazy1 = 0;
        t[v].good = true;
        t[v].ans = r - l + 1;
        return;
    }
    push1(v, l, r);
    push2(v, l, r);
    int m = (l + r) / 2;
    updran1(2 * v, l, m, st, fin, val);
    updran1(2 * v + 1, m + 1, r, st, fin, val);
    t[v] = merg(t[2 * v], t[2 * v + 1]);
}


void updran2(int v, int l, int r, int st, int fin, ll val){
    if(l > fin || r < st)
        return;
    if(l >= st && r <= fin){
        t[v].sum += val * (ll)(r - l + 1);
        t[v].x += val;
        t[v].y += val;
        if(t[v].lazy != -9e18) t[v].lazy += val;
        t[v].lazy1 += val;
        return;
    }
    push1(v, l, r);
    push2(v, l, r);
    int m = (l + r) / 2;
    updran2(2 * v, l, m, st, fin, val);
    updran2(2 * v + 1, m + 1, r, st, fin, val);
    t[v] = merg(t[2 * v], t[2 * v + 1]);
}


ll getsum(int v, int l, int r, int st, int fin){
    if(l > fin || r < st)
        return 0;
    if(l >= st && r <= fin)
        return t[v].sum;
    push1(v, l, r);
    push2(v, l, r);
    int m = (l + r) / 2;
    return getsum(2 * v, l, m,st, fin) + getsum(2 * v + 1, m + 1, r, st, fin);
}

node getans(int v, int l, int r, int tl, int tr){
    if(l == tl && r == tr){
        return t[v];
    }
    push1(v, l, r);
    push2(v, l, r);
    int m = (l + r) / 2;
    if(tl > m)
        return getans(2 * v + 1, m + 1, r, tl, tr);
    if(tr <= m)
        return getans(2 * v, l, m, tl, tr);
    return merg(getans(2 * v, l, m, tl, m), getans(2 * v + 1, m + 1, r, m + 1, tr));
}

int32_t main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, q; cin >> n >> q;
    ll a[n + 1];
    for(int i = 1; i<= n; ++i){
        cin >> a[i];
    }
    for(int i = n; i >= 2; i--){
        updran1(1, 1, n, i - 1, i - 1, a[i] - a[i - 1]);
    }

    while(q--){
        int t; cin >> t;
        if(t == 3){
            int l, r; cin >> l >> r;
            if(l == r) cout << 1 << "\n";
            else
            cout << getans(1, 1, n, l, r - 1).ans + 1 << "\n";
        }
        if(t == 1){
            ll l, r, s, c; cin >> l >> r >> s >> c;
            if(l > 1){
                updran2(1, 1, n, l - 1, l - 1, s);
            }
            else a[1] += s;

            ll val = s + c * (r - l);

            if(r != n)updran2(1, 1, n, r, r, -val);
            updran2(1,1, n, l, r - 1, c);
        }
        if(t == 2){
            ll l, r, s, c; cin >> l >> r >> s >> c;

            ll y =  getsum(1, 1, n, 1, r) + a[1];
            if(l > 1){
                ll x = getsum(1, 1, n, 1, l - 2) + a[1];
                updran1(1, 1, n, l - 1, l - 1, s - x);
            }

            if(l == 1){
                a[1] = s;
            }
            updran1(1, 1, n, l, r - 1, c);
            if(r < n){
                ll x = y;
                updran1(1, 1, n, r, r, x - s  - c * (r - l));
            }
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 500 ms 145192 KB Output is correct
2 Correct 177 ms 142480 KB Output is correct
3 Correct 174 ms 142388 KB Output is correct
4 Correct 161 ms 142364 KB Output is correct
5 Correct 158 ms 142548 KB Output is correct
6 Correct 170 ms 142496 KB Output is correct
7 Correct 157 ms 142376 KB Output is correct
8 Correct 55 ms 141132 KB Output is correct
9 Correct 59 ms 141120 KB Output is correct
10 Correct 56 ms 141176 KB Output is correct
11 Correct 461 ms 145144 KB Output is correct
12 Correct 470 ms 144972 KB Output is correct
13 Correct 469 ms 145356 KB Output is correct
14 Correct 483 ms 145372 KB Output is correct
15 Correct 487 ms 145344 KB Output is correct
16 Correct 520 ms 145052 KB Output is correct
17 Correct 486 ms 145100 KB Output is correct
18 Correct 487 ms 145112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 141184 KB Output is correct
2 Correct 58 ms 141116 KB Output is correct
3 Correct 59 ms 141184 KB Output is correct
4 Correct 59 ms 141132 KB Output is correct
5 Correct 58 ms 141208 KB Output is correct
6 Correct 56 ms 141120 KB Output is correct
7 Correct 64 ms 141112 KB Output is correct
8 Correct 59 ms 141116 KB Output is correct
9 Correct 58 ms 141196 KB Output is correct
10 Correct 60 ms 141128 KB Output is correct
11 Correct 60 ms 141204 KB Output is correct
12 Correct 60 ms 141132 KB Output is correct
13 Correct 61 ms 141132 KB Output is correct
14 Correct 61 ms 141132 KB Output is correct
15 Correct 58 ms 141216 KB Output is correct
16 Correct 65 ms 141132 KB Output is correct
17 Correct 59 ms 141140 KB Output is correct
18 Correct 59 ms 141240 KB Output is correct
19 Correct 58 ms 141144 KB Output is correct
20 Correct 62 ms 141188 KB Output is correct
21 Correct 59 ms 141212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 431 ms 145604 KB Output is correct
2 Correct 136 ms 142672 KB Output is correct
3 Correct 135 ms 142756 KB Output is correct
4 Correct 129 ms 142656 KB Output is correct
5 Correct 140 ms 142740 KB Output is correct
6 Correct 136 ms 142716 KB Output is correct
7 Correct 137 ms 142796 KB Output is correct
8 Correct 57 ms 141132 KB Output is correct
9 Correct 56 ms 141144 KB Output is correct
10 Correct 58 ms 141152 KB Output is correct
11 Correct 462 ms 145292 KB Output is correct
12 Correct 440 ms 145592 KB Output is correct
13 Correct 458 ms 145304 KB Output is correct
14 Correct 454 ms 145228 KB Output is correct
15 Correct 445 ms 145584 KB Output is correct
16 Correct 468 ms 145964 KB Output is correct
17 Correct 463 ms 145868 KB Output is correct
18 Correct 458 ms 145948 KB Output is correct
19 Correct 414 ms 145172 KB Output is correct
20 Correct 425 ms 145140 KB Output is correct
21 Correct 422 ms 145160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 917 ms 144892 KB Output is correct
2 Correct 232 ms 142308 KB Output is correct
3 Correct 238 ms 142352 KB Output is correct
4 Correct 258 ms 142432 KB Output is correct
5 Correct 229 ms 142412 KB Output is correct
6 Correct 238 ms 142272 KB Output is correct
7 Correct 234 ms 142344 KB Output is correct
8 Correct 56 ms 141120 KB Output is correct
9 Correct 57 ms 141132 KB Output is correct
10 Correct 57 ms 141228 KB Output is correct
11 Correct 901 ms 144800 KB Output is correct
12 Correct 875 ms 144812 KB Output is correct
13 Correct 887 ms 144868 KB Output is correct
14 Correct 887 ms 144916 KB Output is correct
15 Correct 850 ms 144732 KB Output is correct
16 Correct 934 ms 144656 KB Output is correct
17 Correct 873 ms 144688 KB Output is correct
18 Correct 944 ms 144584 KB Output is correct
19 Correct 893 ms 144448 KB Output is correct
20 Correct 850 ms 144488 KB Output is correct
21 Correct 846 ms 144368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 431 ms 145604 KB Output is correct
2 Correct 136 ms 142672 KB Output is correct
3 Correct 135 ms 142756 KB Output is correct
4 Correct 129 ms 142656 KB Output is correct
5 Correct 140 ms 142740 KB Output is correct
6 Correct 136 ms 142716 KB Output is correct
7 Correct 137 ms 142796 KB Output is correct
8 Correct 57 ms 141132 KB Output is correct
9 Correct 56 ms 141144 KB Output is correct
10 Correct 58 ms 141152 KB Output is correct
11 Correct 462 ms 145292 KB Output is correct
12 Correct 440 ms 145592 KB Output is correct
13 Correct 458 ms 145304 KB Output is correct
14 Correct 454 ms 145228 KB Output is correct
15 Correct 445 ms 145584 KB Output is correct
16 Correct 468 ms 145964 KB Output is correct
17 Correct 463 ms 145868 KB Output is correct
18 Correct 458 ms 145948 KB Output is correct
19 Correct 414 ms 145172 KB Output is correct
20 Correct 425 ms 145140 KB Output is correct
21 Correct 422 ms 145160 KB Output is correct
22 Correct 903 ms 144332 KB Output is correct
23 Correct 204 ms 142032 KB Output is correct
24 Correct 200 ms 141804 KB Output is correct
25 Correct 203 ms 141772 KB Output is correct
26 Correct 214 ms 141864 KB Output is correct
27 Correct 222 ms 141844 KB Output is correct
28 Correct 216 ms 141828 KB Output is correct
29 Correct 64 ms 141096 KB Output is correct
30 Correct 57 ms 141188 KB Output is correct
31 Correct 59 ms 141212 KB Output is correct
32 Correct 979 ms 144264 KB Output is correct
33 Correct 937 ms 144220 KB Output is correct
34 Correct 955 ms 144100 KB Output is correct
35 Correct 935 ms 144236 KB Output is correct
36 Correct 797 ms 144456 KB Output is correct
37 Correct 762 ms 144412 KB Output is correct
38 Correct 772 ms 144280 KB Output is correct
39 Correct 922 ms 144076 KB Output is correct
40 Correct 948 ms 144192 KB Output is correct
41 Correct 1012 ms 144040 KB Output is correct
42 Correct 964 ms 143908 KB Output is correct
43 Correct 933 ms 144180 KB Output is correct
44 Correct 935 ms 143948 KB Output is correct
45 Correct 934 ms 143992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 500 ms 145192 KB Output is correct
2 Correct 177 ms 142480 KB Output is correct
3 Correct 174 ms 142388 KB Output is correct
4 Correct 161 ms 142364 KB Output is correct
5 Correct 158 ms 142548 KB Output is correct
6 Correct 170 ms 142496 KB Output is correct
7 Correct 157 ms 142376 KB Output is correct
8 Correct 55 ms 141132 KB Output is correct
9 Correct 59 ms 141120 KB Output is correct
10 Correct 56 ms 141176 KB Output is correct
11 Correct 461 ms 145144 KB Output is correct
12 Correct 470 ms 144972 KB Output is correct
13 Correct 469 ms 145356 KB Output is correct
14 Correct 483 ms 145372 KB Output is correct
15 Correct 487 ms 145344 KB Output is correct
16 Correct 520 ms 145052 KB Output is correct
17 Correct 486 ms 145100 KB Output is correct
18 Correct 487 ms 145112 KB Output is correct
19 Correct 59 ms 141184 KB Output is correct
20 Correct 58 ms 141116 KB Output is correct
21 Correct 59 ms 141184 KB Output is correct
22 Correct 59 ms 141132 KB Output is correct
23 Correct 58 ms 141208 KB Output is correct
24 Correct 56 ms 141120 KB Output is correct
25 Correct 64 ms 141112 KB Output is correct
26 Correct 59 ms 141116 KB Output is correct
27 Correct 58 ms 141196 KB Output is correct
28 Correct 60 ms 141128 KB Output is correct
29 Correct 60 ms 141204 KB Output is correct
30 Correct 60 ms 141132 KB Output is correct
31 Correct 61 ms 141132 KB Output is correct
32 Correct 61 ms 141132 KB Output is correct
33 Correct 58 ms 141216 KB Output is correct
34 Correct 65 ms 141132 KB Output is correct
35 Correct 59 ms 141140 KB Output is correct
36 Correct 59 ms 141240 KB Output is correct
37 Correct 58 ms 141144 KB Output is correct
38 Correct 62 ms 141188 KB Output is correct
39 Correct 59 ms 141212 KB Output is correct
40 Correct 431 ms 145604 KB Output is correct
41 Correct 136 ms 142672 KB Output is correct
42 Correct 135 ms 142756 KB Output is correct
43 Correct 129 ms 142656 KB Output is correct
44 Correct 140 ms 142740 KB Output is correct
45 Correct 136 ms 142716 KB Output is correct
46 Correct 137 ms 142796 KB Output is correct
47 Correct 57 ms 141132 KB Output is correct
48 Correct 56 ms 141144 KB Output is correct
49 Correct 58 ms 141152 KB Output is correct
50 Correct 462 ms 145292 KB Output is correct
51 Correct 440 ms 145592 KB Output is correct
52 Correct 458 ms 145304 KB Output is correct
53 Correct 454 ms 145228 KB Output is correct
54 Correct 445 ms 145584 KB Output is correct
55 Correct 468 ms 145964 KB Output is correct
56 Correct 463 ms 145868 KB Output is correct
57 Correct 458 ms 145948 KB Output is correct
58 Correct 414 ms 145172 KB Output is correct
59 Correct 425 ms 145140 KB Output is correct
60 Correct 422 ms 145160 KB Output is correct
61 Correct 917 ms 144892 KB Output is correct
62 Correct 232 ms 142308 KB Output is correct
63 Correct 238 ms 142352 KB Output is correct
64 Correct 258 ms 142432 KB Output is correct
65 Correct 229 ms 142412 KB Output is correct
66 Correct 238 ms 142272 KB Output is correct
67 Correct 234 ms 142344 KB Output is correct
68 Correct 56 ms 141120 KB Output is correct
69 Correct 57 ms 141132 KB Output is correct
70 Correct 57 ms 141228 KB Output is correct
71 Correct 901 ms 144800 KB Output is correct
72 Correct 875 ms 144812 KB Output is correct
73 Correct 887 ms 144868 KB Output is correct
74 Correct 887 ms 144916 KB Output is correct
75 Correct 850 ms 144732 KB Output is correct
76 Correct 934 ms 144656 KB Output is correct
77 Correct 873 ms 144688 KB Output is correct
78 Correct 944 ms 144584 KB Output is correct
79 Correct 893 ms 144448 KB Output is correct
80 Correct 850 ms 144488 KB Output is correct
81 Correct 846 ms 144368 KB Output is correct
82 Correct 903 ms 144332 KB Output is correct
83 Correct 204 ms 142032 KB Output is correct
84 Correct 200 ms 141804 KB Output is correct
85 Correct 203 ms 141772 KB Output is correct
86 Correct 214 ms 141864 KB Output is correct
87 Correct 222 ms 141844 KB Output is correct
88 Correct 216 ms 141828 KB Output is correct
89 Correct 64 ms 141096 KB Output is correct
90 Correct 57 ms 141188 KB Output is correct
91 Correct 59 ms 141212 KB Output is correct
92 Correct 979 ms 144264 KB Output is correct
93 Correct 937 ms 144220 KB Output is correct
94 Correct 955 ms 144100 KB Output is correct
95 Correct 935 ms 144236 KB Output is correct
96 Correct 797 ms 144456 KB Output is correct
97 Correct 762 ms 144412 KB Output is correct
98 Correct 772 ms 144280 KB Output is correct
99 Correct 922 ms 144076 KB Output is correct
100 Correct 948 ms 144192 KB Output is correct
101 Correct 1012 ms 144040 KB Output is correct
102 Correct 964 ms 143908 KB Output is correct
103 Correct 933 ms 144180 KB Output is correct
104 Correct 935 ms 143948 KB Output is correct
105 Correct 934 ms 143992 KB Output is correct
106 Correct 1120 ms 153796 KB Output is correct
107 Correct 256 ms 144528 KB Output is correct
108 Correct 266 ms 144604 KB Output is correct
109 Correct 260 ms 144576 KB Output is correct
110 Correct 56 ms 141220 KB Output is correct
111 Correct 60 ms 141160 KB Output is correct
112 Correct 57 ms 141144 KB Output is correct
113 Correct 977 ms 153056 KB Output is correct
114 Correct 1002 ms 152916 KB Output is correct
115 Correct 1000 ms 152952 KB Output is correct
116 Correct 974 ms 152940 KB Output is correct
117 Correct 1121 ms 153932 KB Output is correct
118 Correct 960 ms 153128 KB Output is correct
119 Correct 931 ms 152984 KB Output is correct
120 Correct 472 ms 151452 KB Output is correct
121 Correct 456 ms 151492 KB Output is correct
122 Correct 457 ms 151464 KB Output is correct
123 Correct 452 ms 150584 KB Output is correct
124 Correct 432 ms 150604 KB Output is correct
125 Correct 426 ms 150500 KB Output is correct
126 Correct 1114 ms 150536 KB Output is correct
127 Correct 1108 ms 150576 KB Output is correct
128 Correct 1183 ms 153828 KB Output is correct
129 Correct 1122 ms 150732 KB Output is correct
130 Correct 782 ms 150536 KB Output is correct
131 Correct 794 ms 150652 KB Output is correct
132 Correct 817 ms 150476 KB Output is correct
133 Correct 1161 ms 153960 KB Output is correct
134 Correct 1111 ms 153932 KB Output is correct
135 Correct 1107 ms 153976 KB Output is correct
136 Correct 254 ms 144564 KB Output is correct
137 Correct 255 ms 144688 KB Output is correct
138 Correct 252 ms 144580 KB Output is correct