Submission #522962

#TimeUsernameProblemLanguageResultExecution timeMemory
522962ftkbrian휴가 (IOI14_holiday)C++14
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pll pair<ll,ll>
#define f first
#define s second
 
ll n,d;
ll A[101010];
 
vector<ll> V;
ll idx(ll v) { return lower_bound(V.begin(),V.end(),v)-V.begin()+1; }
pll ST[404040];
pll hap(pll a,pll b) { return {a.f+b.f,a.s+b.s}; }
void upd(ll id,ll s,ll e,ll t,ll v) {
	if(s > t || t > e) return;
	if(s == e) { ST[id].f += v; ST[id].s++; return; }
	ll m = s+e>>1;
	upd(id*2,s,m,t,v); upd(id*2+1,m+1,e,t,v);
	ST[id] = hap(ST[id*2],ST[id*2+1]);
}
ll query(ll id,ll s,ll e,ll lft) {
	if(s == e) {
		if(ST[id].s == 0) return 0;
		return ST[id].f/ST[id].s*min(ST[id].s,lft);
	}
	ll m = s+e>>1;
	if(ST[id*2+1].s < lft) return ST[id*2+1].f+query(id*2,s,m,lft-ST[id*2+1].s);
	return query(id*2+1,m+1,e,lft);
}
 
ll st;///시작점
ll ans;
 
ll dist(ll a,ll b,ll c) { return c-a+max(0ll,min(c-b,b-a)); }
 
void DnC(ll s,ll e,ll qs,ll qe) {
	if(s > e) return;
	ll m = s+e>>1; V.clear();
	ll opt = qs,val = -1;
	for(int i = m ; i <= qe ; i++) {
		if(dist(m,st,i) > d) break;
		V.push_back(A[i]);
	}
	sort(V.begin(),V.end());
	V.erase(unique(V.begin(),V.end()),V.end());
	ll sz = V.size();
	for(int i = 1 ; i <= 4*sz ; i++) ST[i] = {0,0};
	for(int i = m ; i < qs ; i++) upd(1,1,sz,idx(A[i]),A[i]);
	for(int i = qs ; i <= qe ; i++) {
		ll v = d-dist(m,st,i);
		if(v <= 0) break;
		upd(1,1,sz,idx(A[i]),A[i]);
		ll vl = query(1,1,sz,v);
		if(val < vl) opt = i,val = vl;
	}
	ans = max(ans,val);
	DnC(s,m-1,qs,opt);
	DnC(m+1,e,opt,qe);
}
main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>n>>st>>d; st++;
	for(int i = 1 ; i <= n ; i++) cin>>A[i];
	DnC(1,st,st,n);
	cout<<ans<<"\n";
}

Compilation message (stderr)

holiday.cpp: In function 'void upd(ll, ll, ll, ll, ll)':
holiday.cpp:18:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   18 |  ll m = s+e>>1;
      |          ^
holiday.cpp: In function 'll query(ll, ll, ll, ll)':
holiday.cpp:27:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   27 |  ll m = s+e>>1;
      |          ^
holiday.cpp: In function 'void DnC(ll, ll, ll, ll)':
holiday.cpp:39:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   39 |  ll m = s+e>>1; V.clear();
      |          ^
holiday.cpp: At global scope:
holiday.cpp:61:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   61 | main() {
      | ^~~~
/usr/bin/ld: /tmp/cckRcHkG.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc8GGUDI.o:holiday.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/cckRcHkG.o: in function `main':
grader.cpp:(.text.startup+0xaf): undefined reference to `findMaxAttraction(int, int, int, int*)'
collect2: error: ld returned 1 exit status