Submission #533639

# Submission time Handle Problem Language Result Execution time Memory
533639 2022-03-06T18:14:12 Z CaroLinda Teams (CEOI11_tea) C++14
10 / 100
630 ms 143272 KB
#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 time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 588 KB Output is correct
2 Incorrect 3 ms 588 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 40 ms 5436 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 62 ms 6100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 385 ms 47660 KB Output is correct
2 Incorrect 300 ms 52552 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 630 ms 64984 KB Output is correct
2 Correct 487 ms 143272 KB Output is correct
3 Incorrect 423 ms 67456 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 348 ms 66548 KB Output isn't correct
2 Halted 0 ms 0 KB -