Submission #689415

# Submission time Handle Problem Language Result Execution time Memory
689415 2023-01-28T13:00:07 Z ksjsjsjsjsjsjs Progression (NOI20_progression) C++17
100 / 100
1442 ms 92812 KB
#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define _pb pop_back
#define _pf pop_front
#define lb lower_bound
#define ub upper_bound
#define bg begin
#define ed end
#define ins insert
#define ers erase
#define mtp make_tuple
#define sz(x) (int)(x).size()
#define all(x) (x).bg(), (x).ed
#define ft front
#define bk back
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define str string
#define pi pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pi>
#define vpll vector<pll>
#define FOR(i, l, r) for (int i = (l); i <= (r); ++i)
#define FOS(i, r, l) for (int i = (r); i >= (l); --i)
#define FRN(i, n) for (int i = 0; i < (n); ++i)
#define FSN(i, n) for (int i = (n) - 1; i >= 0; --i)
#define EACH(i, x) for (auto &i : (x))
#define WHILE while
template<typename T> T gcd(T a, T b) { WHILE(b) { a %= b; swap(a, b); } return a; }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define file "TEST"
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); }
struct Node {
    int l, ans;
    ll d, sum;
    pll p, s;
    Node() { l = ans = d = sum = p.st = p.nd = s.st = s.nd = 0; }
};
const int oo = 1e9 + 5;
const int T = 12e5 + 5;
int n, q;
Node tr[T];
pll la[T];
Node mrg(const Node &a, const Node &b) {
    if (!a.l) return b;
    if (!b.l) return a;
    Node ans = a;
    ans.l += b.l;
    ans.sum = a.sum + b.sum;
    ans.ans = max(a.ans, b.ans);
    if (b.d == a.s.st) ans.ans = max(1LL * ans.ans, a.s.nd + 1);
    if (b.d == b.p.st) ans.ans = max(1LL * ans.ans, b.p.nd + 1);
    if (a.s.st == b.p.st && b.p.st == b.d) ans.ans = max(1LL * ans.ans, a.s.nd + b.p.nd);
    if (a.p.nd == a.l) {
        if (a.l == 1) {
            ans.p = {b.d, 2};
            if (b.p.st == b.d) ans.p = {b.d, b.p.nd + 1};
        }
        else if (b.d == a.p.st) {
            ++ans.p.nd;
            if (b.p.st == b.d) ans.p.nd = a.l + b.p.nd;
        }
    }
    ans.s = b.s;
    if (b.s.nd == b.l) {
        if (b.l == 1) {
            ans.s = {b.d, 2};
            if (a.s.st == b.d)  ans.s = {b.d, a.s.nd + 1};
        }
        else if (b.s.st == b.d) {
            ++ans.s.nd;
            if (a.s.st == b.d) ans.s.nd = b.l + a.s.nd;
        }
    }
    return ans;
}
void build(int i, int l, int r) {
    if (l == r) {
        tr[i].l = 1;
        tr[i].d = 0;
        tr[i].ans = 1;
        tr[i].p = tr[i].s = {0, 1};
        return;
    }
    int mid = l + (r - l) / 2;
    build(i * 2, l, mid);
    build(i * 2 + 1, mid + 1, r);
    tr[i] = mrg(tr[i * 2], tr[i * 2 + 1]);
}
void lazy(int i) {
    if (!la[i].st && !la[i].nd) return;
    if (!la[i].st) {
        tr[i].d += la[i].nd;
        tr[i].p.st += la[i].nd;
        tr[i].s.st += la[i].nd;
        tr[i].sum += 1LL * la[i].nd * tr[i].l;
    }
    else {
        tr[i].d = la[i].nd;
        tr[i].ans = tr[i].l;
        tr[i].p = tr[i].s = {la[i].nd, tr[i].l};
        tr[i].sum = 1LL * la[i].nd * tr[i].l;
    }
    if (tr[i].l > 1) {
        if (!la[i].st) {
            la[i * 2].nd += la[i].nd;
            la[i * 2 + 1].nd += la[i].nd;
        }
        else la[i * 2] = la[i * 2 + 1] = la[i];
    }
    la[i] = {0, 0};
}
void upd(int i, int l, int r, int ql, int qr, pll v) {
    lazy(i);
    if (r < ql || l > qr) return;
    if (ql <= l && r <= qr) {
        la[i] = v;
        lazy(i);
        return;
    }
    int mid = l + (r - l) / 2;
    upd(i * 2, l, mid, ql, qr, v);
    upd(i * 2 + 1, mid + 1, r, ql, qr, v);
    tr[i] = mrg(tr[i * 2], tr[i * 2 + 1]);
}
Node get(int i, int l, int r, int ql, int qr) {
    lazy(i);
    if (r < ql || l > qr) return Node();
    if (ql <= l && r <= qr) return tr[i];
    int mid = l + (r - l) / 2;
    return mrg(get(i * 2, l, mid, ql, qr), get(i * 2 + 1, mid + 1, r, ql, qr));
}
signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//    freopen(file".inp", "r", stdin);
//    freopen(file".out", "w", stdout);
    cin >> n >> q;
    build(1, 1, n);
    int pred = 0;
    FOR(i, 1, n) {
        int d;
        cin >> d;
        upd(1, 1, n, i, i, {0, d - pred});
        pred = d;
    }
    WHILE(q--) {
        int t;
        cin >> t;
        if (t == 3) {
            int l, r;
            cin >> l >> r;
            cout << get(1, 1, n, l, r).ans << '\n';
        }
        else if (t == 1) {
            int l, r, s, c;
            cin >> l >> r >> s >> c;
            upd(1, 1, n, l, l, {0, s});
            upd(1, 1, n, l + 1, r, {0, c});
            upd(1, 1, n, r + 1, r + 1, {0, -s - 1LL * (r - l) * c});
        }
        else {
            int l, r, s, c;
            cin >> l >> r >> s >> c;
            ll l1 = get(1, 1, n, 1, l - 1).sum, l2 = get(1, 1, n, 1, r + 1).sum;
            upd(1, 1, n, l, l, {1, s - l1});
            upd(1, 1, n, r + 1, r + 1, {1, l2 - s - 1LL * (r - l) * c});
            upd(1, 1, n, l + 1, r, {1, c});
        }
    }
    cerr << "\nTime: " << setprecision(5) << fixed << (ldb)clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}
