#include <bits/stdc++.h>
using namespace std;
struct SEGT{//range max , point update
vector < int > tree;
int sz;
SEGT(int x){
x++;
sz = x;
tree.assign(4*x,0);
}
void _update(int ind , int l , int r , int qp , int qv){
if(l == r){
tree[ind] = qv;
return;
}
int mid = (l+r)/2;
if(mid >= qp){
_update(ind*2,l,mid,qp,qv);
}
else {
_update(ind*2+1,mid+1,r,qp,qv);
}
tree[ind] = max(tree[ind*2] , tree[ind*2+1]);
}
void update(int p , int v){
_update(1,1,sz,p,v);
}
int _query(int ind , int l , int r , int ql , int qr){
if(l >= ql and r <= qr){
return tree[ind];
}
else if(l > qr or r < ql){
return 0;
}
else{
int mid = (l+r)/2;
return max(_query(ind*2,l,mid,ql,qr) , _query(ind*2+1,mid+1,r,ql,qr));
}
}
int query(int l , int r){
return _query(1,1,sz,l,r);
}
};
void solve(){
int n;
cin >> n;
SEGT segt(n+1);
int p[n],lis[n],mx = 1;
for(int i = 0;i<n;i++){
cin >> p[i];
lis[i] = 1 + segt.query(1,p[i]);
segt.update(p[i] , lis[i]);
mx = max(mx , lis[i]);
}
set < pair < int , int > > v[mx+2];
vector < int > starting_points;
int go[n];
memset(go , -1 , sizeof(go));
for(int i = n-1;i>=0;i--){
if(v[lis[i]+1].size()){
go[i] = (*v[lis[i]+1].begin()).second;
v[lis[i+1]].erase(v[lis[i+1]].begin());
v[lis[i]].insert({p[i],i});
if(lis[i] == 1){
starting_points.push_back(i);
}
}
else if(lis[i] == mx){
v[lis[i]].insert({p[i],i});
if(lis[i] == 1){
starting_points.push_back(i);
}
}
}
cout << starting_points.size() << " " << mx << endl;
for(auto itr : starting_points){
int cur = itr;
do{
cout << cur+1 << " ";
cur = go[cur];
}while(cur != -1);
cout << '\n';
}
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int testcase = 1;//cin >> testcase;
while(testcase--)solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1034 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1034 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1034 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |