답안 #270694

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
270694 2020-08-17T23:52:01 Z doowey Progression (NOI20_progression) C++14
100 / 100
1181 ms 71032 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)3e5 + 10;
const ll inf = (ll)1e12;
const ll F = -inf;

bool debug;

struct Node{
    ll sigma;
    ll set_l;
    ll add_l;
    int siz;
    ll lef_val;
    ll rig_val;
    int answer;
    int ans_pref;
    int ans_suff;
};

Node T[N * 4 + 512];

void push(int node, int cl, int cr){
    if(T[node].set_l != (ll)1e18){
        T[node].set_l += T[node].add_l;
        T[node].sigma = T[node].siz * 1ll * T[node].set_l;
        T[node].lef_val = T[node].set_l;
        T[node].rig_val = T[node].set_l;
        T[node].answer = T[node].siz;
        T[node].ans_pref = T[node].siz;
        T[node].ans_suff = T[node].siz;
        if(cl != cr){
            T[node * 2].set_l = T[node].set_l;
            T[node * 2].add_l = 0;
        }
        if(cl != cr){
            T[node * 2 + 1].set_l = T[node].set_l;
            T[node * 2 + 1].add_l = 0;
        }
        T[node].set_l = (ll)1e18;
        T[node].add_l = 0;
    }
    else if(T[node].add_l != 0){
        T[node].sigma += T[node].siz * 1ll * T[node].add_l;
        T[node].lef_val += T[node].add_l;
        T[node].rig_val += T[node].add_l;
        if(cl != cr)T[node * 2].add_l += T[node].add_l;
        if(cl != cr)T[node * 2 + 1].add_l += T[node].add_l;
        T[node].add_l = 0ll;
    }
}

Node unite(Node A, Node B){
    Node ret;
    ret.sigma = A.sigma + B.sigma;
    ret.add_l = 0ll;
    ret.set_l = (ll)1e18;
    ret.siz = A.siz + B.siz;
    ret.answer = max(A.answer, B.answer);
    ret.lef_val = A.lef_val;
    ret.rig_val = B.rig_val;
    ret.ans_pref = A.ans_pref;
    ret.ans_suff = B.ans_suff;
    if(A.rig_val == B.lef_val){
        ret.answer = max(ret.answer, A.ans_suff + B.ans_pref);
        if(A.ans_pref == A.siz) ret.ans_pref += B.ans_pref;
        if(B.ans_suff == B.siz) ret.ans_suff += A.ans_suff;
    }
    return ret;
}

void upd1(int node, int cl, int cr, int tl, int tr, ll x){
    push(node, cl, cr);
    if(cr < tl || cl > tr)
        return;
    if(cl >= tl && cr <= tr){
        T[node].set_l = x;
        push(node, cl, cr);
        return;
    }
    int mid = (cl + cr) / 2;
    upd1(node * 2, cl, mid, tl, tr, x);
    upd1(node * 2 + 1, mid + 1, cr, tl, tr, x);
    T[node] = unite(T[node * 2], T[node * 2 + 1]);
}

void upd2(int node, int cl, int cr, int tl, int tr, ll x){
    push(node, cl, cr);
    if(cr < tl || cl > tr)
        return;
    if(cl >= tl && cr <= tr){
        T[node].add_l = x;
        push(node, cl, cr);
        return;
    }
    int mid = (cl + cr) / 2;
    upd2(node * 2, cl, mid, tl, tr, x);
    upd2(node * 2 + 1, mid + 1, cr, tl, tr, x);
    T[node] = unite(T[node * 2], T[node * 2 + 1]);
}

ll get_sum(int node, int cl, int cr, int tl, int tr){
    push(node, cl, cr);
    if(cr < tl || cl > tr)
        return 0ll;
    if(cl >= tl && cr <= tr){
        return T[node].sigma;
    }
    int mid = (cl + cr) / 2;
    return get_sum(node * 2, cl, mid, tl, tr) + get_sum(node * 2 + 1, mid + 1, cr, tl, tr);
}

Node cur;
bool has;

void query(int node, int cl, int cr, int tl, int tr){
    push(node, cl, cr);
    if(tl > tr) return;
    if(cr < tl) return;
    if(cl > tr) return;
    if(cl >= tl && cr <= tr){
        if(!has) {
            cur = T[node];
            has=true;
        }
        else{
            cur = unite(cur, T[node]);
        }
        return;
    }
    int mid = (cl + cr) / 2;
    query(node * 2, cl, mid, tl, tr);
    query(node * 2 + 1, mid + 1, cr, tl, tr);
}

