답안 #1093407

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1093407 2024-09-26T18:39:59 Z vyshniak_n Progression (NOI20_progression) C++17
100 / 100
762 ms 96348 KB
//#pragma optimize("Ofast")
//#pragma optimize("unroll-loops")
//#pragma traget("avx,avx2,tune=native")
 
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <cstdint>
#include <cstring>
#include <string>
#include <cstdlib>
#include <vector>
#include <bitset>
#include <map>
#include <queue>
#include <ctime>
#include <stack>
#include <set>
#include <list>
#include <random>
#include <deque>
#include <functional>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <complex>
#include <numeric>
#include <cassert>
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <thread>
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
#define el '\n'
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define point pair <ll, ll>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
 
using namespace std;
 
#include <random>
mt19937 rnd(time(0));
 
const ll INF = 2e18 + 10;
const ll inf = 2e9 + 10;
const ll N = 3e5 + 10;
const ll mod = 1e9 + 7;
const ll LOG = 20;

struct node {
    ll mx;
    ll sum;
    ll l;
    ll vall;
    ll r;
    ll valr;
    ll sum_d;

    node() = default;

    node(ll x, ll len) {
        mx = sum = l = r = len;
        vall = valr = x;
        sum_d = len * x;
    }

    node(node ql, node qr) {
        sum = 0;
        if (ql.sum != 0 && qr.sum != 0)
            sum = ql.sum + qr.sum;

        mx = max(ql.mx, qr.mx);
        if (ql.valr == qr.vall)
            mx = max(mx, ql.r + qr.l);

        if (mx != sum) sum = 0;

        vall = ql.vall;
        valr = qr.valr;

        l = ql.l;
        if (ql.sum != 0 && ql.vall == qr.vall)
            l = max(l, ql.sum + qr.l);

        r = qr.r;
        if (qr.sum != 0 && qr.valr == ql.valr)
            r = max(r, qr.sum + ql.r);
        sum_d = ql.sum_d + qr.sum_d;
    }

    void add(ll x, ll len) {
        vall += x;
        valr += x;
        sum_d += len * x;
    }
};

node t[4 * N];
ll lazy_add[4 * N];
ll lazy_rm[4 * N];
ll len[4 * N];
ll d[N];

void build(ll v, ll tl, ll tr) {
    if (tl == tr) {
        len[v] = 1;
        t[v] = node(d[tl] - d[tl - 1], 1);
        return;
    }

    ll tm = (tl + tr) >> 1;

    build(v << 1, tl, tm);
    build(v << 1 | 1, tm + 1, tr);

    t[v] = node(t[v << 1], t[v << 1 | 1]);
    len[v] = len[v << 1] + len[v << 1 | 1];
}

void push(ll v) {
    if (lazy_rm[v] != -INF) {
        lazy_add[v << 1] = lazy_add[v << 1 | 1] = 0;

        t[v << 1] = node(lazy_rm[v], len[v << 1]);
        t[v << 1 | 1] = node(lazy_rm[v], len[v << 1 | 1]);

        lazy_rm[v << 1] = lazy_rm[v << 1 | 1] = lazy_rm[v];
        lazy_rm[v] = -INF;
    }

    t[v << 1].add(lazy_add[v], len[v << 1]);
    t[v << 1 | 1].add(lazy_add[v], len[v << 1 | 1]);

    lazy_add[v << 1] += lazy_add[v];
    lazy_add[v << 1 | 1] += lazy_add[v];
    lazy_add[v] = 0;
}
void upd_add(ll v, ll tl, ll tr, ll l, ll r, ll x) {
    if (l > tr || r < tl)
        return;
    if (l <= tl && r >= tr) {
        t[v].add(x, len[v]);
        lazy_add[v] += x;
        return;
    }

    push(v);
    ll tm = (tl + tr) >> 1;

    upd_add(v << 1, tl, tm, l, r, x);
    upd_add(v << 1 | 1, tm + 1, tr, l, r, x);

    t[v] = node(t[v << 1], t[v << 1 | 1]);
}
void upd(ll v, ll tl, ll tr, ll l, ll r, ll x) {
    if (l > tr || r < tl)
        return;
    if (l <= tl && r >= tr) {
        lazy_add[v] = 0;
        lazy_rm[v] = x;
        t[v] = node(x, len[v]);
        return;
    }

    push(v);
    ll tm = (tl + tr) >> 1;

    upd(v << 1, tl, tm, l, r, x);
    upd(v << 1 | 1, tm + 1, tr, l, r, x);

    t[v] = node(t[v << 1], t[v << 1 | 1]);
}
node get(ll v, ll tl, ll tr, ll l, ll r) {
    if (l > tr || r < tl)
        return node(-inf, 0);
    if (l <= tl && r >= tr)
        return t[v];

    push(v);
    ll tm = (tl + tr) >> 1;

    return node(get(v << 1, tl, tm, l, r),
                get(v << 1 | 1, tm + 1, tr, l, r));
}
ll get_pos(ll v, ll tl, ll tr, ll l, ll r) {
    if (l > r || l > tr || r < tl)
        return 0;
    if (l <= tl && r >= tr)
        return t[v].sum_d;

    push(v);
    ll tm = (tl + tr) >> 1;

    return get_pos(v << 1, tl, tm, l, r) +
           get_pos(v << 1 | 1, tm + 1, tr, l, r);
}

