# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
533651 |
2022-03-06T19:35:30 Z |
CaroLinda |
Teams (CEOI11_tea) |
C++14 |
|
410 ms |
142044 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*4] , _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 ), seg[1].qry(1,1,2*N , e , 2*N) } ;
sort(p, p+2) ;
tam[e] = (e-p[0])>>1 ;
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 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
880 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
844 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
46 ms |
17628 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
39 ms |
18416 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
205 ms |
113380 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
315 ms |
142044 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
410 ms |
86460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |