Submission #799576

#TimeUsernameProblemLanguageResultExecution timeMemory
799576I_Love_EliskaM_Teams (IOI15_teams)C++14
100 / 100
1010 ms385976 KiB
#include "teams.h" #include <bits/stdc++.h> using namespace std; #define forn(i,n) for(int i=0;i<n;++i) #define pb push_back #define all(x) x.begin(),x.end() using ll = long long; #define pi pair<int,int> #define f first #define s second const int sz=1<<20; struct sgt { sgt *L, *R; int s; sgt() { L=R=NULL; s=0; } sgt* add(int l, int r, int i, int x) { if (r-l==1) { sgt* nw = new sgt(); nw->s = s+x; return nw; } int m=(l+r)>>1; if (i<m) { if (!L) L=new sgt(); sgt* newleft = L->add(l,m,i,x); sgt* nw = new sgt(); nw->L = newleft; nw->R = R; nw->s = s+x; return nw; } else { if (!R) R=new sgt(); sgt* newright = R->add(m,r,i,x); sgt* nw = new sgt(); nw->L = L; nw->R = newright; nw->s = s+x; return nw; } } sgt* add(int i, int x) { return add(0,sz,i,x); } int sum(int l, int r, int lx, int rx) { if (rx<=l || r<=lx) return 0; if (lx<=l && r<=rx) return s; int m=(l+r)>>1; int lq = L?L->sum(l,m,lx,rx):0; int rq = R?R->sum(m,r,lx,rx):0; return lq+rq; } int sum(int l, int r) { if (l>=r) return 0; return sum(0,sz,l,r); } int get(int i) { return sum(0,sz,0,i+1); } }; sgt* st[(int)5e5+55]; pi a[(int)5e5]; int n; void init(int _n, int f[], int s[]) { n=_n; forn(i,n) a[i]={f[i],s[i]}; vector<vector<int>> v(n+1); forn(i,n) v[a[i].s].pb(i); st[n+1]=new sgt(); for(int i=n;i>0;--i) { st[i]=st[i+1]; for(auto&x:v[i]) { auto t=st[i]->add(a[x].f,1); st[i]=t; } } } int can(int m, int k[]) { vector<int> v(m); forn(i,m) v[i]=k[i]; sort(all(v)); int s=0; forn(i,m) s+=k[i]; if (s>n) return 0; vector<pi> z; forn(i,m) { if (!z.size()) { z.pb({v[i],1}); continue; } if (v[i]==z.back().f) z.back().s++; else z.pb({v[i],1}); } int t=z.size(); vector<int> dp(t+1,-1e9); dp[0]=0; forn(i,t) { int mx=i; for(int j=i-1; j>=0; --j) { if (dp[j]<=dp[mx]) continue; int cnt; if (mx==0) { cnt=st[z[i].f]->sum(0,z[i].f+1); } else { cnt=st[z[i].f]->sum(z[mx-1].f+1,z[i].f+1); } dp[i+1]=max(dp[i+1],dp[mx]-cnt); mx=j; } int cnt; if (mx==0) { cnt=st[z[i].f]->sum(0,z[i].f+1); } else { cnt=st[z[i].f]->sum(z[mx-1].f+1,z[i].f+1); } dp[i+1]=max(dp[i+1],dp[mx]-cnt); dp[i+1]+=z[i].f*z[i].s; if (dp[i+1]>0) return 0; } return 1; }

Compilation message (stderr)

teams.cpp: In function 'int can(int, int*)':
teams.cpp:99:15: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   99 |   int t=z.size();
      |         ~~~~~~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...