void solve() {
    ll n, q;
    cin >> n >> q;

    d[0] = INF;
    for (ll i = 1; i <= n; i++)
        cin >> d[i];
    for (ll i = 0; i < 4 * N; i++)
        lazy_rm[i] = -INF;

    build(1, 1, n);
    ll f = d[1];

    while (q--) {
        ll t, l, r, s, c;
        cin >> t;

        if (t == 1) {
            cin >> l >> r >> s >> c;
            if (l != r)
                upd_add(1, 1, n, l + 1, r, c);
            if (l != 1)
                upd_add(1, 1, n, l, l, s);
            if (r != n)
                upd_add(1, 1, n, r + 1, r + 1, -(s + (r - l) * c));
            if (l == 1)
                f += s;
        } else if (t == 2) {
            cin >> l >> r >> s >> c;
            ll vall, valr;
            if (l != 1) vall = f + get_pos(1, 1, n, 2, l - 1);
            if (r != n) valr = f + get_pos(1, 1, n, 2, r + 1);

            if (l != r)
                upd(1, 1, n, l + 1, r, c);
            if (l != 1)
                upd(1, 1, n, l, l, s - vall);
            if (r != n)
                upd(1, 1, n, r + 1, r + 1, valr - (s + (r - l) * c));
            if (l == 1)
                f = s;
        } else {
            cin >> l >> r;
            if (l == r) {
                cout << 1 << el;
                continue;
            }

            cout << get(1, 1, n, l + 1, r).mx + 1 << el;
        }
    }
    return;
}
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    //freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);

    int tests = 1;
    //cin >> tests;
 
    while (tests--) 
        solve();
    return 0;
}
/*
*/

Compilation message

Progression.cpp: In function 'void solve()':
Progression.cpp:248:20: warning: 'valr' may be used uninitialized in this function [-Wmaybe-uninitialized]
  248 |                 upd(1, 1, n, r + 1, r + 1, valr - (s + (r - l) * c));
      |                 ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Progression.cpp:246:20: warning: 'vall' may be used uninitialized in this function [-Wmaybe-uninitialized]
  246 |                 upd(1, 1, n, l, l, s - vall);
      |                 ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 209 ms 83024 KB Output is correct
