답안 #427144

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
427144 2021-06-14T12:47:34 Z egekabas Progression (NOI20_progression) C++14
100 / 100
1769 ms 138616 KB
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
const ll inf = 1e18;
struct node{
    ll lval, rval, sz;
    
    ll lcnt, lslope;
    ll rcnt, rslope;

    ll ans, empty;
    node(){
        empty = 1;   
    }
    node(ll val){
        lval = rval = val;
        sz = 1;
        lcnt = rcnt = 1;
        lslope = rslope = inf;
        ans = 1;
        empty = 0;
    }
    node(ll constant, ll slope, ll sz){
        lval = constant;
        rval = constant+(sz-1)*slope;
        this->sz = sz;

        ans = lcnt = rcnt = sz;
        lslope = rslope = slope;

        empty = 0;
    }
    void updlazy(ll constant, ll slope){
        lval += constant;
        rval += constant+(sz-1)*slope;
        lslope += slope;
        rslope += slope;
    }
};
node merge(node a, node b){
    if(a.empty) return b;
    if(b.empty) return a;
    
    node ret;
    ret.empty = 0;

    ret.sz = a.sz+b.sz;
    ret.lval = a.lval;
    ret.rval = b.rval;

    ret.lcnt = a.lcnt;
    ret.lslope = a.lslope;

    ret.rcnt = b.rcnt;
    ret.rslope = b.rslope;

    ret.ans = max(a.ans, b.ans);
    
    
    ll mslope = b.lval-a.rval;
    
    ll acnt = 1;
    if(mslope == a.rslope)
        acnt = a.rcnt;
    
    ll bcnt = 1;
    if(mslope == b.lslope)
        bcnt = b.lcnt;
    
    ret.ans = max(ret.ans, acnt+bcnt);
    if(acnt == a.sz){
        ret.lcnt = acnt+bcnt;
        ret.lslope = mslope;
    }
    if(bcnt == b.sz){
        ret.rcnt = acnt+bcnt;
        ret.rslope = mslope;
    }
    return ret;
}
ll change[1200009];
pll cval[1200009];
pll add[1200009];
node seg[1200009];
void push(int v, int tl, int tm, int tr){
    if(change[v]){
        change[v] = 0;
        
        seg[2*v] = node(cval[v].ff, cval[v].ss, (tm-tl+1));
        change[2*v] = 1;
        cval[2*v] = {cval[v].ff, cval[v].ss};
        add[2*v] = {0, 0};

        cval[v].ff += (tm-tl+1)*cval[v].ss;
        seg[2*v+1] = node(cval[v].ff, cval[v].ss, (tr-tm));
        change[2*v+1] = 1;
        cval[2*v+1] = {cval[v].ff, cval[v].ss};
        add[2*v+1] = {0, 0};
    }

    seg[2*v].updlazy(add[v].ff, add[v].ss);
    add[2*v].ff += add[v].ff;
    add[2*v].ss += add[v].ss;
    
    add[v].ff += (tm-tl+1)*add[v].ss;
    seg[2*v+1].updlazy(add[v].ff, add[v].ss);
    add[2*v+1].ff += add[v].ff;
    add[2*v+1].ss += add[v].ss;
    
    add[v] = {0, 0};
}
ll a[300009];
void build(ll v, ll tl, ll tr){
    if(tl == tr){
        seg[v] = node(a[tl]);
        return;
    }
    build(2*v, tl, (tl+tr)/2);
    build(2*v+1, (tl+tr)/2+1, tr);
    seg[v] = merge(seg[2*v], seg[2*v+1]);
}
node get(ll v, ll tl, ll tr, ll l, ll r){
    if(tl > r || l > tr)
        return node();
    if(l <= tl && tr <= r)
        return seg[v];
    ll tm = (tl+tr)/2;
    push(v, tl, tm, tr);
    return merge(get(2*v, tl, tm, l, r), get(2*v+1, tm+1, tr, l, r));
}
void upd(ll v, ll tl, ll tr, ll l, ll r, ll type, ll con, ll slope){
    if(tl > r || l > tr)
        return;
    if(l <= tl && tr <= r){
        con += (tl-l)*slope;
        if(type == 0){
            add[v].ff += con;
            add[v].ss += slope;
            seg[v].updlazy(con, slope);
        }
        else{
            add[v] = {0, 0};
            change[v] = 1;
            cval[v] = {con, slope};
            seg[v] = node(con, slope, tr-tl+1);
        }
        return;
    }
    ll tm = (tl+tr)/2;
    push(v, tl, tm, tr);
    upd(2*v, tl, tm, l, r, type, con, slope);
    upd(2*v+1, tm+1, tr, l, r, type, con, slope);
    seg[v] = merge(seg[2*v], seg[2*v+1]);
}
ll n, q;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);

    cin >> n >> q;
    for(ll i = 0; i < n; ++i)
        cin >> a[i];
    build(1, 0, n-1);
    while(q--){
        ll type;
        cin >> type;
        if(type == 1){
            ll l, r, s, c;
            cin >> l >> r >> s >> c;
            --l;
            --r;
            upd(1, 0, n-1, l, r, 0, s, c);
        }
        else if(type == 2){
            ll l, r, s, c;
            cin >> l >> r >> s >> c;
            --l;
            --r;
            upd(1, 0, n-1, l, r, 1, s, c);
        }
        else{
            ll l, r;
            cin >> l >> r;
            --l;
            --r;
            cout << get(1, 0, n-1, l, r).ans << '\n';
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 212 ms 95812 KB Output is correct
2 Correct 145 ms 88056 KB Output is correct
3 Correct 145 ms 88004 KB Output is correct
4 Correct 141 ms 88016 KB Output is correct
5 Correct 141 ms 88096 KB Output is correct
6 Correct 145 ms 88060 KB Output is correct
7 Correct 151 ms 88020 KB Output is correct
8 Correct 35 ms 84856 KB Output is correct
9 Correct 43 ms 84804 KB Output is correct
10 Correct 42 ms 84872 KB Output is correct
11 Correct 223 ms 95824 KB Output is correct
12 Correct 234 ms 95724 KB Output is correct
13 Correct 216 ms 95940 KB Output is correct
14 Correct 220 ms 96140 KB Output is correct
15 Correct 219 ms 95948 KB Output is correct
16 Correct 225 ms 95808 KB Output is correct
17 Correct 215 ms 95692 KB Output is correct
18 Correct 247 ms 95752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 85060 KB Output is correct
2 Correct 35 ms 84792 KB Output is correct
3 Correct 36 ms 84880 KB Output is correct
4 Correct 36 ms 84828 KB Output is correct
5 Correct 37 ms 84812 KB Output is correct
6 Correct 36 ms 84804 KB Output is correct
7 Correct 42 ms 84812 KB Output is correct
8 Correct 41 ms 84908 KB Output is correct
9 Correct 39 ms 84940 KB Output is correct
10 Correct 39 ms 84908 KB Output is correct
11 Correct 37 ms 84940 KB Output is correct
12 Correct 37 ms 84940 KB Output is correct
13 Correct 37 ms 84932 KB Output is correct
14 Correct 38 ms 84952 KB Output is correct
15 Correct 37 ms 84884 KB Output is correct
16 Correct 39 ms 84952 KB Output is correct
17 Correct 36 ms 84984 KB Output is correct
18 Correct 36 ms 84872 KB Output is correct
19 Correct 45 ms 84844 KB Output is correct
20 Correct 37 ms 84860 KB Output is correct
21 Correct 35 ms 84824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 670 ms 110588 KB Output is correct
2 Correct 188 ms 87508 KB Output is correct
3 Correct 196 ms 87556 KB Output is correct
4 Correct 187 ms 87512 KB Output is correct
5 Correct 209 ms 87704 KB Output is correct
6 Correct 187 ms 87656 KB Output is correct
7 Correct 180 ms 87732 KB Output is correct
8 Correct 36 ms 84812 KB Output is correct
9 Correct 38 ms 84932 KB Output is correct
10 Correct 35 ms 84812 KB Output is correct
11 Correct 823 ms 109300 KB Output is correct
12 Correct 846 ms 110608 KB Output is correct
13 Correct 979 ms 109320 KB Output is correct
14 Correct 964 ms 109316 KB Output is correct
15 Correct 747 ms 110628 KB Output is correct
16 Correct 942 ms 111244 KB Output is correct
17 Correct 895 ms 111184 KB Output is correct
18 Correct 903 ms 111288 KB Output is correct
19 Correct 855 ms 110620 KB Output is correct
20 Correct 842 ms 110612 KB Output is correct
21 Correct 827 ms 110572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1192 ms 131892 KB Output is correct
2 Correct 261 ms 88192 KB Output is correct
3 Correct 270 ms 88188 KB Output is correct
4 Correct 267 ms 88188 KB Output is correct
5 Correct 249 ms 88320 KB Output is correct
6 Correct 262 ms 88236 KB Output is correct
7 Correct 237 ms 88184 KB Output is correct
8 Correct 40 ms 84828 KB Output is correct
9 Correct 40 ms 84808 KB Output is correct
10 Correct 51 ms 84888 KB Output is correct
11 Correct 1202 ms 128584 KB Output is correct
12 Correct 1270 ms 131884 KB Output is correct
13 Correct 1154 ms 128628 KB Output is correct
14 Correct 1180 ms 128632 KB Output is correct
15 Correct 1224 ms 131780 KB Output is correct
16 Correct 1304 ms 131912 KB Output is correct
17 Correct 1277 ms 131976 KB Output is correct
18 Correct 1204 ms 132088 KB Output is correct
19 Correct 1155 ms 131892 KB Output is correct
20 Correct 1085 ms 131912 KB Output is correct
21 Correct 1101 ms 131932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 670 ms 110588 KB Output is correct
2 Correct 188 ms 87508 KB Output is correct
3 Correct 196 ms 87556 KB Output is correct
4 Correct 187 ms 87512 KB Output is correct
5 Correct 209 ms 87704 KB Output is correct
6 Correct 187 ms 87656 KB Output is correct
7 Correct 180 ms 87732 KB Output is correct
8 Correct 36 ms 84812 KB Output is correct
9 Correct 38 ms 84932 KB Output is correct
10 Correct 35 ms 84812 KB Output is correct
11 Correct 823 ms 109300 KB Output is correct
12 Correct 846 ms 110608 KB Output is correct
13 Correct 979 ms 109320 KB Output is correct
14 Correct 964 ms 109316 KB Output is correct
15 Correct 747 ms 110628 KB Output is correct
16 Correct 942 ms 111244 KB Output is correct
17 Correct 895 ms 111184 KB Output is correct
18 Correct 903 ms 111288 KB Output is correct
19 Correct 855 ms 110620 KB Output is correct
20 Correct 842 ms 110612 KB Output is correct
21 Correct 827 ms 110572 KB Output is correct
22 Correct 1365 ms 112980 KB Output is correct
23 Correct 244 ms 87996 KB Output is correct
24 Correct 234 ms 88120 KB Output is correct
25 Correct 233 ms 88004 KB Output is correct
26 Correct 239 ms 88036 KB Output is correct
27 Correct 245 ms 88132 KB Output is correct
28 Correct 262 ms 88104 KB Output is correct
29 Correct 48 ms 84804 KB Output is correct
30 Correct 41 ms 84804 KB Output is correct
31 Correct 44 ms 84820 KB Output is correct
32 Correct 1381 ms 110208 KB Output is correct
33 Correct 1351 ms 113080 KB Output is correct
34 Correct 1376 ms 110028 KB Output is correct
35 Correct 1341 ms 110140 KB Output is correct
36 Correct 1278 ms 109920 KB Output is correct
37 Correct 1348 ms 110104 KB Output is correct
38 Correct 1317 ms 109980 KB Output is correct
39 Correct 1430 ms 112896 KB Output is correct
40 Correct 1533 ms 113092 KB Output is correct
41 Correct 1481 ms 112992 KB Output is correct
42 Correct 1498 ms 112896 KB Output is correct
43 Correct 1395 ms 112876 KB Output is correct
44 Correct 1318 ms 112912 KB Output is correct
45 Correct 1354 ms 113012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 212 ms 95812 KB Output is correct
2 Correct 145 ms 88056 KB Output is correct
3 Correct 145 ms 88004 KB Output is correct
4 Correct 141 ms 88016 KB Output is correct
5 Correct 141 ms 88096 KB Output is correct
6 Correct 145 ms 88060 KB Output is correct
7 Correct 151 ms 88020 KB Output is correct
8 Correct 35 ms 84856 KB Output is correct
9 Correct 43 ms 84804 KB Output is correct
10 Correct 42 ms 84872 KB Output is correct
11 Correct 223 ms 95824 KB Output is correct
12 Correct 234 ms 95724 KB Output is correct
13 Correct 216 ms 95940 KB Output is correct
14 Correct 220 ms 96140 KB Output is correct
15 Correct 219 ms 95948 KB Output is correct
16 Correct 225 ms 95808 KB Output is correct
17 Correct 215 ms 95692 KB Output is correct
18 Correct 247 ms 95752 KB Output is correct
19 Correct 36 ms 85060 KB Output is correct
20 Correct 35 ms 84792 KB Output is correct
21 Correct 36 ms 84880 KB Output is correct
22 Correct 36 ms 84828 KB Output is correct
23 Correct 37 ms 84812 KB Output is correct
24 Correct 36 ms 84804 KB Output is correct
25 Correct 42 ms 84812 KB Output is correct
26 Correct 41 ms 84908 KB Output is correct
27 Correct 39 ms 84940 KB Output is correct
28 Correct 39 ms 84908 KB Output is correct
29 Correct 37 ms 84940 KB Output is correct
30 Correct 37 ms 84940 KB Output is correct
31 Correct 37 ms 84932 KB Output is correct
32 Correct 38 ms 84952 KB Output is correct
33 Correct 37 ms 84884 KB Output is correct
34 Correct 39 ms 84952 KB Output is correct
35 Correct 36 ms 84984 KB Output is correct
36 Correct 36 ms 84872 KB Output is correct
37 Correct 45 ms 84844 KB Output is correct
38 Correct 37 ms 84860 KB Output is correct
39 Correct 35 ms 84824 KB Output is correct
40 Correct 670 ms 110588 KB Output is correct
41 Correct 188 ms 87508 KB Output is correct
42 Correct 196 ms 87556 KB Output is correct
43 Correct 187 ms 87512 KB Output is correct
44 Correct 209 ms 87704 KB Output is correct
45 Correct 187 ms 87656 KB Output is correct
46 Correct 180 ms 87732 KB Output is correct
47 Correct 36 ms 84812 KB Output is correct
48 Correct 38 ms 84932 KB Output is correct
49 Correct 35 ms 84812 KB Output is correct
50 Correct 823 ms 109300 KB Output is correct
51 Correct 846 ms 110608 KB Output is correct
52 Correct 979 ms 109320 KB Output is correct
53 Correct 964 ms 109316 KB Output is correct
54 Correct 747 ms 110628 KB Output is correct
55 Correct 942 ms 111244 KB Output is correct
56 Correct 895 ms 111184 KB Output is correct
57 Correct 903 ms 111288 KB Output is correct
58 Correct 855 ms 110620 KB Output is correct
59 Correct 842 ms 110612 KB Output is correct
60 Correct 827 ms 110572 KB Output is correct
61 Correct 1192 ms 131892 KB Output is correct
62 Correct 261 ms 88192 KB Output is correct
63 Correct 270 ms 88188 KB Output is correct
64 Correct 267 ms 88188 KB Output is correct
65 Correct 249 ms 88320 KB Output is correct
66 Correct 262 ms 88236 KB Output is correct
67 Correct 237 ms 88184 KB Output is correct
68 Correct 40 ms 84828 KB Output is correct
69 Correct 40 ms 84808 KB Output is correct
70 Correct 51 ms 84888 KB Output is correct
71 Correct 1202 ms 128584 KB Output is correct
72 Correct 1270 ms 131884 KB Output is correct
73 Correct 1154 ms 128628 KB Output is correct
74 Correct 1180 ms 128632 KB Output is correct
75 Correct 1224 ms 131780 KB Output is correct
76 Correct 1304 ms 131912 KB Output is correct
77 Correct 1277 ms 131976 KB Output is correct
78 Correct 1204 ms 132088 KB Output is correct
79 Correct 1155 ms 131892 KB Output is correct
80 Correct 1085 ms 131912 KB Output is correct
81 Correct 1101 ms 131932 KB Output is correct
82 Correct 1365 ms 112980 KB Output is correct
83 Correct 244 ms 87996 KB Output is correct
84 Correct 234 ms 88120 KB Output is correct
85 Correct 233 ms 88004 KB Output is correct
86 Correct 239 ms 88036 KB Output is correct
87 Correct 245 ms 88132 KB Output is correct
88 Correct 262 ms 88104 KB Output is correct
89 Correct 48 ms 84804 KB Output is correct
90 Correct 41 ms 84804 KB Output is correct
91 Correct 44 ms 84820 KB Output is correct
92 Correct 1381 ms 110208 KB Output is correct
93 Correct 1351 ms 113080 KB Output is correct
94 Correct 1376 ms 110028 KB Output is correct
95 Correct 1341 ms 110140 KB Output is correct
96 Correct 1278 ms 109920 KB Output is correct
97 Correct 1348 ms 110104 KB Output is correct
98 Correct 1317 ms 109980 KB Output is correct
99 Correct 1430 ms 112896 KB Output is correct
100 Correct 1533 ms 113092 KB Output is correct
101 Correct 1481 ms 112992 KB Output is correct
102 Correct 1498 ms 112896 KB Output is correct
103 Correct 1395 ms 112876 KB Output is correct
104 Correct 1318 ms 112912 KB Output is correct
105 Correct 1354 ms 113012 KB Output is correct
106 Correct 1765 ms 138616 KB Output is correct
107 Correct 309 ms 88208 KB Output is correct
108 Correct 267 ms 88364 KB Output is correct
109 Correct 267 ms 88260 KB Output is correct
110 Correct 44 ms 84804 KB Output is correct
111 Correct 47 ms 84932 KB Output is correct
112 Correct 44 ms 84812 KB Output is correct
113 Correct 1419 ms 112964 KB Output is correct
114 Correct 1391 ms 112956 KB Output is correct
115 Correct 1431 ms 112984 KB Output is correct
116 Correct 1360 ms 112900 KB Output is correct
117 Correct 1769 ms 138400 KB Output is correct
118 Correct 1295 ms 112908 KB Output is correct
119 Correct 1384 ms 112948 KB Output is correct
120 Correct 829 ms 111428 KB Output is correct
121 Correct 865 ms 111396 KB Output is correct
122 Correct 881 ms 111372 KB Output is correct
123 Correct 727 ms 110724 KB Output is correct
124 Correct 771 ms 110624 KB Output is correct
125 Correct 781 ms 110516 KB Output is correct
126 Correct 1639 ms 135088 KB Output is correct
127 Correct 1698 ms 135300 KB Output is correct
128 Correct 1657 ms 138388 KB Output is correct
129 Correct 1652 ms 135236 KB Output is correct
130 Correct 1425 ms 135328 KB Output is correct
131 Correct 1437 ms 135264 KB Output is correct
132 Correct 1462 ms 135196 KB Output is correct
133 Correct 1736 ms 138528 KB Output is correct
134 Correct 1655 ms 138580 KB Output is correct
135 Correct 1711 ms 138576 KB Output is correct
136 Correct 282 ms 88208 KB Output is correct
137 Correct 250 ms 88196 KB Output is correct
138 Correct 256 ms 88276 KB Output is correct