# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
522961 | ftkbrian | Holiday (IOI14_holiday) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pll pair<ll,ll>
#define f first
#define s second
bool offline;
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);