int n;
ll A[N];

void build(int node, int cl, int cr){
    if(cl == cr){
        T[node] = {A[cl], (ll)1e18, 0ll,cr-cl+1,A[cl],A[cl],1,1,1};
        return;
    }
    int mid = (cl + cr) / 2;
    build(node * 2, cl, mid);
    build(node * 2 + 1, mid + 1, cr);
    T[node] = unite(T[node * 2], T[node * 2 + 1]);
}

int main(){
    fastIO;
    int q;
    cin >> n >> q;
    A[0] = F;
    for(int i = 1; i <= n; i ++ ){
        cin >> A[i];
    }
    for(int i = n; i >= 1; i -- ){
        A[i] = A[i] - A[i - 1];
    }
    build(1, 0, n);
    int type;
    ll l, r, s, x;
    ll fb, fs;
    for(int i = 0 ; i < q; i ++ ){
        cin >> type;
        if(type == 1){
            cin >> l >> r >> s >> x;
            if(l + 1 <= r)upd2(1, 0, n, l + 1, r, x);
            upd2(1, 0, n, l, l, s);
            if(r + 1 <= n)
                upd2(1, 0, n, r + 1, r + 1, -(s + (r - l) * 1ll * x));
        }
        else if(type == 2){
            cin >> l >> r >> s >> x;
            fb = get_sum(1, 0, n, 0, l - 1);
            if(r < n) fs = get_sum(1, 0, n, 0, r + 1);
            upd1(1, 0, n, l, l, s - fb);
            if(l + 1 <= r)upd1(1, 0, n, l + 1, r, x);
            if(r < n) upd1(1, 0, n, r + 1, r + 1, fs-(s+(r-l)*x));
        }
        else{
            cin >> l >> r;
            if(l == r){
                cout << 1 << "\n";
            }
            else{
                has=false;
                query(1, 0, n, l+1, r);
                cout << cur.answer + 1 << "\n";
            }
        }
    }
    return 0;
}

Compilation message

Progression.cpp: In function 'int main()':
Progression.cpp:190:27: warning: 'fs' may be used uninitialized in this function [-Wmaybe-uninitialized]
  190 |             if(r < n) upd1(1, 0, n, r + 1, r + 1, fs-(s+(r-l)*x));
      |                       ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 416 ms 69112 KB Output is correct
