Submission #376260

# Submission time Handle Problem Language Result Execution time Memory
376260 2021-03-11T06:30:57 Z errorgorn Sjeckanje (COCI21_sjeckanje) C++17
0 / 110
91 ms 50540 KB
//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl

#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define up upper_bound

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

int n,q;
ll arr[200005];

struct node{
	int s,e,m;
	ll val=0,lazy=0;
	node *l,*r;
	
	node (int _s,int _e){
		s=_s,e=_e,m=s+e>>1;
		
		if (s!=e){
			l=new node(s,m);
			r=new node(m+1,e);
		}
	}
	
	void propo(){
		if (lazy){
			val+=lazy;
			
			if (s!=e){
				l->lazy+=lazy;
				r->lazy+=lazy;
			}
			lazy=0;
		}
	}
	
	void update(int i,int j,ll k){
		if (s==i && e==j) lazy=k;
		else{
			if (j<=m) l->update(i,j,k);
			else if (m<i) r->update(i,j,k);
			else l->update(i,m,k),r->update(m+1,j,k);
			
			l->propo();
			r->propo();
			val=max(l->val,r->val);
		}
	}
} *root;

void calc(){
	//Crep(x,1,n+1) cout<<arr[x]<<" "; cout<<endl;
	
	root=new node(0,2005);
	
	vector<int> mn={0},mx={0};
	
	rep(x,1,n+1){
		while (mn.back() && arr[mn.back()]>arr[x]){
			root->update(mn[sz(mn)-2]+1,mn.back(),arr[mn.back()]);
			mn.pob();
		}
		root->update(mn.back()+1,x,-arr[x]);
		mn.pub(x);
		
		while (mx.back() && arr[mx.back()]<arr[x]){
			root->update(mx[sz(mx)-2]+1,mx.back(),-arr[mx.back()]);
			mx.pob();
		}
		root->update(mx.back()+1,x,arr[x]);
		mx.pub(x);
		
		//cout<<root->val<<endl;
		root->update(x+1,x+1,root->val);
	}
	
	cout<<root->val<<endl;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin.exceptions(ios::badbit | ios::failbit);
	
	cin>>n>>q;
	rep(x,1,n+1) cin>>arr[x];
	
	int a,b,c;
	rep(x,0,q){
		cin>>a>>b>>c;
		rep(x,a,b+1) arr[x]+=c;
		calc();
	}
	
}

Compilation message

Main.cpp: In constructor 'node::node(int, int)':
Main.cpp:44:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   44 |   s=_s,e=_e,m=s+e>>1;
      |               ~^~
# Verdict Execution time Memory Grader output
1 Incorrect 91 ms 50540 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 91 ms 50540 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 91 ms 50540 KB Output isn't correct
2 Halted 0 ms 0 KB -