Submission #533639

#TimeUsernameProblemLanguageResultExecution timeMemory
533639CaroLindaTeams (CEOI11_tea)C++14
10 / 100
630 ms143272 KiB
#include <bits/stdc++.h> #define mk make_pair #define lp(i,a,b) for(int i = a ; i < b; i++ ) #define sz(x) (int)x.size() #define all(x) x.begin(),x.end() const int MAX = 1e6+5 ; using namespace std ; int main(){ ios_base::sync_with_stdio(false ); cin.tie(0) ; int N ; cin >> N ; vector<int> arr(N) , idx(N) ; iota(all(idx) , 0) ; vector<int> corte(N) , mx(N) , tam(N) ; for(auto &e : arr ) cin >> e ; sort(all(idx),[&](int a, int b) { return arr[a] < arr[b] ; }) ; vector<int> dp(N) ; for(int i = 0 ; i < N ; i++){ tam[i] = i+1 ; corte[i] = -1 ; if( i+1 < arr[idx[i]] ){ dp[i] = mx[i] = 0 ; if(i) mx[i] = max(mx[i] , mx[i-1]) ; } else{ dp[i] = mx[i] = max(1, mx[i-arr[idx[i]]]+1) ; if(i) mx[i] = max(mx[i] , mx[i-1]) ; } } vector<vector<int> > sweep(N+1, vector<int>()) ; for(int i = 0 ; i < N ; i++ ) sweep[dp[i]].push_back(i) ; for(int i = 1 ; i <= N ; i++ ){ sort(all(sweep[i]) , [&](int a, int b){ return a-arr[idx[a]] < b-arr[idx[b]] ; }) ; } auto getPair = [&](int x){ return make_pair( tam[x]+x , x-tam[x] ) ; } ; for(int i = 2 ; i <= N ; i++ ){ int ptr = 0 ; sort(all(sweep[i-1])) ; set<pair<int,int> > s_menor , s_maior , grupo_maior ; for(auto e : sweep[i] ) { while(ptr < sz(sweep[i-1]) && sweep[i-1][ptr] <= e-arr[idx[e]] ){ pair<int,int> p = getPair(sweep[i-1][ptr]) ; int id = sweep[i-1][ptr++] ; s_maior.insert(make_pair(p.first-p.second, id)) ; grupo_maior.insert(mk( p.first, id ) ) ; } while( !grupo_maior.empty() && grupo_maior.begin()->first < e ){ int k = grupo_maior.begin()->second ; grupo_maior.erase( grupo_maior.begin() ) ; pair<int,int> p = getPair(k) ; s_maior.erase( make_pair(p.first-p.second, k) ) ; s_menor.insert(make_pair(-p.first-p.second , k)) ; } tam[e] = N*2 ; vector<pair<int,int> > vec ; if( !s_menor.empty() ) vec.push_back(*s_menor.begin() ) ; if(!s_maior.empty()) vec.push_back(*s_maior.begin() ); sort(all(vec)) ; tam[e] = (2*e+vec[0].first)>>1 ; corte[e] = vec[0].second ; } } //lp(i,0,N) cout << dp[i] << " " << tam[i] << " " << corte[i] << endl ; vector<vector<int> > ans ; int x = N-1 ; while(x != -1){ ans.push_back(vector<int>()) ; for(int i = corte[x]+1 ; i <= x ; i++ ) ans.back().push_back(idx[i]+1) ; x = corte[x] ; } cout << sz(ans) <<"\n" ; for(auto e : ans ){ cout << sz(e) <<" " ; for(auto ee : e ) cout << ee <<" " ; cout << "\n" ; } }
#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...