Submission #835611

#TimeUsernameProblemLanguageResultExecution timeMemory
835611LiudasProgression (NOI20_progression)C++17
35 / 100
844 ms59780 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; 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}); } void add_val(int val, node &a){ a.l += val; a.r += val; } 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 id, int val){ if(R-L == 1){ add_val(val, tree[head]); return; } int mid = (L + R) / 2; if(id < mid){ add(head * 2 + 1, L, mid, id, val); } else{ add(head * 2 + 2, mid, R, id, val); } tree[head] = deal_with(tree[head*2+1], tree[head*2+2]); } void add(int id, int val){ add(0, 0, N, id, val); } node get(int head, int L, int R, int l, int r){ 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); for(int i = 0; i < N; i ++){ cin >> arr[i]; if(i > 0){ tree.add(i, arr[i]-arr[i-1]); } } while(Q--){ int a; cin >> a; if(a != 3){ return 0; } if(a == 3){ int b, c; cin >> b >> c; cout << tree.get(b, c).midmax + 1 << endl; } } return 0; }
#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...