/*
3 3
-1 0 -1
2 1 2 1 -1
2 3 3 -1 1
3 1 3

*/
# Verdict Execution time Memory Grader output
1 Correct 499 ms 87056 KB Output is correct
2 Correct 176 ms 69216 KB Output is correct
3 Correct 163 ms 69388 KB Output is correct
4 Correct 157 ms 69196 KB Output is correct
5 Correct 183 ms 69356 KB Output is correct
6 Correct 156 ms 69408 KB Output is correct
7 Correct 150 ms 69264 KB Output is correct
8 Correct 33 ms 66028 KB Output is correct
9 Correct 30 ms 66036 KB Output is correct
10 Correct 29 ms 65992 KB Output is correct
11 Correct 521 ms 87200 KB Output is correct
12 Correct 513 ms 87012 KB Output is correct
13 Correct 493 ms 87184 KB Output is correct
14 Correct 505 ms 87336 KB Output is correct
15 Correct 529 ms 87308 KB Output is correct
16 Correct 521 ms 86988 KB Output is correct
17 Correct 514 ms 87128 KB Output is correct
18 Correct 513 ms 87008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 66076 KB Output is correct
2 Correct 27 ms 66004 KB Output is correct
3 Correct 31 ms 66024 KB Output is correct
4 Correct 29 ms 65988 KB Output is correct
5 Correct 32 ms 66076 KB Output is correct
6 Correct 27 ms 65996 KB Output is correct
7 Correct 29 ms 66020 KB Output is correct
8 Correct 33 ms 66124 KB Output is correct
9 Correct 29 ms 66020 KB Output is correct
10 Correct 36 ms 66088 KB Output is correct
11 Correct 34 ms 66088 KB Output is correct
12 Correct 32 ms 66132 KB Output is correct
13 Correct 28 ms 66104 KB Output is correct
14 Correct 33 ms 66076 KB Output is correct
15 Correct 30 ms 66080 KB Output is correct
16 Correct 37 ms 66220 KB Output is correct
17 Correct 29 ms 66100 KB Output is correct
18 Correct 34 ms 66128 KB Output is correct
19 Correct 30 ms 66032 KB Output is correct
20 Correct 29 ms 66072 KB Output is correct
21 Correct 29 ms 65984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 464 ms 85416 KB Output is correct
2 Correct 117 ms 68684 KB Output is correct
3 Correct 119 ms 68712 KB Output is correct
4 Correct 141 ms 68684 KB Output is correct
5 Correct 136 ms 68900 KB Output is correct
6 Correct 127 ms 68828 KB Output is correct
7 Correct 126 ms 69096 KB Output is correct
8 Correct 29 ms 66028 KB Output is correct
9 Correct 29 ms 65988 KB Output is correct
10 Correct 34 ms 66024 KB Output is correct
11 Correct 495 ms 84208 KB Output is correct
12 Correct 490 ms 85488 KB Output is correct
13 Correct 489 ms 84120 KB Output is correct
14 Correct 508 ms 84084 KB Output is correct
15 Correct 462 ms 85424 KB Output is correct
16 Correct 491 ms 86120 KB Output is correct
17 Correct 501 ms 85924 KB Output is correct
18 Correct 492 ms 85992 KB Output is correct
19 Correct 458 ms 85412 KB Output is correct
20 Correct 471 ms 85560 KB Output is correct
21 Correct 466 ms 85428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1000 ms 88252 KB Output is correct
2 Correct 208 ms 69404 KB Output is correct
3 Correct 261 ms 69408 KB Output is correct
4 Correct 216 ms 69380 KB Output is correct
5 Correct 239 ms 69432 KB Output is correct
6 Correct 216 ms 69412 KB Output is correct
7 Correct 216 ms 69408 KB Output is correct
8 Correct 28 ms 66004 KB Output is correct
9 Correct 27 ms 66044 KB Output is correct
10 Correct 27 ms 65996 KB Output is correct
11 Correct 1002 ms 84976 KB Output is correct
12 Correct 944 ms 88180 KB Output is correct
13 Correct 925 ms 84960 KB Output is correct
14 Correct 930 ms 84912 KB Output is correct
15 Correct 955 ms 88148 KB Output is correct
16 Correct 991 ms 88436 KB Output is correct
17 Correct 994 ms 88252 KB Output is correct
18 Correct 936 ms 88392 KB Output is correct
19 Correct 962 ms 88260 KB Output is correct
20 Correct 998 ms 88196 KB Output is correct
21 Correct 955 ms 88180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 464 ms 85416 KB Output is correct
2 Correct 117 ms 68684 KB Output is correct
3 Correct 119 ms 68712 KB Output is correct
4 Correct 141 ms 68684 KB Output is correct
5 Correct 136 ms 68900 KB Output is correct
6 Correct 127 ms 68828 KB Output is correct
7 Correct 126 ms 69096 KB Output is correct
8 Correct 29 ms 66028 KB Output is correct
9 Correct 29 ms 65988 KB Output is correct
10 Correct 34 ms 66024 KB Output is correct
11 Correct 495 ms 84208 KB Output is correct
12 Correct 490 ms 85488 KB Output is correct
13 Correct 489 ms 84120 KB Output is correct
14 Correct 508 ms 84084 KB Output is correct
15 Correct 462 ms 85424 KB Output is correct
16 Correct 491 ms 86120 KB Output is correct
17 Correct 501 ms 85924 KB Output is correct
18 Correct 492 ms 85992 KB Output is correct
19 Correct 458 ms 85412 KB Output is correct
20 Correct 471 ms 85560 KB Output is correct
21 Correct 466 ms 85428 KB Output is correct
22 Correct 1064 ms 91712 KB Output is correct
23 Correct 189 ms 69308 KB Output is correct
24 Correct 194 ms 69308 KB Output is correct
25 Correct 189 ms 69196 KB Output is correct
26 Correct 192 ms 69336 KB Output is correct
27 Correct 188 ms 69252 KB Output is correct
28 Correct 213 ms 69304 KB Output is correct
29 Correct 35 ms 66004 KB Output is correct
30 Correct 34 ms 65996 KB Output is correct
31 Correct 28 ms 66004 KB Output is correct
32 Correct 1069 ms 88972 KB Output is correct
33 Correct 1068 ms 91760 KB Output is correct
34 Correct 1087 ms 89008 KB Output is correct
35 Correct 1093 ms 89064 KB Output is correct
36 Correct 938 ms 88912 KB Output is correct
37 Correct 895 ms 88848 KB Output is correct
38 Correct 920 ms 88876 KB Output is correct
39 Correct 1083 ms 91784 KB Output is correct
40 Correct 1093 ms 91924 KB Output is correct
41 Correct 1126 ms 91840 KB Output is correct
42 Correct 1116 ms 91764 KB Output is correct
43 Correct 1119 ms 91784 KB Output is correct
44 Correct 1060 ms 91672 KB Output is correct
45 Correct 1095 ms 91700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 499 ms 87056 KB Output is correct
2 Correct 176 ms 69216 KB Output is correct
3 Correct 163 ms 69388 KB Output is correct
4 Correct 157 ms 69196 KB Output is correct
5 Correct 183 ms 69356 KB Output is correct
6 Correct 156 ms 69408 KB Output is correct
7 Correct 150 ms 69264 KB Output is correct
8 Correct 33 ms 66028 KB Output is correct
9 Correct 30 ms 66036 KB Output is correct
10 Correct 29 ms 65992 KB Output is correct
11 Correct 521 ms 87200 KB Output is correct
12 Correct 513 ms 87012 KB Output is correct
13 Correct 493 ms 87184 KB Output is correct
14 Correct 505 ms 87336 KB Output is correct
15 Correct 529 ms 87308 KB Output is correct
16 Correct 521 ms 86988 KB Output is correct
17 Correct 514 ms 87128 KB Output is correct
18 Correct 513 ms 87008 KB Output is correct
19 Correct 28 ms 66076 KB Output is correct
20 Correct 27 ms 66004 KB Output is correct
21 Correct 31 ms 66024 KB Output is correct
22 Correct 29 ms 65988 KB Output is correct
23 Correct 32 ms 66076 KB Output is correct
24 Correct 27 ms 65996 KB Output is correct
25 Correct 29 ms 66020 KB Output is correct
26 Correct 33 ms 66124 KB Output is correct
27 Correct 29 ms 66020 KB Output is correct
28 Correct 36 ms 66088 KB Output is correct
29 Correct 34 ms 66088 KB Output is correct
30 Correct 32 ms 66132 KB Output is correct
31 Correct 28 ms 66104 KB Output is correct
32 Correct 33 ms 66076 KB Output is correct
33 Correct 30 ms 66080 KB Output is correct
34 Correct 37 ms 66220 KB Output is correct
35 Correct 29 ms 66100 KB Output is correct
36 Correct 34 ms 66128 KB Output is correct
37 Correct 30 ms 66032 KB Output is correct
38 Correct 29 ms 66072 KB Output is correct
39 Correct 29 ms 65984 KB Output is correct
40 Correct 464 ms 85416 KB Output is correct
41 Correct 117 ms 68684 KB Output is correct
42 Correct 119 ms 68712 KB Output is correct
43 Correct 141 ms 68684 KB Output is correct
44 Correct 136 ms 68900 KB Output is correct
45 Correct 127 ms 68828 KB Output is correct
46 Correct 126 ms 69096 KB Output is correct
47 Correct 29 ms 66028 KB Output is correct
48 Correct 29 ms 65988 KB Output is correct
49 Correct 34 ms 66024 KB Output is correct
50 Correct 495 ms 84208 KB Output is correct
51 Correct 490 ms 85488 KB Output is correct
52 Correct 489 ms 84120 KB Output is correct
53 Correct 508 ms 84084 KB Output is correct
54 Correct 462 ms 85424 KB Output is correct
55 Correct 491 ms 86120 KB Output is correct
56 Correct 501 ms 85924 KB Output is correct
57 Correct 492 ms 85992 KB Output is correct
58 Correct 458 ms 85412 KB Output is correct
59 Correct 471 ms 85560 KB Output is correct
60 Correct 466 ms 85428 KB Output is correct
61 Correct 1000 ms 88252 KB Output is correct
62 Correct 208 ms 69404 KB Output is correct
63 Correct 261 ms 69408 KB Output is correct
64 Correct 216 ms 69380 KB Output is correct
65 Correct 239 ms 69432 KB Output is correct
66 Correct 216 ms 69412 KB Output is correct
67 Correct 216 ms 69408 KB Output is correct
68 Correct 28 ms 66004 KB Output is correct
69 Correct 27 ms 66044 KB Output is correct
70 Correct 27 ms 65996 KB Output is correct
71 Correct 1002 ms 84976 KB Output is correct
72 Correct 944 ms 88180 KB Output is correct
73 Correct 925 ms 84960 KB Output is correct
74 Correct 930 ms 84912 KB Output is correct
75 Correct 955 ms 88148 KB Output is correct
76 Correct 991 ms 88436 KB Output is correct
77 Correct 994 ms 88252 KB Output is correct
78 Correct 936 ms 88392 KB Output is correct
79 Correct 962 ms 88260 KB Output is correct
80 Correct 998 ms 88196 KB Output is correct
81 Correct 955 ms 88180 KB Output is correct
82 Correct 1064 ms 91712 KB Output is correct
83 Correct 189 ms 69308 KB Output is correct
84 Correct 194 ms 69308 KB Output is correct
85 Correct 189 ms 69196 KB Output is correct
86 Correct 192 ms 69336 KB Output is correct
87 Correct 188 ms 69252 KB Output is correct
88 Correct 213 ms 69304 KB Output is correct
89 Correct 35 ms 66004 KB Output is correct
90 Correct 34 ms 65996 KB Output is correct
91 Correct 28 ms 66004 KB Output is correct
92 Correct 1069 ms 88972 KB Output is correct
93 Correct 1068 ms 91760 KB Output is correct
94 Correct 1087 ms 89008 KB Output is correct
95 Correct 1093 ms 89064 KB Output is correct
96 Correct 938 ms 88912 KB Output is correct
97 Correct 895 ms 88848 KB Output is correct
98 Correct 920 ms 88876 KB Output is correct
99 Correct 1083 ms 91784 KB Output is correct
100 Correct 1093 ms 91924 KB Output is correct
101 Correct 1126 ms 91840 KB Output is correct
102 Correct 1116 ms 91764 KB Output is correct
103 Correct 1119 ms 91784 KB Output is correct
104 Correct 1060 ms 91672 KB Output is correct
105 Correct 1095 ms 91700 KB Output is correct
106 Correct 1269 ms 92764 KB Output is correct
107 Correct 248 ms 69480 KB Output is correct
108 Correct 257 ms 69496 KB Output is correct
109 Correct 258 ms 69572 KB Output is correct
110 Correct 30 ms 66064 KB Output is correct
111 Correct 30 ms 66004 KB Output is correct
112 Correct 31 ms 65980 KB Output is correct
113 Correct 1235 ms 91748 KB Output is correct
114 Correct 1061 ms 91904 KB Output is correct
115 Correct 1106 ms 91916 KB Output is correct
116 Correct 1075 ms 91896 KB Output is correct
117 Correct 1382 ms 92812 KB Output is correct
118 Correct 1045 ms 91828 KB Output is correct
119 Correct 1022 ms 91672 KB Output is correct
120 Correct 501 ms 86428 KB Output is correct
121 Correct 491 ms 86100 KB Output is correct
122 Correct 501 ms 86168 KB Output is correct
123 Correct 464 ms 85400 KB Output is correct
124 Correct 458 ms 85388 KB Output is correct
125 Correct 461 ms 85432 KB Output is correct
126 Correct 1258 ms 89512 KB Output is correct
127 Correct 1366 ms 89440 KB Output is correct
128 Correct 1380 ms 92756 KB Output is correct
129 Correct 1309 ms 89432 KB Output is correct
130 Correct 961 ms 89380 KB Output is correct
131 Correct 941 ms 89556 KB Output is correct
132 Correct 964 ms 89420 KB Output is correct
133 Correct 1429 ms 92792 KB Output is correct
134 Correct 1293 ms 92792 KB Output is correct
135 Correct 1442 ms 92772 KB Output is correct
136 Correct 256 ms 69648 KB Output is correct
137 Correct 251 ms 69396 KB Output is correct
138 Correct 249 ms 69496 KB Output is correct