Submission #658240

#TimeUsernameProblemLanguageResultExecution timeMemory
658240AntekbTeams (CEOI11_tea)C++14
0 / 100
340 ms109704 KiB
#include<bits/stdc++.h> //#pragma GCC optimize("Ofast") //#pragma GCC optimize("trapv") #define st first #define nd second #define pb push_back #define pp pop_back #define eb emplace_back #define mp(a, b) make_pair(a, b) #define all(x) (x).begin(), (x).end() #define rev(x) reverse(all(x)) #define sor(x) sort(all(x)) #define sz(x) (int)(x).size() #define rsz(x) resize(x) using namespace std; ///~~~~~~~~~~~~~~~~~~~~~~~~~~ template <typename H, typename T> ostream& operator<<(ostream& os, pair<H, T> m){ return os <<"("<< m.st<<", "<<m.nd<<")"; } template <typename H> ostream& operator<<(ostream& os, vector<H> V){ os<<"{"; for(int i=0; i<V.size(); i++){ if(i)os<<" "; os<<V[i]; } os<<"}"; return os; } void debug(){cerr<<"\n";} template <typename H, typename... T> void debug(H h, T... t) {cerr<<h; if (sizeof...(t)) cerr << ", "; debug(t...);} #define deb(x...) cerr<<#x<<" = ";debug(x); ///~~~~~~~~~~~~~~~~~~~~~~~~~ typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<pii > vii; typedef vector<ll> vl; typedef vector<pll> vll; typedef string str; #define BOOST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); const int N=1e6+5, INF=1e9+5, mod=1e9+7; vi id[N], id2[N], mini[N];//id-kto ma dp o takiej wartosci, mini-najmniejsza najwieksza druzyna int dp[N], gdzie[N], par[N], opt[N], mi[N];//dp-ile druz, gdzie-numer w wektorze, par-rodzic, opt-maxi na przedziale int main(){ BOOST; int n; cin>>n; vii V(n+1); for(int i=1; i<=n; i++){ cin>>V[i].st; V[i].nd=i; } sor(V); id[0].pb(0); for(int i=1; i<=n; i++){ //deb(i); int j=i-V[i].st; if(j<0){ opt[i]=opt[i-1]; } else{ //deb(i); int k=opt[j]; dp[i]=k+1; opt[i]=max(opt[i-1], k+1); id[k+1].pb(i); } //deb(dp[i]); } for(int k=0; k<dp[n]; k++){ vii spec; for(int j:id[k+1])spec.eb(j-V[j].st, j); sor(spec); rev(spec); id[k].pb(n+1); for(int j:id[k]){ while(spec.size() && spec.back().st<j){ int i=spec.back().nd; int l=0, r=id2[k].size(); while(l<r){ int m=(l+r)>>1; if(i-m>=mini[k][m])l=m+1; else r=m; } //deb(i); int m; if(l==id2[k].size() || id2[k][l]>j || (l!=0 && i-l+1>mini[k][l])){ par[i]=id2[k][l-1]; m=i-l+1; } else{ par[i]=id2[k][l]; m=mini[k][l]; } mi[i]=m; spec.pp(); } if(j==n+1)break; while(id2[k].size() && mi[j]<=mini[k].back()){ id2[k].pp(); mini[k].pp(); } id2[k].pb(j); mini[k].pb(mi[j]); } } for(int i=1; i<=n; i++){ //deb(i, dp[i], par[i], mi[i]); } cout<<dp[n]<<"\n"; int v=n; while(v!=0){ int v2=par[v]; cout<<v-v2<<" "; for(int i=v; i>v2; i--){ cout<<V[i].nd<<" "; } cout<<"\n"; v=v2; } }

Compilation message (stderr)

tea.cpp: In function 'int main()':
tea.cpp:104:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |     if(l==id2[k].size() || id2[k][l]>j || (l!=0 && i-l+1>mini[k][l])){
      |        ~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...