2 Correct 147 ms 632 KB Output is correct
3 Correct 150 ms 724 KB Output is correct
4 Correct 145 ms 720 KB Output is correct
5 Correct 142 ms 760 KB Output is correct
6 Correct 149 ms 764 KB Output is correct
7 Correct 142 ms 632 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 393 ms 69252 KB Output is correct
12 Correct 398 ms 69068 KB Output is correct
13 Correct 390 ms 69216 KB Output is correct
14 Correct 389 ms 69212 KB Output is correct
15 Correct 398 ms 69184 KB Output is correct
16 Correct 398 ms 68984 KB Output is correct
17 Correct 406 ms 69104 KB Output is correct
18 Correct 400 ms 68984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 2 ms 512 KB Output is correct
18 Correct 2 ms 544 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 322 ms 69368 KB Output is correct
2 Correct 104 ms 1028 KB Output is correct
3 Correct 97 ms 1020 KB Output is correct
4 Correct 90 ms 1016 KB Output is correct
5 Correct 100 ms 1016 KB Output is correct
6 Correct 100 ms 1020 KB Output is correct
7 Correct 100 ms 1016 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 383 ms 69240 KB Output is correct
12 Correct 342 ms 69496 KB Output is correct
13 Correct 400 ms 69176 KB Output is correct
14 Correct 392 ms 69240 KB Output is correct
15 Correct 319 ms 69496 KB Output is correct
16 Correct 400 ms 69880 KB Output is correct
17 Correct 396 ms 69740 KB Output is correct
18 Correct 374 ms 69844 KB Output is correct
19 Correct 335 ms 69048 KB Output is correct
20 Correct 395 ms 69112 KB Output is correct
21 Correct 338 ms 69112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 706 ms 68856 KB Output is correct
2 Correct 164 ms 632 KB Output is correct
3 Correct 169 ms 632 KB Output is correct
4 Correct 165 ms 504 KB Output is correct
5 Correct 170 ms 504 KB Output is correct
6 Correct 172 ms 516 KB Output is correct
7 Correct 169 ms 760 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 670 ms 68796 KB Output is correct
12 Correct 694 ms 68728 KB Output is correct
13 Correct 729 ms 68600 KB Output is correct
14 Correct 655 ms 68600 KB Output is correct
15 Correct 624 ms 68600 KB Output is correct
16 Correct 751 ms 68724 KB Output is correct
17 Correct 686 ms 68856 KB Output is correct
18 Correct 752 ms 68624 KB Output is correct
19 Correct 654 ms 68728 KB Output is correct
20 Correct 643 ms 68604 KB Output is correct
21 Correct 664 ms 68660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 322 ms 69368 KB Output is correct
2 Correct 104 ms 1028 KB Output is correct
3 Correct 97 ms 1020 KB Output is correct
4 Correct 90 ms 1016 KB Output is correct
5 Correct 100 ms 1016 KB Output is correct
6 Correct 100 ms 1020 KB Output is correct
7 Correct 100 ms 1016 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 383 ms 69240 KB Output is correct
12 Correct 342 ms 69496 KB Output is correct
13 Correct 400 ms 69176 KB Output is correct
14 Correct 392 ms 69240 KB Output is correct
15 Correct 319 ms 69496 KB Output is correct
16 Correct 400 ms 69880 KB Output is correct
17 Correct 396 ms 69740 KB Output is correct
18 Correct 374 ms 69844 KB Output is correct
19 Correct 335 ms 69048 KB Output is correct
20 Correct 395 ms 69112 KB Output is correct
21 Correct 338 ms 69112 KB Output is correct
22 Correct 885 ms 68764 KB Output is correct
23 Correct 165 ms 760 KB Output is correct
24 Correct 164 ms 632 KB Output is correct
25 Correct 163 ms 632 KB Output is correct
26 Correct 168 ms 632 KB Output is correct
27 Correct 165 ms 632 KB Output is correct
28 Correct 166 ms 712 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1008 ms 68984 KB Output is correct
33 Correct 932 ms 68728 KB Output is correct
34 Correct 972 ms 68856 KB Output is correct
35 Correct 985 ms 68984 KB Output is correct
36 Correct 703 ms 69112 KB Output is correct
37 Correct 741 ms 69112 KB Output is correct
38 Correct 746 ms 68972 KB Output is correct
39 Correct 904 ms 68728 KB Output is correct
40 Correct 916 ms 68856 KB Output is correct
41 Correct 946 ms 68852 KB Output is correct
42 Correct 1020 ms 68860 KB Output is correct
43 Correct 912 ms 68984 KB Output is correct
44 Correct 872 ms 68856 KB Output is correct
45 Correct 885 ms 68980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 416 ms 69112 KB Output is correct
2 Correct 147 ms 632 KB Output is correct
3 Correct 150 ms 724 KB Output is correct
4 Correct 145 ms 720 KB Output is correct
5 Correct 142 ms 760 KB Output is correct
6 Correct 149 ms 764 KB Output is correct
7 Correct 142 ms 632 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 393 ms 69252 KB Output is correct
12 Correct 398 ms 69068 KB Output is correct
13 Correct 390 ms 69216 KB Output is correct
14 Correct 389 ms 69212 KB Output is correct
15 Correct 398 ms 69184 KB Output is correct
16 Correct 398 ms 68984 KB Output is correct
17 Correct 406 ms 69104 KB Output is correct
18 Correct 400 ms 68984 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 2 ms 512 KB Output is correct
27 Correct 2 ms 512 KB Output is correct
28 Correct 2 ms 512 KB Output is correct
29 Correct 1 ms 512 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 2 ms 512 KB Output is correct
33 Correct 2 ms 512 KB Output is correct
34 Correct 2 ms 512 KB Output is correct
35 Correct 2 ms 512 KB Output is correct
36 Correct 2 ms 544 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 2 ms 384 KB Output is correct
40 Correct 322 ms 69368 KB Output is correct
41 Correct 104 ms 1028 KB Output is correct
42 Correct 97 ms 1020 KB Output is correct
43 Correct 90 ms 1016 KB Output is correct
44 Correct 100 ms 1016 KB Output is correct
45 Correct 100 ms 1020 KB Output is correct
46 Correct 100 ms 1016 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 1 ms 384 KB Output is correct
50 Correct 383 ms 69240 KB Output is correct
51 Correct 342 ms 69496 KB Output is correct
52 Correct 400 ms 69176 KB Output is correct
53 Correct 392 ms 69240 KB Output is correct
54 Correct 319 ms 69496 KB Output is correct
55 Correct 400 ms 69880 KB Output is correct
56 Correct 396 ms 69740 KB Output is correct
57 Correct 374 ms 69844 KB Output is correct
58 Correct 335 ms 69048 KB Output is correct
59 Correct 395 ms 69112 KB Output is correct
60 Correct 338 ms 69112 KB Output is correct
61 Correct 706 ms 68856 KB Output is correct
62 Correct 164 ms 632 KB Output is correct
63 Correct 169 ms 632 KB Output is correct
64 Correct 165 ms 504 KB Output is correct
65 Correct 170 ms 504 KB Output is correct
66 Correct 172 ms 516 KB Output is correct
67 Correct 169 ms 760 KB Output is correct
68 Correct 2 ms 384 KB Output is correct
69 Correct 1 ms 384 KB Output is correct
70 Correct 1 ms 384 KB Output is correct
71 Correct 670 ms 68796 KB Output is correct
72 Correct 694 ms 68728 KB Output is correct
73 Correct 729 ms 68600 KB Output is correct
74 Correct 655 ms 68600 KB Output is correct
75 Correct 624 ms 68600 KB Output is correct
76 Correct 751 ms 68724 KB Output is correct
77 Correct 686 ms 68856 KB Output is correct
78 Correct 752 ms 68624 KB Output is correct
79 Correct 654 ms 68728 KB Output is correct
80 Correct 643 ms 68604 KB Output is correct
81 Correct 664 ms 68660 KB Output is correct
82 Correct 885 ms 68764 KB Output is correct
83 Correct 165 ms 760 KB Output is correct
84 Correct 164 ms 632 KB Output is correct
85 Correct 163 ms 632 KB Output is correct
86 Correct 168 ms 632 KB Output is correct
87 Correct 165 ms 632 KB Output is correct
88 Correct 166 ms 712 KB Output is correct
89 Correct 1 ms 384 KB Output is correct
90 Correct 1 ms 384 KB Output is correct
91 Correct 1 ms 384 KB Output is correct
92 Correct 1008 ms 68984 KB Output is correct
93 Correct 932 ms 68728 KB Output is correct
94 Correct 972 ms 68856 KB Output is correct
95 Correct 985 ms 68984 KB Output is correct
96 Correct 703 ms 69112 KB Output is correct
97 Correct 741 ms 69112 KB Output is correct
98 Correct 746 ms 68972 KB Output is correct
99 Correct 904 ms 68728 KB Output is correct
100 Correct 916 ms 68856 KB Output is correct
101 Correct 946 ms 68852 KB Output is correct
102 Correct 1020 ms 68860 KB Output is correct
103 Correct 912 ms 68984 KB Output is correct
104 Correct 872 ms 68856 KB Output is correct
105 Correct 885 ms 68980 KB Output is correct
106 Correct 1167 ms 70060 KB Output is correct
107 Correct 217 ms 1656 KB Output is correct
108 Correct 206 ms 1528 KB Output is correct
109 Correct 246 ms 1528 KB Output is correct
110 Correct 1 ms 384 KB Output is correct
111 Correct 1 ms 384 KB Output is correct
112 Correct 1 ms 384 KB Output is correct
113 Correct 917 ms 70008 KB Output is correct
114 Correct 916 ms 70008 KB Output is correct
115 Correct 922 ms 69880 KB Output is correct
116 Correct 878 ms 69880 KB Output is correct
117 Correct 1156 ms 70112 KB Output is correct
118 Correct 885 ms 69752 KB Output is correct
119 Correct 894 ms 69780 KB Output is correct
120 Correct 394 ms 71032 KB Output is correct
121 Correct 403 ms 70904 KB Output is correct
122 Correct 405 ms 70888 KB Output is correct
123 Correct 355 ms 70264 KB Output is correct
124 Correct 335 ms 70264 KB Output is correct
125 Correct 342 ms 70152 KB Output is correct
126 Correct 1168 ms 70020 KB Output is correct
127 Correct 1128 ms 69940 KB Output is correct
128 Correct 1127 ms 70264 KB Output is correct
129 Correct 1181 ms 70264 KB Output is correct
130 Correct 811 ms 70628 KB Output is correct
131 Correct 780 ms 70732 KB Output is correct
132 Correct 759 ms 70780 KB Output is correct
133 Correct 1152 ms 70032 KB Output is correct
134 Correct 1142 ms 70008 KB Output is correct
135 Correct 1139 ms 70008 KB Output is correct
136 Correct 209 ms 1528 KB Output is correct
137 Correct 218 ms 1784 KB Output is correct
138 Correct 208 ms 1528 KB Output is correct