답안 #892549

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
892549 2023-12-25T13:36:34 Z vjudge1 Progression (NOI20_progression) C++17
100 / 100
628 ms 91356 KB
/*
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,fma,bmi,bmi2,sse4.2,popcnt,lzcnt")
*/

#include <bits/stdc++.h>
#define taskname ""
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define int long long
#define i64 long long
#define pb push_back
#define ff first
#define ss second
#define isz(x) (int)x.size()
using namespace std;

const int mxN = 3e5 + 5;
const int mod = 1e9 + 7;
const i64 oo = 1e18;

struct SegmentTree {
    struct node {
        i64 val = 0;
        int same = 0, len = 0;
        pair<int, int> pfx, sfx;
        i64 lz_mul = 1, lz_add = 0;

        node() {}
        node(int val) : val(val), same(1), len(1), pfx({val, 1}), sfx({val, 1}) {}
        
        node operator + (const node &rhs) {
            node res;
            res.val = val + rhs.val;
            res.len = len + rhs.len;
            res.same = max(same, rhs.same);
            if (sfx.ff == rhs.pfx.ff) res.same = max(res.same, sfx.ss + rhs.pfx.ss);
            res.pfx = pfx, res.sfx = rhs.sfx;
            if (pfx.ss == len and pfx.ff == rhs.pfx.ff) res.pfx = {pfx.ff, pfx.ss + rhs.pfx.ss};
            if (rhs.sfx.ss == rhs.len and sfx.ff == rhs.sfx.ff) res.sfx = {rhs.sfx.ff, rhs.sfx.ss + sfx.ss};
            // cout << *this << endl << rhs << endl << res << endl << endl;
            return res;
        }

        friend ostream & operator << (ostream &out, node o) {
            return out << o.pfx.ff << " " << o.pfx.ss << " " << o.sfx.ff << " " << o.sfx.ss << " " << o.same;
        }
    };

    int n;
    vector<node> data;

    SegmentTree(int n, vector<int> &diff) : n(n), data(4 * n + 10) {
        auto build = [&](auto build, int l, int r, int idx) -> void {
            if (l == r) {
                data[idx] = node(diff[l]);
                return;
            }
            int mid = (l + r) >> 1;
            build(build, l, mid, idx << 1);
            build(build, mid + 1, r, idx << 1 | 1);
            data[idx] = data[idx << 1] + data[idx << 1 | 1];
        };
        build(build, 1, n, 1);
    };

    void apply(int idx, i64 mul, i64 add) {
        if (mul == 0) {
            data[idx].val = add * data[idx].len;
            data[idx].same = data[idx].len;
            data[idx].pfx = data[idx].sfx = {add, data[idx].len};
            data[idx].lz_mul = mul, data[idx].lz_add = add;
        }
        else {
            data[idx].val += add * data[idx].len;
            data[idx].pfx.ff += add, data[idx].sfx.ff += add;
            data[idx].lz_add += add;
        }
    }

    void down(int idx) {
        apply(idx << 1, data[idx].lz_mul, data[idx].lz_add);
        apply(idx << 1 | 1, data[idx].lz_mul, data[idx].lz_add);
        data[idx].lz_add = 0, data[idx].lz_mul = 1;
    }

    void update(int l, int r, int idx, int u, int v, i64 mul, i64 add) {
        if (u <= l && r <= v) {
            apply(idx, mul, add);
            return;
        }
        down(idx);
        int mid = (l + r) >> 1;
        if (u <= mid) update(l, mid, idx << 1, u, v, mul, add);
        if (mid + 1 <= v) update(mid + 1, r, idx << 1 | 1, u, v, mul, add);
        data[idx] = data[idx << 1] + data[idx << 1 | 1];
    }

    void update(int u, int v, i64 mul, i64 add) {
        update(1, n, 1, u, v, mul, add);
    }

    node get(int l, int r, int idx, int u, int v) {
        if (u <= l && r <= v) return data[idx];
        down(idx);
        int mid = (l + r) >> 1;
        if (v <= mid) return get(l, mid, idx << 1, u, v);
        if (mid + 1 <= u) return get(mid + 1, r, idx << 1 | 1, u, v);
        return get(l, mid, idx << 1, u, v) + get(mid + 1, r, idx << 1 | 1, u, v);
    }

    node get(int u, int v) {
        return get(1, n, 1, u, v);
    }
};

