답안 #336646

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
336646 2020-12-16T08:01:09 Z monkey8 Progression (NOI20_progression) C++14
100 / 100
1653 ms 83180 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cstdio>
#include <utility> 
#include <queue>
#include <math.h>
#include <set>
#include <bitset>
#include <cmath>
#include <bitset>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MAXN = 300010;
struct node {
    int maxleft, maxright, maxtot;
    ll kleft, kright, valleft, valright;
} st[MAXN << 2];
ll lazy[MAXN << 2];
int lazyClear[MAXN << 2];
ll lazyS[MAXN << 2];
ll lazyC[MAXN << 2];
ll val[MAXN];
int left(int p) {
    return (p << 1);
}
int right(int p) {
    return (p << 1) + 1;
}
node merge(node p1, int l1, int r1, node p2, int l2, int r2) {
    node newNode = node{p1.maxleft, p2.maxright, max(p1.maxtot, max(p2.maxtot, 2)), p1.kleft, p2.kright, p1.valleft, p2.valright};
    int num1 = r1 - l1 + 1;
    int num2 = r2 - l2 + 1;
    if(num1 == p1.maxleft) {
        if(p1.maxleft == 1 && p2.maxleft == 1) {
            newNode.maxleft = 2;
            newNode.kleft = p2.valleft - p1.valright;
        }
        else if(p1.maxleft == 1) {
            if(p2.valleft - p1.valright == p2.kleft) {
                newNode.maxleft = 1 + p2.maxleft;
                newNode.kleft = p2.kleft;
            }
            else {
                newNode.maxleft = 2;
                newNode.kleft = p2.valleft - p1.valright;
            }
        }
        else if(p2.maxleft == 1) {
            if(p2.valleft - p1.valright == p1.kleft) {
                newNode.maxleft = p1.maxleft + 1;
                newNode.kleft = p1.kleft;
            }
        }
        else {
            if(p1.kleft == p2.kleft && p2.valleft - p1.valright == p1.kleft) {
                newNode.maxleft = p1.maxleft + p2.maxleft;
                newNode.kleft = p1.kleft;
            }
            else if(p2.valleft - p1.valright == p1.kleft) {
                newNode.maxleft = p1.maxleft + 1;
                newNode.kleft = p1.kleft;
            }
        }
    }
    if(num2 == p2.maxright) {
        if(p1.maxright == 1 && p2.maxright == 1) {
            newNode.maxright = 2;
            newNode.kright = p2.valleft - p1.valright;
        }
        else if(p1.maxright == 1) {
            if(p2.valleft - p1.valright == p2.kright) {
                newNode.maxright = 1 + p2.maxright;
                newNode.kright = p2.kright;
            }
        }
        else if(p2.maxright == 1) {
            if(p2.valleft - p1.valright == p1.kright) {
                newNode.maxright = p1.maxright + 1;
                newNode.kright = p1.kright;
            }
            else {
                newNode.maxright = 2;
                newNode.kright = p2.valleft - p1.valright;
            }
        }
        else {
            if(p1.kright == p2.kright && p2.valleft - p1.valright == p1.kright) {
                newNode.maxright = p1.maxright + p2.maxright;
                newNode.kright = p1.kright;
            }
            else if(p2.valleft - p1.valright == p2.kright) {
                newNode.maxright = 1 + p2.maxright;
                newNode.kright = p2.kright;
            }
        }
    }
    if(p1.maxright == 1 && p2.maxleft == 1) newNode.maxtot = max(newNode.maxtot, 2);
    else if(p1.maxright == 1) {
        if(p2.valleft - p1.valright == p2.kleft) newNode.maxtot = max(newNode.maxtot, 1 + p2.maxleft);
    }
    else if(p2.maxleft == 1) {
        if(p2.valleft - p1.valright == p1.kright) newNode.maxtot = max(newNode.maxtot, p1.maxright + 1);
    }
    else {
        if(p1.kright == p2.kleft && p2.valleft - p1.valright == p1.kright) newNode.maxtot = max(newNode.maxtot, p1.maxright + p2.maxleft);
        else if(p2.valleft - p1.valright == p1.kright) newNode.maxtot = max(newNode.maxtot, p1.maxright + 1);
        else if(p2.valleft - p1.valright == p2.kleft) newNode.maxtot = max(newNode.maxtot, 1 + p2.maxleft);
    }
    return newNode;
}
void build(int p, int L, int R) {
    if(L == R) st[p] = node{1, 1, 1, 0, 0, val[L], val[R]};
    else {
        build(left(p), L, (L + R)/2);
        build(right(p), (L + R)/2 + 1, R);
        st[p] = merge(st[left(p)], L, (L + R)/2, st[right(p)], (L + R)/2 + 1, R);
    }
}
void push(int p, int L, int R) {
    if(lazyClear[p] == 1) st[p] = node{R - L + 1, R - L + 1, R - L + 1, 0, 0, 0, 0};
    st[p].valleft += lazyS[p] + lazyC[p] * (ll)L;
    st[p].valright += lazyS[p] + lazyC[p] * (ll)R;
    st[p].kleft += lazyC[p];
    st[p].kright += lazyC[p];
    if(L != R) {
        if(lazyClear[p] == 1) {
            lazyClear[left(p)] = 1;
            lazyClear[right(p)] = 1;
            lazyS[left(p)] = 0;
            lazyC[left(p)] = 0;
            lazyS[right(p)] = 0;
            lazyC[right(p)] = 0;
        }
        lazyS[left(p)] += lazyS[p];
        lazyC[left(p)] += lazyC[p];
        lazyS[right(p)] += lazyS[p];
        lazyC[right(p)] += lazyC[p];
    }
    lazyClear[p] = 0;
    lazyS[p] = 0;
    lazyC[p] = 0;
}
void update(int p, int L, int R, int i, int j, ll valS, ll valC) {
    push(p, L, R);
    if(i > R || j < L) return;
    if(L >= i && R <= j) {
        lazyS[p] = valS;
        lazyC[p] = valC;
        push(p, L, R);
        return;
    }
    update(left(p), L, (L + R)/2, i, j, valS, valC);
    update(right(p), (L + R)/2 + 1, R, i, j, valS, valC);
    st[p] = merge(st[left(p)], L, (L + R)/2, st[right(p)], (L + R)/2 + 1, R);
}
void updateClear(int p, int L, int R, int i, int j) {
    push(p, L, R);
    if(i > R || j < L) return;
    if(L >= i && R <= j) {
        lazyS[p] = 0;
        lazyC[p] = 0;
        lazyClear[p] = 1;
        push(p, L, R);
        return;
    }
    updateClear(left(p), L, (L + R)/2, i, j);
    updateClear(right(p), (L + R)/2 + 1, R, i, j);
    st[p] = merge(st[left(p)], L, (L + R)/2, st[right(p)], (L + R)/2 + 1, R);
}
node query(int p, int L, int R, int i, int j) {
    push(p, L, R);
    if(i > R || j < L) return node{-1, 0, 0, 0, 0, 0, 0};
    if(L >= i && R <= j) return st[p];
    node p1 = query(left(p), L, (L + R)/2, i, j);
    node p2 = query(right(p), (L + R)/2 + 1, R, i, j);
    if(p1.maxleft == -1) return p2; 
    if(p2.maxleft == -1) return p1;
    return merge(p1, L, (L + R)/2, p2, (L + R)/2 + 1, R);
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int n, q; cin >> n >> q;
    for(int i = 0; i < n; i++)
        cin >> val[i];
    build(1, 0, n - 1);
    for(int i = 0; i < q; i++) {
        int x; cin >> x;
        if(x == 3) {
            int l, r; cin >> l >> r;
            cout << query(1, 0, n - 1, l - 1, r - 1).maxtot << '\n';
        }
        else {
            int l, r; ll s, c; cin >> l >> r >> s >> c;
            if(x == 2) updateClear(1, 0, n - 1, l - 1, r - 1);
            update(1, 0, n - 1, l - 1, r - 1, s - (ll)(l - 1) * c, c);
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 189 ms 53100 KB Output is correct
2 Correct 107 ms 3712 KB Output is correct
3 Correct 104 ms 3692 KB Output is correct
4 Correct 103 ms 3692 KB Output is correct
5 Correct 107 ms 3692 KB Output is correct
6 Correct 105 ms 3820 KB Output is correct
7 Correct 103 ms 3564 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 190 ms 60524 KB Output is correct
12 Correct 198 ms 60524 KB Output is correct
13 Correct 195 ms 60908 KB Output is correct
14 Correct 197 ms 60908 KB Output is correct
15 Correct 192 ms 60780 KB Output is correct
16 Correct 193 ms 60524 KB Output is correct
17 Correct 194 ms 60652 KB Output is correct
18 Correct 198 ms 60620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 3 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 3 ms 492 KB Output is correct
9 Correct 3 ms 492 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 2 ms 492 KB Output is correct
12 Correct 3 ms 492 KB Output is correct
13 Correct 2 ms 492 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
15 Correct 3 ms 492 KB Output is correct
16 Correct 3 ms 492 KB Output is correct
17 Correct 3 ms 492 KB Output is correct
18 Correct 3 ms 544 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 603 ms 73580 KB Output is correct
2 Correct 142 ms 1004 KB Output is correct
3 Correct 142 ms 1004 KB Output is correct
4 Correct 150 ms 1132 KB Output is correct
5 Correct 147 ms 1132 KB Output is correct
6 Correct 144 ms 1132 KB Output is correct
7 Correct 143 ms 1004 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 728 ms 73364 KB Output is correct
12 Correct 615 ms 73708 KB Output is correct
13 Correct 736 ms 73412 KB Output is correct
14 Correct 743 ms 73324 KB Output is correct
15 Correct 596 ms 73580 KB Output is correct
16 Correct 740 ms 73964 KB Output is correct
17 Correct 737 ms 73964 KB Output is correct
18 Correct 776 ms 74100 KB Output is correct
19 Correct 642 ms 73280 KB Output is correct
20 Correct 632 ms 73196 KB Output is correct
21 Correct 653 ms 73196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1061 ms 77000 KB Output is correct
2 Correct 213 ms 3692 KB Output is correct
3 Correct 214 ms 3692 KB Output is correct
4 Correct 214 ms 3820 KB Output is correct
5 Correct 217 ms 3820 KB Output is correct
6 Correct 220 ms 3720 KB Output is correct
7 Correct 217 ms 3920 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1089 ms 79340 KB Output is correct
12 Correct 1065 ms 82412 KB Output is correct
13 Correct 1089 ms 79084 KB Output is correct
14 Correct 1116 ms 79084 KB Output is correct
15 Correct 999 ms 82412 KB Output is correct
16 Correct 1098 ms 82412 KB Output is correct
17 Correct 1112 ms 82412 KB Output is correct
18 Correct 1110 ms 82540 KB Output is correct
19 Correct 1034 ms 82412 KB Output is correct
20 Correct 1038 ms 82372 KB Output is correct
21 Correct 1035 ms 82284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 603 ms 73580 KB Output is correct
2 Correct 142 ms 1004 KB Output is correct
3 Correct 142 ms 1004 KB Output is correct
4 Correct 150 ms 1132 KB Output is correct
5 Correct 147 ms 1132 KB Output is correct
6 Correct 144 ms 1132 KB Output is correct
7 Correct 143 ms 1004 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 728 ms 73364 KB Output is correct
12 Correct 615 ms 73708 KB Output is correct
13 Correct 736 ms 73412 KB Output is correct
14 Correct 743 ms 73324 KB Output is correct
15 Correct 596 ms 73580 KB Output is correct
16 Correct 740 ms 73964 KB Output is correct
17 Correct 737 ms 73964 KB Output is correct
18 Correct 776 ms 74100 KB Output is correct
19 Correct 642 ms 73280 KB Output is correct
20 Correct 632 ms 73196 KB Output is correct
21 Correct 653 ms 73196 KB Output is correct
22 Correct 1216 ms 73068 KB Output is correct
23 Correct 192 ms 1004 KB Output is correct
24 Correct 187 ms 1004 KB Output is correct
25 Correct 190 ms 1132 KB Output is correct
26 Correct 191 ms 1132 KB Output is correct
27 Correct 193 ms 1004 KB Output is correct
28 Correct 191 ms 1004 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1309 ms 73196 KB Output is correct
33 Correct 1192 ms 73068 KB Output is correct
34 Correct 1270 ms 73260 KB Output is correct
35 Correct 1244 ms 73324 KB Output is correct
36 Correct 1151 ms 73580 KB Output is correct
37 Correct 1114 ms 73708 KB Output is correct
38 Correct 1125 ms 73568 KB Output is correct
39 Correct 1220 ms 73452 KB Output is correct
40 Correct 1270 ms 73532 KB Output is correct
41 Correct 1264 ms 73576 KB Output is correct
42 Correct 1331 ms 73404 KB Output is correct
43 Correct 1214 ms 73324 KB Output is correct
44 Correct 1195 ms 73360 KB Output is correct
45 Correct 1184 ms 73068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 189 ms 53100 KB Output is correct
2 Correct 107 ms 3712 KB Output is correct
3 Correct 104 ms 3692 KB Output is correct
4 Correct 103 ms 3692 KB Output is correct
5 Correct 107 ms 3692 KB Output is correct
6 Correct 105 ms 3820 KB Output is correct
7 Correct 103 ms 3564 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 190 ms 60524 KB Output is correct
12 Correct 198 ms 60524 KB Output is correct
13 Correct 195 ms 60908 KB Output is correct
14 Correct 197 ms 60908 KB Output is correct
15 Correct 192 ms 60780 KB Output is correct
16 Correct 193 ms 60524 KB Output is correct
17 Correct 194 ms 60652 KB Output is correct
18 Correct 198 ms 60620 KB Output is correct
19 Correct 3 ms 492 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 3 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 3 ms 492 KB Output is correct
27 Correct 3 ms 492 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
29 Correct 2 ms 492 KB Output is correct
30 Correct 3 ms 492 KB Output is correct
31 Correct 2 ms 492 KB Output is correct
32 Correct 2 ms 492 KB Output is correct
33 Correct 3 ms 492 KB Output is correct
34 Correct 3 ms 492 KB Output is correct
35 Correct 3 ms 492 KB Output is correct
36 Correct 3 ms 544 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 603 ms 73580 KB Output is correct
41 Correct 142 ms 1004 KB Output is correct
42 Correct 142 ms 1004 KB Output is correct
43 Correct 150 ms 1132 KB Output is correct
44 Correct 147 ms 1132 KB Output is correct
45 Correct 144 ms 1132 KB Output is correct
46 Correct 143 ms 1004 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 1 ms 364 KB Output is correct
50 Correct 728 ms 73364 KB Output is correct
51 Correct 615 ms 73708 KB Output is correct
52 Correct 736 ms 73412 KB Output is correct
53 Correct 743 ms 73324 KB Output is correct
54 Correct 596 ms 73580 KB Output is correct
55 Correct 740 ms 73964 KB Output is correct
56 Correct 737 ms 73964 KB Output is correct
57 Correct 776 ms 74100 KB Output is correct
58 Correct 642 ms 73280 KB Output is correct
59 Correct 632 ms 73196 KB Output is correct
60 Correct 653 ms 73196 KB Output is correct
61 Correct 1061 ms 77000 KB Output is correct
62 Correct 213 ms 3692 KB Output is correct
63 Correct 214 ms 3692 KB Output is correct
64 Correct 214 ms 3820 KB Output is correct
65 Correct 217 ms 3820 KB Output is correct
66 Correct 220 ms 3720 KB Output is correct
67 Correct 217 ms 3920 KB Output is correct
68 Correct 1 ms 364 KB Output is correct
69 Correct 1 ms 364 KB Output is correct
70 Correct 1 ms 364 KB Output is correct
71 Correct 1089 ms 79340 KB Output is correct
72 Correct 1065 ms 82412 KB Output is correct
73 Correct 1089 ms 79084 KB Output is correct
74 Correct 1116 ms 79084 KB Output is correct
75 Correct 999 ms 82412 KB Output is correct
76 Correct 1098 ms 82412 KB Output is correct
77 Correct 1112 ms 82412 KB Output is correct
78 Correct 1110 ms 82540 KB Output is correct
79 Correct 1034 ms 82412 KB Output is correct
80 Correct 1038 ms 82372 KB Output is correct
81 Correct 1035 ms 82284 KB Output is correct
82 Correct 1216 ms 73068 KB Output is correct
83 Correct 192 ms 1004 KB Output is correct
84 Correct 187 ms 1004 KB Output is correct
85 Correct 190 ms 1132 KB Output is correct
86 Correct 191 ms 1132 KB Output is correct
87 Correct 193 ms 1004 KB Output is correct
88 Correct 191 ms 1004 KB Output is correct
89 Correct 1 ms 364 KB Output is correct
90 Correct 1 ms 364 KB Output is correct
91 Correct 1 ms 364 KB Output is correct
92 Correct 1309 ms 73196 KB Output is correct
93 Correct 1192 ms 73068 KB Output is correct
94 Correct 1270 ms 73260 KB Output is correct
95 Correct 1244 ms 73324 KB Output is correct
96 Correct 1151 ms 73580 KB Output is correct
97 Correct 1114 ms 73708 KB Output is correct
98 Correct 1125 ms 73568 KB Output is correct
99 Correct 1220 ms 73452 KB Output is correct
100 Correct 1270 ms 73532 KB Output is correct
101 Correct 1264 ms 73576 KB Output is correct
102 Correct 1331 ms 73404 KB Output is correct
103 Correct 1214 ms 73324 KB Output is correct
104 Correct 1195 ms 73360 KB Output is correct
105 Correct 1184 ms 73068 KB Output is correct
106 Correct 1644 ms 83052 KB Output is correct
107 Correct 258 ms 3820 KB Output is correct
108 Correct 256 ms 3872 KB Output is correct
109 Correct 277 ms 3820 KB Output is correct
110 Correct 1 ms 364 KB Output is correct
111 Correct 1 ms 364 KB Output is correct
112 Correct 1 ms 364 KB Output is correct
113 Correct 1278 ms 81900 KB Output is correct
114 Correct 1283 ms 82216 KB Output is correct
115 Correct 1312 ms 82164 KB Output is correct
116 Correct 1207 ms 82156 KB Output is correct
117 Correct 1653 ms 82956 KB Output is correct
118 Correct 1166 ms 81900 KB Output is correct
119 Correct 1162 ms 81900 KB Output is correct
120 Correct 735 ms 80752 KB Output is correct
121 Correct 741 ms 80364 KB Output is correct
122 Correct 733 ms 80364 KB Output is correct
123 Correct 634 ms 79724 KB Output is correct
124 Correct 640 ms 79596 KB Output is correct
125 Correct 635 ms 79468 KB Output is correct
126 Correct 1577 ms 79664 KB Output is correct
127 Correct 1569 ms 79864 KB Output is correct
128 Correct 1607 ms 82812 KB Output is correct
129 Correct 1636 ms 79468 KB Output is correct
130 Correct 1245 ms 79724 KB Output is correct
131 Correct 1234 ms 79468 KB Output is correct
132 Correct 1238 ms 79852 KB Output is correct
133 Correct 1607 ms 82924 KB Output is correct
134 Correct 1593 ms 83180 KB Output is correct
135 Correct 1606 ms 82984 KB Output is correct
136 Correct 252 ms 3820 KB Output is correct
137 Correct 251 ms 3820 KB Output is correct
138 Correct 254 ms 3820 KB Output is correct