#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] = (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" ;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
588 KB |
Output is correct |
2 |
Incorrect |
2 ms |
588 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
34 ms |
5776 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
40 ms |
6120 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
400 ms |
47712 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
498 ms |
64708 KB |
Output is correct |
2 |
Correct |
504 ms |
145296 KB |
Output is correct |
3 |
Correct |
418 ms |
70400 KB |
Output is correct |
4 |
Incorrect |
546 ms |
60976 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
347 ms |
66440 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |