Submission #934227

# Submission time Handle Problem Language Result Execution time Memory
934227 2024-02-27T02:49:06 Z beepbeepsheep Divide and conquer (IZhO14_divide) C++17
100 / 100
142 ms 22920 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef tree<long long, null_type, less_equal<>,
        rb_tree_tag, tree_order_statistics_node_update>
        ordered_set;
        
#define ll long long
#define ii pair<ll,ll>
#define iii tuple<ll,ll,ll>

#ifndef DEBUG
#define cerr if (0) cerr
#define endl '\n'
#endif

const ll inf=1e15;
const ll maxn=2e5+5;
const ll mod=1e9+7;

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

ll arr[maxn],brr[maxn],crr[maxn];
ll pref[maxn];
ll bpref[maxn];
struct node{
	ll s,e,m,val;
	node *l, *r;
	node(ll _s, ll _e){
		s=_s,e=_e,m=(s+e)>>1,val=0;
		if (s!=e) l=new node(s,m),r=new node(m+1,e);
	}
	void upd(ll x, ll v){
		if (s==e){
			val=v;
			return;
		}
		if (x>m) r->upd(x,v);
		else l->upd(x,v);
		val=max(l->val,r->val);
	}
	ll query(ll x, ll y){
		if (x<=s && e<=y) return val;
		if (x>m) return r->query(x,y);
		if (y<=m) return l->query(x,y);
		return max(l->query(x,y),r->query(x,y));
	}
}*root;
ll n;
ll find(ll x, ll s){
	ll l=s,r=n+1,m; //left is legal for sure
	while (l!=r-1){
		m=(l+r)>>1;
		if (root->query(m,n)>=x) l=m;
		else r=m;
	}
	return l;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	root=new node(1,n);
	for (int i=1;i<=n;i++){
		cin>>arr[i]>>brr[i]>>crr[i];
	}
	pref[1]=crr[1];
	cerr<<pref[1]<<' ';
	root->upd(1,pref[1]);
	bpref[1]=brr[1];
	for (int i=2;i<=n;i++){
		pref[i]=pref[i-1]+crr[i]-(arr[i]-arr[i-1]);
		cerr<<pref[i]<<' ';
		root->upd(i,pref[i]);
		//difference between length and cover
		bpref[i]=brr[i]+bpref[i-1]; 
	}
	cerr<<endl;
	ll tot=0,ans=0; //minimally more than this
	for (int i=1;i<=n;i++){
		ll res=find(tot,i);
		ans=max(bpref[res]-bpref[i-1],ans);
		tot-=(arr[i+1]-arr[i])-crr[i];
	}
	cout<<ans;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6628 KB Output is correct
6 Correct 1 ms 6640 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 1 ms 6744 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6628 KB Output is correct
6 Correct 1 ms 6640 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 1 ms 6744 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6488 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 2 ms 6760 KB Output is correct
18 Correct 2 ms 6748 KB Output is correct
19 Correct 2 ms 6756 KB Output is correct
20 Correct 2 ms 6744 KB Output is correct
21 Correct 2 ms 6744 KB Output is correct
22 Correct 2 ms 6744 KB Output is correct
23 Correct 5 ms 7260 KB Output is correct
24 Correct 5 ms 7368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6628 KB Output is correct
6 Correct 1 ms 6640 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 1 ms 6744 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6488 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 2 ms 6760 KB Output is correct
18 Correct 2 ms 6748 KB Output is correct
19 Correct 2 ms 6756 KB Output is correct
20 Correct 2 ms 6744 KB Output is correct
21 Correct 2 ms 6744 KB Output is correct
22 Correct 2 ms 6744 KB Output is correct
23 Correct 5 ms 7260 KB Output is correct
24 Correct 5 ms 7368 KB Output is correct
25 Correct 4 ms 7260 KB Output is correct
26 Correct 7 ms 8028 KB Output is correct
27 Correct 7 ms 8088 KB Output is correct
28 Correct 37 ms 14184 KB Output is correct
29 Correct 38 ms 14684 KB Output is correct
30 Correct 85 ms 22920 KB Output is correct
31 Correct 80 ms 21752 KB Output is correct
32 Correct 80 ms 21848 KB Output is correct
33 Correct 78 ms 21448 KB Output is correct
34 Correct 138 ms 21656 KB Output is correct
35 Correct 142 ms 22364 KB Output is correct
36 Correct 136 ms 22276 KB Output is correct