int n, q;
int a[mxN];
vector<int> diff;

void solve() {
    cin >> n >> q;
    diff.resize(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        diff[i] = a[i] - a[i - 1];
    }
    SegmentTree st(n, diff);
    // cout << st.data[1].same << endl;
    while (q--) {
        int tp;
        cin >> tp;
        if (tp == 1) {
            int l, r, s, c;
            cin >> l >> r >> s >> c;
            st.update(l, l, 1, s);
            if (l < r) st.update(l + 1, r, 1, c);
            if (r + 1 <= n) st.update(r + 1, r + 1, 1, -(1ll * c * (r - l) + s));
        }
        else if (tp == 2) {
            int l, r, s, c;
            cin >> l >> r >> s >> c;
            i64 cl = st.get(1, l).val;
            if (r + 1 <= n) {
                i64 cr1 = st.get(1, r + 1).val;
                st.update(r + 1, r + 1, 0, cr1 - (s + (r - l) * c));
            }
            st.update(l, l, 1, s - cl);
            if (l < r) st.update(l + 1, r, 0, c);
        }
        else {
            int l, r;
            cin >> l >> r;
            if (l == r) cout << 1 << "\n";
            else cout << st.get(l + 1, r).same + 1 << "\n";
        }
    }
    // for (int i = 1; i <= n; ++i)
    //     cout << st.get(1, i).val << " \n"[i == n];
}