2 Correct 81 ms 12880 KB Output is correct
3 Correct 78 ms 12880 KB Output is correct
4 Correct 80 ms 12896 KB Output is correct
5 Correct 77 ms 13140 KB Output is correct
6 Correct 80 ms 13136 KB Output is correct
7 Correct 86 ms 12880 KB Output is correct
8 Correct 4 ms 9816 KB Output is correct
9 Correct 4 ms 9820 KB Output is correct
10 Correct 4 ms 9820 KB Output is correct
11 Correct 211 ms 86536 KB Output is correct
12 Correct 207 ms 86380 KB Output is correct
13 Correct 213 ms 86708 KB Output is correct
14 Correct 209 ms 86824 KB Output is correct
15 Correct 208 ms 86612 KB Output is correct
16 Correct 212 ms 86352 KB Output is correct
17 Correct 207 ms 86352 KB Output is correct
18 Correct 209 ms 86352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9816 KB Output is correct
2 Correct 5 ms 9820 KB Output is correct
3 Correct 5 ms 9820 KB Output is correct
4 Correct 4 ms 9820 KB Output is correct
5 Correct 4 ms 9820 KB Output is correct
6 Correct 4 ms 9816 KB Output is correct
7 Correct 4 ms 9820 KB Output is correct
8 Correct 5 ms 9820 KB Output is correct
9 Correct 7 ms 9820 KB Output is correct
10 Correct 5 ms 9828 KB Output is correct
11 Correct 4 ms 9872 KB Output is correct
12 Correct 5 ms 9820 KB Output is correct
13 Correct 5 ms 9816 KB Output is correct
14 Correct 4 ms 10036 KB Output is correct
15 Correct 5 ms 9820 KB Output is correct
16 Correct 5 ms 9820 KB Output is correct
17 Correct 5 ms 9820 KB Output is correct
18 Correct 5 ms 9820 KB Output is correct
19 Correct 4 ms 9820 KB Output is correct
20 Correct 4 ms 9816 KB Output is correct
21 Correct 4 ms 9736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 261 ms 87048 KB Output is correct
2 Correct 68 ms 10324 KB Output is correct
3 Correct 64 ms 10348 KB Output is correct
4 Correct 54 ms 10340 KB Output is correct
5 Correct 67 ms 10328 KB Output is correct
6 Correct 67 ms 10404 KB Output is correct
7 Correct 73 ms 10508 KB Output is correct
8 Correct 4 ms 9816 KB Output is correct
9 Correct 4 ms 9772 KB Output is correct
10 Correct 4 ms 9820 KB Output is correct
11 Correct 309 ms 86864 KB Output is correct
12 Correct 245 ms 87120 KB Output is correct
13 Correct 279 ms 86708 KB Output is correct
14 Correct 284 ms 86676 KB Output is correct
15 Correct 262 ms 86908 KB Output is correct
16 Correct 283 ms 87376 KB Output is correct
17 Correct 275 ms 87276 KB Output is correct
18 Correct 276 ms 87380 KB Output is correct
19 Correct 252 ms 86728 KB Output is correct
20 Correct 262 ms 86688 KB Output is correct
21 Correct 263 ms 86672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 505 ms 86352 KB Output is correct
2 Correct 96 ms 10064 KB Output is correct
3 Correct 99 ms 10016 KB Output is correct
4 Correct 96 ms 10064 KB Output is correct
5 Correct 103 ms 10068 KB Output is correct
6 Correct 100 ms 9948 KB Output is correct
7 Correct 101 ms 10064 KB Output is correct
8 Correct 4 ms 9820 KB Output is correct
9 Correct 4 ms 9820 KB Output is correct
10 Correct 4 ms 9820 KB Output is correct
11 Correct 502 ms 86220 KB Output is correct
12 Correct 470 ms 86356 KB Output is correct
13 Correct 482 ms 86352 KB Output is correct
14 Correct 499 ms 86352 KB Output is correct
15 Correct 460 ms 86356 KB Output is correct
16 Correct 507 ms 86608 KB Output is correct
17 Correct 501 ms 86352 KB Output is correct
18 Correct 502 ms 86236 KB Output is correct
19 Correct 488 ms 86104 KB Output is correct
20 Correct 486 ms 86100 KB Output is correct
21 Correct 486 ms 86244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 261 ms 87048 KB Output is correct
2 Correct 68 ms 10324 KB Output is correct
3 Correct 64 ms 10348 KB Output is correct
4 Correct 54 ms 10340 KB Output is correct
5 Correct 67 ms 10328 KB Output is correct
6 Correct 67 ms 10404 KB Output is correct
7 Correct 73 ms 10508 KB Output is correct
8 Correct 4 ms 9816 KB Output is correct
9 Correct 4 ms 9772 KB Output is correct
10 Correct 4 ms 9820 KB Output is correct
11 Correct 309 ms 86864 KB Output is correct
12 Correct 245 ms 87120 KB Output is correct
13 Correct 279 ms 86708 KB Output is correct
14 Correct 284 ms 86676 KB Output is correct
15 Correct 262 ms 86908 KB Output is correct
16 Correct 283 ms 87376 KB Output is correct
17 Correct 275 ms 87276 KB Output is correct
18 Correct 276 ms 87380 KB Output is correct
19 Correct 252 ms 86728 KB Output is correct
20 Correct 262 ms 86688 KB Output is correct
21 Correct 263 ms 86672 KB Output is correct
22 Correct 520 ms 88148 KB Output is correct
23 Correct 99 ms 13116 KB Output is correct
24 Correct 100 ms 13112 KB Output is correct
25 Correct 92 ms 12880 KB Output is correct
26 Correct 94 ms 12976 KB Output is correct
27 Correct 95 ms 13064 KB Output is correct
28 Correct 96 ms 13148 KB Output is correct
29 Correct 4 ms 9816 KB Output is correct
30 Correct 4 ms 9700 KB Output is correct
31 Correct 4 ms 9820 KB Output is correct
32 Correct 523 ms 92364 KB Output is correct
33 Correct 518 ms 95316 KB Output is correct
34 Correct 534 ms 92496 KB Output is correct
35 Correct 515 ms 92500 KB Output is correct
36 Correct 465 ms 92256 KB Output is correct
37 Correct 443 ms 92244 KB Output is correct
38 Correct 452 ms 92244 KB Output is correct
39 Correct 523 ms 95316 KB Output is correct
40 Correct 577 ms 95424 KB Output is correct
41 Correct 532 ms 95312 KB Output is correct
42 Correct 535 ms 95176 KB Output is correct
43 Correct 501 ms 95312 KB Output is correct
44 Correct 526 ms 95240 KB Output is correct
45 Correct 500 ms 95176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 209 ms 83024 KB Output is correct
2 Correct 81 ms 12880 KB Output is correct
3 Correct 78 ms 12880 KB Output is correct
4 Correct 80 ms 12896 KB Output is correct
5 Correct 77 ms 13140 KB Output is correct
6 Correct 80 ms 13136 KB Output is correct
7 Correct 86 ms 12880 KB Output is correct
8 Correct 4 ms 9816 KB Output is correct
9 Correct 4 ms 9820 KB Output is correct
10 Correct 4 ms 9820 KB Output is correct
11 Correct 211 ms 86536 KB Output is correct
12 Correct 207 ms 86380 KB Output is correct
13 Correct 213 ms 86708 KB Output is correct
14 Correct 209 ms 86824 KB Output is correct
15 Correct 208 ms 86612 KB Output is correct
16 Correct 212 ms 86352 KB Output is correct
17 Correct 207 ms 86352 KB Output is correct
18 Correct 209 ms 86352 KB Output is correct
19 Correct 6 ms 9816 KB Output is correct
20 Correct 5 ms 9820 KB Output is correct
21 Correct 5 ms 9820 KB Output is correct
22 Correct 4 ms 9820 KB Output is correct
23 Correct 4 ms 9820 KB Output is correct
24 Correct 4 ms 9816 KB Output is correct
25 Correct 4 ms 9820 KB Output is correct
26 Correct 5 ms 9820 KB Output is correct
27 Correct 7 ms 9820 KB Output is correct
28 Correct 5 ms 9828 KB Output is correct
29 Correct 4 ms 9872 KB Output is correct
30 Correct 5 ms 9820 KB Output is correct
31 Correct 5 ms 9816 KB Output is correct
32 Correct 4 ms 10036 KB Output is correct
33 Correct 5 ms 9820 KB Output is correct
34 Correct 5 ms 9820 KB Output is correct
35 Correct 5 ms 9820 KB Output is correct
36 Correct 5 ms 9820 KB Output is correct
37 Correct 4 ms 9820 KB Output is correct
38 Correct 4 ms 9816 KB Output is correct
39 Correct 4 ms 9736 KB Output is correct
40 Correct 261 ms 87048 KB Output is correct
41 Correct 68 ms 10324 KB Output is correct
42 Correct 64 ms 10348 KB Output is correct
43 Correct 54 ms 10340 KB Output is correct
44 Correct 67 ms 10328 KB Output is correct
45 Correct 67 ms 10404 KB Output is correct
46 Correct 73 ms 10508 KB Output is correct
47 Correct 4 ms 9816 KB Output is correct
48 Correct 4 ms 9772 KB Output is correct
49 Correct 4 ms 9820 KB Output is correct
50 Correct 309 ms 86864 KB Output is correct
51 Correct 245 ms 87120 KB Output is correct
52 Correct 279 ms 86708 KB Output is correct
53 Correct 284 ms 86676 KB Output is correct
54 Correct 262 ms 86908 KB Output is correct
55 Correct 283 ms 87376 KB Output is correct
56 Correct 275 ms 87276 KB Output is correct
57 Correct 276 ms 87380 KB Output is correct
58 Correct 252 ms 86728 KB Output is correct
59 Correct 262 ms 86688 KB Output is correct
60 Correct 263 ms 86672 KB Output is correct
61 Correct 505 ms 86352 KB Output is correct
62 Correct 96 ms 10064 KB Output is correct
63 Correct 99 ms 10016 KB Output is correct
64 Correct 96 ms 10064 KB Output is correct
65 Correct 103 ms 10068 KB Output is correct
66 Correct 100 ms 9948 KB Output is correct
67 Correct 101 ms 10064 KB Output is correct
68 Correct 4 ms 9820 KB Output is correct
69 Correct 4 ms 9820 KB Output is correct
70 Correct 4 ms 9820 KB Output is correct
71 Correct 502 ms 86220 KB Output is correct
72 Correct 470 ms 86356 KB Output is correct
73 Correct 482 ms 86352 KB Output is correct
74 Correct 499 ms 86352 KB Output is correct
75 Correct 460 ms 86356 KB Output is correct
76 Correct 507 ms 86608 KB Output is correct
77 Correct 501 ms 86352 KB Output is correct
78 Correct 502 ms 86236 KB Output is correct
79 Correct 488 ms 86104 KB Output is correct
80 Correct 486 ms 86100 KB Output is correct
81 Correct 486 ms 86244 KB Output is correct
82 Correct 520 ms 88148 KB Output is correct
83 Correct 99 ms 13116 KB Output is correct
84 Correct 100 ms 13112 KB Output is correct
85 Correct 92 ms 12880 KB Output is correct
86 Correct 94 ms 12976 KB Output is correct
87 Correct 95 ms 13064 KB Output is correct
88 Correct 96 ms 13148 KB Output is correct
89 Correct 4 ms 9816 KB Output is correct
90 Correct 4 ms 9700 KB Output is correct
91 Correct 4 ms 9820 KB Output is correct
92 Correct 523 ms 92364 KB Output is correct
93 Correct 518 ms 95316 KB Output is correct
94 Correct 534 ms 92496 KB Output is correct
95 Correct 515 ms 92500 KB Output is correct
96 Correct 465 ms 92256 KB Output is correct
97 Correct 443 ms 92244 KB Output is correct
98 Correct 452 ms 92244 KB Output is correct
99 Correct 523 ms 95316 KB Output is correct
100 Correct 577 ms 95424 KB Output is correct
101 Correct 532 ms 95312 KB Output is correct
102 Correct 535 ms 95176 KB Output is correct
103 Correct 501 ms 95312 KB Output is correct
104 Correct 526 ms 95240 KB Output is correct
105 Correct 500 ms 95176 KB Output is correct
106 Correct 709 ms 96348 KB Output is correct
107 Correct 130 ms 13252 KB Output is correct
108 Correct 131 ms 13136 KB Output is correct
109 Correct 130 ms 13136 KB Output is correct
110 Correct 4 ms 9820 KB Output is correct
111 Correct 4 ms 9820 KB Output is correct
112 Correct 4 ms 9820 KB Output is correct
113 Correct 512 ms 95356 KB Output is correct
114 Correct 541 ms 95348 KB Output is correct
115 Correct 532 ms 95272 KB Output is correct
116 Correct 486 ms 95248 KB Output is correct
117 Correct 696 ms 96336 KB Output is correct
118 Correct 501 ms 95368 KB Output is correct
119 Correct 511 ms 95196 KB Output is correct
120 Correct 281 ms 93776 KB Output is correct
121 Correct 297 ms 93772 KB Output is correct
122 Correct 283 ms 93780 KB Output is correct
123 Correct 262 ms 92896 KB Output is correct
124 Correct 258 ms 92952 KB Output is correct
125 Correct 251 ms 93012 KB Output is correct
126 Correct 708 ms 92884 KB Output is correct
127 Correct 720 ms 93012 KB Output is correct
128 Correct 722 ms 96340 KB Output is correct
129 Correct 762 ms 93008 KB Output is correct
130 Correct 507 ms 93008 KB Output is correct
131 Correct 503 ms 93012 KB Output is correct
132 Correct 510 ms 92896 KB Output is correct
133 Correct 734 ms 96340 KB Output is correct
134 Correct 733 ms 96340 KB Output is correct
135 Correct 727 ms 96336 KB Output is correct
136 Correct 130 ms 13140 KB Output is correct
137 Correct 134 ms 13140 KB Output is correct
138 Correct 135 ms 13136 KB Output is correct