답안 #355585

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
355585 2021-01-22T18:24:25 Z YJU 금 캐기 (IZhO14_divide) C++14
100 / 100
255 ms 109676 KB
#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=1e5+5;
const ll C=1e9+10;
const ld pi=acos(-1);
const ll INF=(1LL<<60);
#define SQ(i) ((ll)(i)*(i))
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(_a) (ll)_a.size()


ll n,d[N],g[N],x[N],ans,ansid;

struct node{
	ll val;
	node *lc,*rc;
}*rt=new node{INF,0,0};

ll get(node *nd){
	if(nd)return nd->val;
	return INF;
}

void ins(node *nd,ll l,ll r,ll to,ll D){
	if(l==r-1){nd->val=min(nd->val,D);return ;}
	ll mid=(l+r)>>1;
	if(to<mid){
		if(!nd->lc)nd->lc=new node{INF,0,0};
		ins(nd->lc,l,mid,to,D);
	}else{
		if(!nd->rc)nd->rc=new node{INF,0,0};
		ins(nd->rc,mid,r,to,D);
	}
	nd->val=min(get(nd->lc),get(nd->rc));
}

ll q(node *nd,ll l,ll r,ll ql,ll qr){
	if(l>=ql&&r<=qr)return nd->val;
	if(l>=qr||r<=ql)return INF;
	ll mid=(l+r)>>1;
	if(!nd->lc)nd->lc=new node{INF,0,0};
	if(!nd->rc)nd->rc=new node{INF,0,0};
	return min(q(nd->lc,l,mid,ql,qr),q(nd->rc,mid,r,ql,qr));
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n;
	REP1(i,n){
		cin>>x[i]>>g[i]>>d[i];
		g[i]+=g[i-1];d[i]+=d[i-1];
	}
	ins(rt,0,2*C,d[0]-x[1]+C,0);
	REP1(i,n){
		ansid=q(rt,0,2*C,0,d[i]-x[i]+1+C);
		if(ansid!=INF)ans=max(ans,g[i]-g[ansid]);
		ins(rt,0,2*C,d[i]-x[i+1]+C,i);
	}
	cout<<ans<<"\n";
	return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 2 ms 1260 KB Output is correct
16 Correct 3 ms 1516 KB Output is correct
17 Correct 4 ms 1900 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 4 ms 1900 KB Output is correct
20 Correct 4 ms 1900 KB Output is correct
21 Correct 3 ms 1280 KB Output is correct
22 Correct 5 ms 1772 KB Output is correct
23 Correct 14 ms 6380 KB Output is correct
24 Correct 16 ms 7276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 2 ms 1260 KB Output is correct
16 Correct 3 ms 1516 KB Output is correct
17 Correct 4 ms 1900 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 4 ms 1900 KB Output is correct
20 Correct 4 ms 1900 KB Output is correct
21 Correct 3 ms 1280 KB Output is correct
22 Correct 5 ms 1772 KB Output is correct
23 Correct 14 ms 6380 KB Output is correct
24 Correct 16 ms 7276 KB Output is correct
25 Correct 10 ms 3436 KB Output is correct
26 Correct 22 ms 7276 KB Output is correct
27 Correct 13 ms 4716 KB Output is correct
28 Correct 31 ms 5868 KB Output is correct
29 Correct 38 ms 6124 KB Output is correct
30 Correct 54 ms 5612 KB Output is correct
31 Correct 61 ms 7148 KB Output is correct
32 Correct 52 ms 7276 KB Output is correct
33 Correct 202 ms 73068 KB Output is correct
34 Correct 156 ms 43372 KB Output is correct
35 Correct 230 ms 93492 KB Output is correct
36 Correct 255 ms 109676 KB Output is correct