Submission #270687

# Submission time Handle Problem Language Result Execution time Memory
270687 2020-08-17T23:26:42 Z doowey Progression (NOI20_progression) C++14
68 / 100
980 ms 70264 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].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;
        T[node].add_l = 0ll;
        if(cl != cr)T[node * 2].set_l = T[node].set_l;
        if(cl != cr)T[node * 2 + 1].set_l = T[node].set_l;
        T[node].set_l = (ll)1e18;
    }
    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:183:27: warning: 'fs' may be used uninitialized in this function [-Wmaybe-uninitialized]
  183 |             if(r < n) upd1(1, 0, n, r + 1, r + 1, fs-(s+(r-l)*x));
      |                       ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 387 ms 69028 KB Output is correct
2 Correct 144 ms 760 KB Output is correct
3 Correct 145 ms 760 KB Output is correct
4 Correct 171 ms 720 KB Output is correct
5 Correct 146 ms 764 KB Output is correct
6 Correct 146 ms 760 KB Output is correct
7 Correct 145 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 395 ms 69244 KB Output is correct
12 Correct 400 ms 68984 KB Output is correct
13 Correct 396 ms 69368 KB Output is correct
14 Correct 393 ms 69368 KB Output is correct
15 Correct 396 ms 69192 KB Output is correct
16 Correct 401 ms 68984 KB Output is correct
17 Correct 396 ms 69088 KB Output is correct
18 Correct 403 ms 68984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 343 ms 69368 KB Output is correct
2 Correct 103 ms 996 KB Output is correct
3 Correct 100 ms 1016 KB Output is correct
4 Correct 92 ms 1016 KB Output is correct
5 Correct 102 ms 1144 KB Output is correct
6 Correct 104 ms 1112 KB Output is correct
7 Correct 105 ms 1144 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 369 ms 69188 KB Output is correct
12 Correct 331 ms 69624 KB Output is correct
13 Correct 394 ms 69112 KB Output is correct
14 Correct 386 ms 69280 KB Output is correct
15 Correct 329 ms 69368 KB Output is correct
16 Correct 375 ms 69752 KB Output is correct
17 Correct 371 ms 69752 KB Output is correct
18 Correct 370 ms 69880 KB Output is correct
19 Correct 342 ms 69112 KB Output is correct
20 Correct 340 ms 69112 KB Output is correct
21 Correct 340 ms 69084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 690 ms 69064 KB Output is correct
2 Correct 167 ms 1400 KB Output is correct
3 Correct 182 ms 1400 KB Output is correct
4 Correct 168 ms 1400 KB Output is correct
5 Correct 174 ms 1528 KB Output is correct
6 Correct 170 ms 1400 KB Output is correct
7 Correct 170 ms 1400 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 650 ms 69624 KB Output is correct
12 Correct 696 ms 69776 KB Output is correct
13 Correct 664 ms 69624 KB Output is correct
14 Correct 694 ms 69624 KB Output is correct
15 Correct 625 ms 69472 KB Output is correct
16 Correct 666 ms 69652 KB Output is correct
17 Correct 674 ms 69624 KB Output is correct
18 Correct 667 ms 69752 KB Output is correct
19 Correct 644 ms 69624 KB Output is correct
20 Correct 647 ms 69496 KB Output is correct
21 Correct 646 ms 69496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 343 ms 69368 KB Output is correct
2 Correct 103 ms 996 KB Output is correct
3 Correct 100 ms 1016 KB Output is correct
4 Correct 92 ms 1016 KB Output is correct
5 Correct 102 ms 1144 KB Output is correct
6 Correct 104 ms 1112 KB Output is correct
7 Correct 105 ms 1144 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 369 ms 69188 KB Output is correct
12 Correct 331 ms 69624 KB Output is correct
13 Correct 394 ms 69112 KB Output is correct
14 Correct 386 ms 69280 KB Output is correct
15 Correct 329 ms 69368 KB Output is correct
16 Correct 375 ms 69752 KB Output is correct
17 Correct 371 ms 69752 KB Output is correct
18 Correct 370 ms 69880 KB Output is correct
19 Correct 342 ms 69112 KB Output is correct
20 Correct 340 ms 69112 KB Output is correct
21 Correct 340 ms 69084 KB Output is correct
22 Correct 892 ms 70264 KB Output is correct
23 Correct 167 ms 2296 KB Output is correct
24 Correct 167 ms 2296 KB Output is correct
25 Correct 167 ms 2424 KB Output is correct
26 Correct 177 ms 2428 KB Output is correct
27 Correct 172 ms 2296 KB Output is correct
28 Correct 169 ms 2424 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 891 ms 70008 KB Output is correct
33 Correct 863 ms 69964 KB Output is correct
34 Correct 900 ms 70008 KB Output is correct
35 Correct 904 ms 70008 KB Output is correct
36 Correct 720 ms 70032 KB Output is correct
37 Correct 699 ms 70008 KB Output is correct
38 Correct 695 ms 70232 KB Output is correct
39 Correct 925 ms 69828 KB Output is correct
40 Correct 930 ms 69880 KB Output is correct
41 Correct 927 ms 70008 KB Output is correct
42 Correct 980 ms 70008 KB Output is correct
43 Correct 953 ms 70008 KB Output is correct
44 Correct 867 ms 69880 KB Output is correct
45 Correct 868 ms 69880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 387 ms 69028 KB Output is correct
2 Correct 144 ms 760 KB Output is correct
3 Correct 145 ms 760 KB Output is correct
4 Correct 171 ms 720 KB Output is correct
5 Correct 146 ms 764 KB Output is correct
6 Correct 146 ms 760 KB Output is correct
7 Correct 145 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 395 ms 69244 KB Output is correct
12 Correct 400 ms 68984 KB Output is correct
13 Correct 396 ms 69368 KB Output is correct
14 Correct 393 ms 69368 KB Output is correct
15 Correct 396 ms 69192 KB Output is correct
16 Correct 401 ms 68984 KB Output is correct
17 Correct 396 ms 69088 KB Output is correct
18 Correct 403 ms 68984 KB Output is correct
19 Incorrect 3 ms 512 KB Output isn't correct
20 Halted 0 ms 0 KB -