# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
533655 |
2022-03-06T19:52:03 Z |
CaroLinda |
Teams (CEOI11_tea) |
C++14 |
|
934 ms |
176088 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 ;
struct Seg{
int tree[MAX*8] , _default =MAX*10 ;
int m(int l, int r ) { return (l+r)>>1 ; }
void build(int pos, int l, int r){
tree[pos] = _default ;
if(l == r ) return ;
build(pos<<1 , l , m(l,r)) ;
build(pos<<1|1 , m(l,r)+1 , r ) ;
}
int qry(int pos, int l, int r, int beg, int en){
if(l > en || r < beg ) return _default ;
if(l >= beg && r <= en ) return tree[pos] ;
int al = qry(pos<<1 , l , m(l,r ) , beg, en ) ;
int ar = qry(pos<<1|1 , m(l,r)+1, r, beg, en ) ;
return min(al, ar) ;
}
void upd(int pos, int l, int r, int id, int p){
tree[pos] = min(tree[pos] , p ) ;
if(l == r) return ;
if(id <= m(l,r)) upd(pos<<1 , l , m(l,r) , id,p) ;
else upd(pos<<1|1 , m(l,r)+1, r, id, p ) ;
}
void clean(int pos, int l, int r){
if( tree[pos] == _default ) return ;
tree[pos] = _default ;
if(l == r ) return ;
clean(pos<<1 , l , m(l,r)) ;
clean(pos<<1|1 , m(l,r)+1, r ) ;
}
} seg[2] ;
int s[MAX] ;
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])) ;
seg[0].clean(1,1,2*N) ;
seg[1].clean(1,1,2*N ) ;
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[ tam[id] ] = id ;
seg[0].upd(1,1,2*N , p.first, -p.first-p.second ) ;
seg[1].upd(1,1,2*N , p.first, p.first-p.second ) ;
}
tam[e] = N*2 ;
int p[2] = { seg[0].qry( 1 , 1, 2*N , 1 , e )+2*e, seg[1].qry(1,1,2*N , e , 2*N) } ;
sort(p, p+2) ;
tam[e] = (p[0])>>1 ;
corte[e] = e-tam[e] ;
if(dp[corte[e]] != i-1 || tam[corte[e]] > tam[e] ){
corte[e] = s[tam[e]-1] ;
}
}
}
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 |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
844 KB |
Output is correct |
2 |
Correct |
3 ms |
844 KB |
Output is correct |
3 |
Correct |
3 ms |
844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
844 KB |
Output is correct |
2 |
Correct |
3 ms |
844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
9612 KB |
Output is correct |
2 |
Correct |
48 ms |
9680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
10048 KB |
Output is correct |
2 |
Correct |
45 ms |
9484 KB |
Output is correct |
3 |
Correct |
49 ms |
10052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
480 ms |
80436 KB |
Output is correct |
2 |
Correct |
451 ms |
83288 KB |
Output is correct |
3 |
Correct |
463 ms |
84724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
598 ms |
95768 KB |
Output is correct |
2 |
Correct |
934 ms |
176088 KB |
Output is correct |
3 |
Correct |
614 ms |
100352 KB |
Output is correct |
4 |
Correct |
616 ms |
88248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
387 ms |
97684 KB |
Output is correct |
2 |
Correct |
260 ms |
106672 KB |
Output is correct |
3 |
Correct |
623 ms |
100392 KB |
Output is correct |
4 |
Correct |
714 ms |
101520 KB |
Output is correct |