제출 #835697

#제출 시각아이디문제언어결과실행 시간메모리
835697LiudasProgression (NOI20_progression)C++17
35 / 100
948 ms69556 KiB
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <climits>
#define int long long
using namespace std;
class segment_tree{
public:
    struct node{
        int l, r;
        int lmax, rmax, midmax;
        int siz;
    };
    vector<node> tree;
    vector<int> propagate;
    int N;
    segment_tree(int X){
        N = 1;
        while(N <= X){
            N *= 2;
        }
        tree.assign(N * 2, {INT_MIN,INT_MIN,1,1,1,1});
        propagate.assign(N*2, 0);
    }
    void add_val(int val, node &a){
        a.l += val;
        a.r += val;
    }
    void prop(int head){
        add_val(propagate[head], tree[head]);
        if(head >= N){propagate[head] = 0; return;}
        propagate[head * 2 + 1] += propagate[head];
        propagate[head * 2 + 2] += propagate[head];
        propagate[head] = 0;
    }
    node deal_with(node a, node b){
        node c = {INT_MIN,INT_MIN,0,0,0};
        c.l = a.l;
        c.r = b.r;
        c.lmax = a.lmax;
        c.rmax = b.rmax;
        c.siz = a.siz + b.siz;
        if(a.r == b.l && a.rmax == a.siz){
            c.lmax += b.lmax;
        }
        if(a.r == b.l && b.lmax == b.siz){
            c.rmax += a.rmax;
        }
        if(a.r==b.l){
            c.midmax = max(c.midmax, a.rmax + b.lmax);
        }
        c.midmax = max({c.midmax, c.lmax, c.rmax, a.midmax, b.midmax});
        return c;
    }
    void add(int head, int L, int R, int l, int r, int val){
        prop(head);
        if(l <= L && R <= r){
            add_val(val, tree[head]);
            return;
        }
        if(L >= r || R <= l){
            return;
        }
        int mid = (L + R) / 2;
        add(head * 2 + 1, L, mid, l, r, val);
        add(head * 2 + 2, mid, R, l, r, val);
        tree[head] = deal_with(tree[head*2+1], tree[head*2+2]);
    }
    void add(int l, int r, int val){
        add(0, 0, N, l, r, val);
    }
    node get(int head, int L, int R, int l, int r){
        prop(head);
        if(R - L < 1){
            return {INT_MIN, INT_MIN, 0, 0, 0};
        }
        if(l <= L && R <= r){
            return tree[head];
        }
        if(r <= L || R <= l){
            return {INT_MIN, INT_MIN, 0, 0, 0};
        }
        int mid = (L+R)/2;
        return deal_with(get(head * 2 + 1, L, mid, l, r), get(head * 2 + 2, mid, R, l, r));

    }
    node get(int l, int r){
        return get(0, 0, N, l, r);
    }

};
signed main(){
    int N, Q;
    cin >> N >> Q;
    vector<int> arr(N);
    segment_tree tree(N + 5);
    for(int i = 0; i < N; i ++){
        cin >> arr[i];
        if(i > 0){
            tree.add(i, i + 1, arr[i]-arr[i-1]);
        }
    }
    while(Q--){
        int a;
        cin >> a;
        if(a == 3){
            int b, c;
            cin >> b >> c;
            cout << tree.get(b, c).midmax + 1 << endl;
        }
        if(a == 1){
            int b, c, d, e;
            cin >> b >> c >> d >> e;
            int t = (c-b) * e + d;
            //cout << "ADDS  " << b << " " << c << " " << d << " " << e << endl;
            //cout << t << endl;
            //tree.add(b, b+1, d);
            //tree.add(b+1,c,e);
            //tree.add(c, c+1, -t);
            //cout << tree.get(b, c).l << " " << tree.get(b, c).r << endl;
        }
    }
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

Progression.cpp: In function 'int main()':
Progression.cpp:115:17: warning: unused variable 't' [-Wunused-variable]
  115 |             int t = (c-b) * e + d;
      |                 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...