signed main() {

#ifndef CDuongg
    if(fopen(taskname".inp", "r"))
        assert(freopen(taskname".inp", "r", stdin)), assert(freopen(taskname".out", "w", stdout));
#else
    freopen("bai3.inp", "r", stdin);
    freopen("bai3.out", "w", stdout);
    auto start = chrono::high_resolution_clock::now();
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1; //cin >> t;
    while(t--) solve();

#ifdef CDuongg
   // auto end = chrono::high_resolution_clock::now();
   // cout << "\n"; for(int i = 1; i <= 100; ++i) cout << '=';
   // cout << "\nExecution time: " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl;
   // cout << "Check array size pls sir" << endl;
#endif

}
# 결과 실행 시간 메모리 Grader output
1 Correct 264 ms 90196 KB Output is correct
2 Correct 96 ms 596 KB Output is correct
3 Correct 97 ms 592 KB Output is correct
4 Correct 98 ms 552 KB Output is correct
5 Correct 98 ms 580 KB Output is correct
6 Correct 102 ms 852 KB Output is correct
7 Correct 101 ms 812 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 600 KB Output is correct
11 Correct 269 ms 90644 KB Output is correct
12 Correct 268 ms 90196 KB Output is correct
13 Correct 264 ms 90536 KB Output is correct
14 Correct 277 ms 90492 KB Output is correct
15 Correct 293 ms 90448 KB Output is correct
16 Correct 271 ms 90028 KB Output is correct
17 Correct 267 ms 90196 KB Output is correct
18 Correct 286 ms 90448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 472 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 500 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 700 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 213 ms 90712 KB Output is correct
2 Correct 65 ms 844 KB Output is correct
3 Correct 66 ms 1036 KB Output is correct
4 Correct 61 ms 1080 KB Output is correct
5 Correct 73 ms 1108 KB Output is correct
6 Correct 74 ms 1100 KB Output is correct
7 Correct 75 ms 920 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 253 ms 90292 KB Output is correct
12 Correct 212 ms 90520 KB Output is correct
13 Correct 251 ms 90540 KB Output is correct
14 Correct 258 ms 90264 KB Output is correct
15 Correct 198 ms 90708 KB Output is correct
16 Correct 254 ms 91004 KB Output is correct
17 Correct 261 ms 91020 KB Output is correct
18 Correct 262 ms 90908 KB Output is correct
19 Correct 233 ms 90272 KB Output is correct
20 Correct 236 ms 90200 KB Output is correct
21 Correct 240 ms 90284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 439 ms 89912 KB Output is correct
2 Correct 108 ms 768 KB Output is correct
3 Correct 100 ms 548 KB Output is correct
4 Correct 102 ms 516 KB Output is correct
5 Correct 106 ms 540 KB Output is correct
6 Correct 108 ms 612 KB Output is correct
7 Correct 112 ms 1016 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 442 ms 89956 KB Output is correct
12 Correct 448 ms 89984 KB Output is correct
13 Correct 422 ms 89936 KB Output is correct
14 Correct 446 ms 89900 KB Output is correct
15 Correct 403 ms 89684 KB Output is correct
16 Correct 498 ms 89988 KB Output is correct
17 Correct 454 ms 90172 KB Output is correct
18 Correct 440 ms 89896 KB Output is correct
19 Correct 417 ms 90032 KB Output is correct
20 Correct 427 ms 89732 KB Output is correct
21 Correct 421 ms 89692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 213 ms 90712 KB Output is correct
2 Correct 65 ms 844 KB Output is correct
3 Correct 66 ms 1036 KB Output is correct
4 Correct 61 ms 1080 KB Output is correct
5 Correct 73 ms 1108 KB Output is correct
6 Correct 74 ms 1100 KB Output is correct
7 Correct 75 ms 920 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 253 ms 90292 KB Output is correct
12 Correct 212 ms 90520 KB Output is correct
13 Correct 251 ms 90540 KB Output is correct
14 Correct 258 ms 90264 KB Output is correct
15 Correct 198 ms 90708 KB Output is correct
16 Correct 254 ms 91004 KB Output is correct
17 Correct 261 ms 91020 KB Output is correct
18 Correct 262 ms 90908 KB Output is correct
19 Correct 233 ms 90272 KB Output is correct
20 Correct 236 ms 90200 KB Output is correct
21 Correct 240 ms 90284 KB Output is correct
22 Correct 491 ms 90012 KB Output is correct
23 Correct 100 ms 568 KB Output is correct
24 Correct 94 ms 592 KB Output is correct
25 Correct 94 ms 596 KB Output is correct
26 Correct 110 ms 636 KB Output is correct
27 Correct 97 ms 644 KB Output is correct
28 Correct 99 ms 608 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 490 ms 90196 KB Output is correct
33 Correct 468 ms 89956 KB Output is correct
34 Correct 481 ms 89928 KB Output is correct
35 Correct 483 ms 90232 KB Output is correct
36 Correct 382 ms 90292 KB Output is correct
37 Correct 389 ms 90364 KB Output is correct
38 Correct 389 ms 90196 KB Output is correct
39 Correct 447 ms 89936 KB Output is correct
40 Correct 488 ms 90012 KB Output is correct
41 Correct 478 ms 90184 KB Output is correct
42 Correct 494 ms 90544 KB Output is correct
43 Correct 466 ms 90280 KB Output is correct
44 Correct 468 ms 89988 KB Output is correct
45 Correct 472 ms 90052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 264 ms 90196 KB Output is correct
2 Correct 96 ms 596 KB Output is correct
3 Correct 97 ms 592 KB Output is correct
4 Correct 98 ms 552 KB Output is correct
5 Correct 98 ms 580 KB Output is correct
6 Correct 102 ms 852 KB Output is correct
7 Correct 101 ms 812 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 600 KB Output is correct
11 Correct 269 ms 90644 KB Output is correct
12 Correct 268 ms 90196 KB Output is correct
13 Correct 264 ms 90536 KB Output is correct
14 Correct 277 ms 90492 KB Output is correct
15 Correct 293 ms 90448 KB Output is correct
16 Correct 271 ms 90028 KB Output is correct
17 Correct 267 ms 90196 KB Output is correct
18 Correct 286 ms 90448 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 472 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 500 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 1 ms 700 KB Output is correct
36 Correct 2 ms 604 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 213 ms 90712 KB Output is correct
41 Correct 65 ms 844 KB Output is correct
42 Correct 66 ms 1036 KB Output is correct
43 Correct 61 ms 1080 KB Output is correct
44 Correct 73 ms 1108 KB Output is correct
45 Correct 74 ms 1100 KB Output is correct
46 Correct 75 ms 920 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 253 ms 90292 KB Output is correct
51 Correct 212 ms 90520 KB Output is correct
52 Correct 251 ms 90540 KB Output is correct
53 Correct 258 ms 90264 KB Output is correct
54 Correct 198 ms 90708 KB Output is correct
55 Correct 254 ms 91004 KB Output is correct
56 Correct 261 ms 91020 KB Output is correct
57 Correct 262 ms 90908 KB Output is correct
58 Correct 233 ms 90272 KB Output is correct
59 Correct 236 ms 90200 KB Output is correct
60 Correct 240 ms 90284 KB Output is correct
61 Correct 439 ms 89912 KB Output is correct
62 Correct 108 ms 768 KB Output is correct
63 Correct 100 ms 548 KB Output is correct
64 Correct 102 ms 516 KB Output is correct
65 Correct 106 ms 540 KB Output is correct
66 Correct 108 ms 612 KB Output is correct
67 Correct 112 ms 1016 KB Output is correct
68 Correct 1 ms 348 KB Output is correct
69 Correct 1 ms 348 KB Output is correct
70 Correct 1 ms 348 KB Output is correct
71 Correct 442 ms 89956 KB Output is correct
72 Correct 448 ms 89984 KB Output is correct
73 Correct 422 ms 89936 KB Output is correct
74 Correct 446 ms 89900 KB Output is correct
75 Correct 403 ms 89684 KB Output is correct
76 Correct 498 ms 89988 KB Output is correct
77 Correct 454 ms 90172 KB Output is correct
78 Correct 440 ms 89896 KB Output is correct
79 Correct 417 ms 90032 KB Output is correct
80 Correct 427 ms 89732 KB Output is correct
81 Correct 421 ms 89692 KB Output is correct
82 Correct 491 ms 90012 KB Output is correct
83 Correct 100 ms 568 KB Output is correct
84 Correct 94 ms 592 KB Output is correct
85 Correct 94 ms 596 KB Output is correct
86 Correct 110 ms 636 KB Output is correct
87 Correct 97 ms 644 KB Output is correct
88 Correct 99 ms 608 KB Output is correct
89 Correct 1 ms 348 KB Output is correct
90 Correct 0 ms 348 KB Output is correct
91 Correct 0 ms 348 KB Output is correct
92 Correct 490 ms 90196 KB Output is correct
93 Correct 468 ms 89956 KB Output is correct
94 Correct 481 ms 89928 KB Output is correct
95 Correct 483 ms 90232 KB Output is correct
96 Correct 382 ms 90292 KB Output is correct
97 Correct 389 ms 90364 KB Output is correct
98 Correct 389 ms 90196 KB Output is correct
99 Correct 447 ms 89936 KB Output is correct
100 Correct 488 ms 90012 KB Output is correct
101 Correct 478 ms 90184 KB Output is correct
102 Correct 494 ms 90544 KB Output is correct
103 Correct 466 ms 90280 KB Output is correct
104 Correct 468 ms 89988 KB Output is correct
105 Correct 472 ms 90052 KB Output is correct
106 Correct 628 ms 90452 KB Output is correct
107 Correct 138 ms 592 KB Output is correct
108 Correct 133 ms 524 KB Output is correct
109 Correct 134 ms 528 KB Output is correct
110 Correct 1 ms 348 KB Output is correct
111 Correct 1 ms 348 KB Output is correct
112 Correct 1 ms 348 KB Output is correct
113 Correct 484 ms 90036 KB Output is correct
114 Correct 484 ms 89960 KB Output is correct
115 Correct 480 ms 90028 KB Output is correct
116 Correct 447 ms 90028 KB Output is correct
117 Correct 607 ms 90272 KB Output is correct
118 Correct 451 ms 89936 KB Output is correct
119 Correct 448 ms 89984 KB Output is correct
120 Correct 239 ms 90960 KB Output is correct
121 Correct 240 ms 91356 KB Output is correct
122 Correct 237 ms 90964 KB Output is correct
123 Correct 215 ms 90556 KB Output is correct
124 Correct 208 ms 90248 KB Output is correct
125 Correct 209 ms 90192 KB Output is correct
126 Correct 622 ms 90440 KB Output is correct
127 Correct 617 ms 90672 KB Output is correct
128 Correct 615 ms 90584 KB Output is correct
129 Correct 584 ms 90096 KB Output is correct
130 Correct 424 ms 90888 KB Output is correct
131 Correct 399 ms 90964 KB Output is correct
132 Correct 405 ms 90932 KB Output is correct
133 Correct 610 ms 90528 KB Output is correct
134 Correct 611 ms 90456 KB Output is correct
135 Correct 597 ms 90264 KB Output is correct
136 Correct 141 ms 764 KB Output is correct
137 Correct 144 ms 592 KB Output is correct
138 Correct 134 ms 572 KB Output is correct