Submission #249604

#TimeUsernameProblemLanguageResultExecution timeMemory
249604ryanseeTeams (IOI15_teams)C++14
77 / 100
1224 ms524292 KiB
#include "teams.h" #include "bits/stdc++.h" using namespace std; #define FAST ios_base::sync_with_stdio(false); cin.tie(0); #define pb push_back #define eb emplace_back #define ins insert #define f first #define s second #define cbr cerr<<"hi\n" #define mmst(x, v) memset((x), v, sizeof ((x))) #define siz(x) ll(x.size()) #define all(x) (x).begin(), (x).end() #define lbd(x,y) (lower_bound(all(x),y)-x.begin()) #define ubd(x,y) (upper_bound(all(x),y)-x.begin()) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //can be used by calling rng() or shuffle(A, A+n, rng) inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); } using ll=int; using ld=long double; #define FOR(i,s,e) for(ll i=s;i<=ll(e);++i) #define DEC(i,s,e) for(ll i=s;i>=ll(e);--i) using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>; #define LLINF ((long long)1e18) #define INF int(1e9+1e6) #define MAXN (500006) const ll sq = 720; ll n, A[MAXN], B[MAXN]; struct node { int s,e,m; ll v; node *l,*r; node(int S,int E,bool prog){ s=S,e=E,m=(s+e)>>1; v=0; if(s!=e&&prog){ l=new node(s,m,1),r=new node(m+1,e,1); }else l=r=0; } node* update(int x,ll nval){ node* tmp=new node(s,e,0); if(s==e){ tmp->v=v+nval; return tmp; } if(x>m){ tmp->l=l; tmp->r=r->update(x,nval); }else{ tmp->l=l->update(x,nval); tmp->r=r; } tmp->v=tmp->l->v+tmp->r->v; return tmp; } ll rmq(int x,int y){ if(s==x&&e==y)return v; if(x>m)return r->rmq(x,y); else if(y<=m)return l->rmq(x,y); else return l->rmq(x,m)+r->rmq(m+1,y); } } *seg[MAXN]; void init(int N, int _A[], int _B[]) { n=N; FOR(i,0,n-1)A[i]=_A[i],B[i]=_B[i]; vector<pi> v; FOR(i,0,n-1)v.eb(A[i],B[i]); sort(all(v),greater<>()); seg[0]=new node(0,n+1,1); FOR(i,1,n){ seg[i]=seg[i-1]; while(v.size()&&v.back().f==i){ seg[i]=seg[i]->update(v.back().s,1); v.pop_back(); } } } int can(int M, int K[]) { if(accumulate(K,K+M,0ll)>n) return 0; sort(K,K+M); vector<pi> v; FOR(i,0,M-1){ if(v.empty()||v.back().f!=K[i])v.eb(K[i],1); else ++v.back().s; } // assert(v.size() <= 2 * sq + 3); vector<vector<ll>> bet(siz(v), vector<ll>(siz(v)+1, 0)); if(M>=250){ /*FOR(i,0,n-1){ ll f=lbd(v,pi(A[i],0)); if(f==v.size())continue; ll s=lbd(v,pi(B[i],LLINF)); ++ bet[f][s]; }*/ vector<int>start(n+2,siz(v)),endd(n+2,siz(v)); FOR(i,0,siz(v)-1){ FOR(j,i==0?0:v[i-1].f+1,v[i].f)start[j]=i; FOR(j,i==0?0:v[i-1].f,v[i].f-1)endd[j]=i; } FOR(i,0,n-1){ if(start[A[i]]==siz(v))continue; ++bet[start[A[i]]][endd[B[i]]]; } }else{ FOR(i,0,siz(v)-1)FOR(j,i+1,siz(v)){ bet[i][j]=seg[v[i].f]->rmq(v[j-1].f,j == siz(v) ? n+1 : (v[j].f-1)); if(i) bet[i][j]-=seg[v[i-1].f]->rmq(v[j-1].f,j == siz(v) ? n+1 : (v[j].f-1)); } } vector<ll> cnt(siz(v)+1,0); FOR(i,0,siz(v)-1){ FOR(j,i+1,siz(v))cnt[j]+=bet[i][j]; ll need=v[i].f*v[i].s,sum=0; FOR(j,i+1,siz(v)){ if(cnt[j]+sum>=need){ cnt[j]-=need-sum, sum=need; break; }else{ sum+=cnt[j],cnt[j]=0; } } if(sum^need) return 0; } return 1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...