답안 #336645

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
336645 2020-12-16T07:47:34 Z monkey8 Progression (NOI20_progression) C++14
48 / 100
1188 ms 78188 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];
ll 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) {
    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) {
        lazyS[left(p)] += lazyS[p];
        lazyC[left(p)] += lazyC[p];
        lazyS[right(p)] += lazyS[p];
        lazyC[right(p)] += lazyC[p];
    }
    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);
}
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 if(x == 1) {
            int l, r; ll s, c; cin >> l >> r >> s >> c;
            update(1, 0, n - 1, l - 1, r - 1, s - (ll)(l - 1) * c, c);
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 194 ms 52460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 564 ms 69484 KB Output is correct
2 Correct 157 ms 1004 KB Output is correct
3 Correct 136 ms 1004 KB Output is correct
4 Correct 132 ms 1056 KB Output is correct
5 Correct 151 ms 1132 KB Output is correct
6 Correct 136 ms 1004 KB Output is correct
7 Correct 138 ms 1196 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 672 ms 69356 KB Output is correct
12 Correct 548 ms 69612 KB Output is correct
13 Correct 671 ms 69356 KB Output is correct
14 Correct 669 ms 69228 KB Output is correct
15 Correct 551 ms 69484 KB Output is correct
16 Correct 685 ms 69996 KB Output is correct
17 Correct 685 ms 69868 KB Output is correct
18 Correct 681 ms 70160 KB Output is correct
19 Correct 584 ms 69100 KB Output is correct
20 Correct 601 ms 69100 KB Output is correct
21 Correct 608 ms 69100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 337 ms 68588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 564 ms 69484 KB Output is correct
2 Correct 157 ms 1004 KB Output is correct
3 Correct 136 ms 1004 KB Output is correct
4 Correct 132 ms 1056 KB Output is correct
5 Correct 151 ms 1132 KB Output is correct
6 Correct 136 ms 1004 KB Output is correct
7 Correct 138 ms 1196 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 672 ms 69356 KB Output is correct
12 Correct 548 ms 69612 KB Output is correct
13 Correct 671 ms 69356 KB Output is correct
14 Correct 669 ms 69228 KB Output is correct
15 Correct 551 ms 69484 KB Output is correct
16 Correct 685 ms 69996 KB Output is correct
17 Correct 685 ms 69868 KB Output is correct
18 Correct 681 ms 70160 KB Output is correct
19 Correct 584 ms 69100 KB Output is correct
20 Correct 601 ms 69100 KB Output is correct
21 Correct 608 ms 69100 KB Output is correct
22 Correct 1109 ms 68944 KB Output is correct
23 Correct 179 ms 3692 KB Output is correct
24 Correct 185 ms 3564 KB Output is correct
25 Correct 183 ms 3564 KB Output is correct
26 Correct 188 ms 3692 KB Output is correct
27 Correct 185 ms 3820 KB Output is correct
28 Correct 183 ms 3692 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 1154 ms 74860 KB Output is correct
33 Correct 1096 ms 77676 KB Output is correct
34 Correct 1139 ms 74988 KB Output is correct
35 Correct 1125 ms 74988 KB Output is correct
36 Correct 996 ms 74988 KB Output is correct
37 Correct 1006 ms 74988 KB Output is correct
38 Correct 996 ms 74988 KB Output is correct
39 Correct 1079 ms 77908 KB Output is correct
40 Correct 1136 ms 78060 KB Output is correct
41 Correct 1138 ms 78188 KB Output is correct
42 Correct 1188 ms 77676 KB Output is correct
43 Correct 1114 ms 77676 KB Output is correct
44 Correct 1107 ms 77804 KB Output is correct
45 Correct 1095 ms 77676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 194 ms 52460 KB Output isn't correct
2 Halted 0 ms 0 KB -