#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
//#define endl '\n'
int n;
int it[1000001];
int tree[1000001*4];
int vis[1000001*2];
void build(int no,int l,int r){
if(l==r){
tree[no]=it[l];
}
else{
int mid=(l+r)/2;
build(no*2+1,l,mid);
build(no*2+2,mid+1,r);
tree[no]=max(tree[no*2+1],tree[no*2+2]);
}
}
int query(int no,int l,int r,int aa,int bb){
if(r<aa){
return -1;
}
if(aa<=l){
if(tree[no]<=bb){
return -1;
}
if(l==r){
return l;
}
}
int mid=(l+r)/2;
int x=query(no*2+1,l,mid,aa,bb);
if(x==-1){
return query(no*2+2,mid+1,r,aa,bb);
}
else{
return x;
}
}
bool cmp(pair<pair<int,int>,int> aa,pair<pair<int,int>,int> bb){
return aa.a.b<bb.a.b;
}
vector<pair<int,int>> pre[1000001];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n;
for(int i=0;i<n;i++){
cin>>it[i];
}
vector<pair<int,int>> ss;
vector<pair<pair<int,int>,int>> tt;
set<int> kk;
build(0,0,n-1);
int cur=0;
for(int i=0;i<n;i++){
while(ss.size()){
if(ss.back().a<=it[i]){
ss.pop_back();
}
else{
break;
}
}
if(ss.size()){
int ne=ss.back().b;
tt.pb({{ne,i-1},cur});
cur++;
int jj=*kk.upper_bound(it[i]);
/*int low=i;
for(int j=19;j>=0;j--){
if(low+(1<<j)<n){
if(query(0,0,n-1,i,low+(1<<j))<=jj){
low+=(1<<j);
}
}
}*/
int low=query(0,0,n-1,i,jj);
if(low!=-1){
tt.pb({{i,low-1},cur});
cur++;
}
}
kk.insert(it[i]);
ss.pb({it[i],i});
}
vector<pair<pair<int,int>,int>> mm;
/*for(auto j:tt){
mm.pb(j);
}
sort(mm.begin(),mm.end());*/
for(auto j:tt){
pre[j.a.b].pb({j.a.a,j.b});
}
//sort(tt.begin(),tt.end(),cmp);
int ans=1;
int ma=-1;
for(int i=0;i<n-1;i++){
//if(vis[j.b]==0){
for(auto j:pre[i]){
if(j.a<=ma){
continue;
}
ans+=1;
ma=i;
/*while(ind<mm.size()){
if(mm[ind].a.a<=j.a.b){
vis[mm[ind].b]=1;
ind++;
}
else{
break;
}
}*/
}
//}
}
cout<<ans<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
Output is correct |
2 |
Correct |
17 ms |
23788 KB |
Output is correct |
3 |
Correct |
16 ms |
23788 KB |
Output is correct |
4 |
Correct |
17 ms |
23788 KB |
Output is correct |
5 |
Correct |
17 ms |
23788 KB |
Output is correct |
6 |
Correct |
17 ms |
23788 KB |
Output is correct |
7 |
Correct |
16 ms |
23912 KB |
Output is correct |
8 |
Correct |
17 ms |
23788 KB |
Output is correct |
9 |
Correct |
16 ms |
23788 KB |
Output is correct |
10 |
Correct |
16 ms |
23788 KB |
Output is correct |
11 |
Correct |
16 ms |
23788 KB |
Output is correct |
12 |
Correct |
16 ms |
23788 KB |
Output is correct |
13 |
Correct |
17 ms |
23788 KB |
Output is correct |
14 |
Correct |
17 ms |
23788 KB |
Output is correct |
15 |
Correct |
17 ms |
23788 KB |
Output is correct |
16 |
Correct |
17 ms |
23788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
Output is correct |
2 |
Correct |
17 ms |
23788 KB |
Output is correct |
3 |
Correct |
16 ms |
23788 KB |
Output is correct |
4 |
Correct |
17 ms |
23788 KB |
Output is correct |
5 |
Correct |
17 ms |
23788 KB |
Output is correct |
6 |
Correct |
17 ms |
23788 KB |
Output is correct |
7 |
Correct |
16 ms |
23912 KB |
Output is correct |
8 |
Correct |
17 ms |
23788 KB |
Output is correct |
9 |
Correct |
16 ms |
23788 KB |
Output is correct |
10 |
Correct |
16 ms |
23788 KB |
Output is correct |
11 |
Correct |
16 ms |
23788 KB |
Output is correct |
12 |
Correct |
16 ms |
23788 KB |
Output is correct |
13 |
Correct |
17 ms |
23788 KB |
Output is correct |
14 |
Correct |
17 ms |
23788 KB |
Output is correct |
15 |
Correct |
17 ms |
23788 KB |
Output is correct |
16 |
Correct |
17 ms |
23788 KB |
Output is correct |
17 |
Correct |
17 ms |
23892 KB |
Output is correct |
18 |
Correct |
18 ms |
23788 KB |
Output is correct |
19 |
Correct |
17 ms |
23788 KB |
Output is correct |
20 |
Correct |
17 ms |
23788 KB |
Output is correct |
21 |
Correct |
16 ms |
23788 KB |
Output is correct |
22 |
Correct |
17 ms |
23788 KB |
Output is correct |
23 |
Correct |
16 ms |
23788 KB |
Output is correct |
24 |
Correct |
17 ms |
23820 KB |
Output is correct |
25 |
Correct |
18 ms |
23916 KB |
Output is correct |
26 |
Correct |
16 ms |
23788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
Output is correct |
2 |
Correct |
17 ms |
23788 KB |
Output is correct |
3 |
Correct |
16 ms |
23788 KB |
Output is correct |
4 |
Correct |
17 ms |
23788 KB |
Output is correct |
5 |
Correct |
17 ms |
23788 KB |
Output is correct |
6 |
Correct |
17 ms |
23788 KB |
Output is correct |
7 |
Correct |
16 ms |
23912 KB |
Output is correct |
8 |
Correct |
17 ms |
23788 KB |
Output is correct |
9 |
Correct |
16 ms |
23788 KB |
Output is correct |
10 |
Correct |
16 ms |
23788 KB |
Output is correct |
11 |
Correct |
16 ms |
23788 KB |
Output is correct |
12 |
Correct |
16 ms |
23788 KB |
Output is correct |
13 |
Correct |
17 ms |
23788 KB |
Output is correct |
14 |
Correct |
17 ms |
23788 KB |
Output is correct |
15 |
Correct |
17 ms |
23788 KB |
Output is correct |
16 |
Correct |
17 ms |
23788 KB |
Output is correct |
17 |
Correct |
17 ms |
23892 KB |
Output is correct |
18 |
Correct |
18 ms |
23788 KB |
Output is correct |
19 |
Correct |
17 ms |
23788 KB |
Output is correct |
20 |
Correct |
17 ms |
23788 KB |
Output is correct |
21 |
Correct |
16 ms |
23788 KB |
Output is correct |
22 |
Correct |
17 ms |
23788 KB |
Output is correct |
23 |
Correct |
16 ms |
23788 KB |
Output is correct |
24 |
Correct |
17 ms |
23820 KB |
Output is correct |
25 |
Correct |
18 ms |
23916 KB |
Output is correct |
26 |
Correct |
16 ms |
23788 KB |
Output is correct |
27 |
Correct |
17 ms |
23916 KB |
Output is correct |
28 |
Correct |
17 ms |
23916 KB |
Output is correct |
29 |
Correct |
17 ms |
23916 KB |
Output is correct |
30 |
Correct |
19 ms |
23916 KB |
Output is correct |
31 |
Correct |
17 ms |
23916 KB |
Output is correct |
32 |
Correct |
17 ms |
23916 KB |
Output is correct |
33 |
Correct |
17 ms |
23936 KB |
Output is correct |
34 |
Correct |
17 ms |
24044 KB |
Output is correct |
35 |
Correct |
17 ms |
23916 KB |
Output is correct |
36 |
Correct |
16 ms |
23916 KB |
Output is correct |
37 |
Correct |
17 ms |
23916 KB |
Output is correct |
38 |
Correct |
17 ms |
23916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
Output is correct |
2 |
Correct |
17 ms |
23788 KB |
Output is correct |
3 |
Correct |
16 ms |
23788 KB |
Output is correct |
4 |
Correct |
17 ms |
23788 KB |
Output is correct |
5 |
Correct |
17 ms |
23788 KB |
Output is correct |
6 |
Correct |
17 ms |
23788 KB |
Output is correct |
7 |
Correct |
16 ms |
23912 KB |
Output is correct |
8 |
Correct |
17 ms |
23788 KB |
Output is correct |
9 |
Correct |
16 ms |
23788 KB |
Output is correct |
10 |
Correct |
16 ms |
23788 KB |
Output is correct |
11 |
Correct |
16 ms |
23788 KB |
Output is correct |
12 |
Correct |
16 ms |
23788 KB |
Output is correct |
13 |
Correct |
17 ms |
23788 KB |
Output is correct |
14 |
Correct |
17 ms |
23788 KB |
Output is correct |
15 |
Correct |
17 ms |
23788 KB |
Output is correct |
16 |
Correct |
17 ms |
23788 KB |
Output is correct |
17 |
Correct |
17 ms |
23892 KB |
Output is correct |
18 |
Correct |
18 ms |
23788 KB |
Output is correct |
19 |
Correct |
17 ms |
23788 KB |
Output is correct |
20 |
Correct |
17 ms |
23788 KB |
Output is correct |
21 |
Correct |
16 ms |
23788 KB |
Output is correct |
22 |
Correct |
17 ms |
23788 KB |
Output is correct |
23 |
Correct |
16 ms |
23788 KB |
Output is correct |
24 |
Correct |
17 ms |
23820 KB |
Output is correct |
25 |
Correct |
18 ms |
23916 KB |
Output is correct |
26 |
Correct |
16 ms |
23788 KB |
Output is correct |
27 |
Correct |
17 ms |
23916 KB |
Output is correct |
28 |
Correct |
17 ms |
23916 KB |
Output is correct |
29 |
Correct |
17 ms |
23916 KB |
Output is correct |
30 |
Correct |
19 ms |
23916 KB |
Output is correct |
31 |
Correct |
17 ms |
23916 KB |
Output is correct |
32 |
Correct |
17 ms |
23916 KB |
Output is correct |
33 |
Correct |
17 ms |
23936 KB |
Output is correct |
34 |
Correct |
17 ms |
24044 KB |
Output is correct |
35 |
Correct |
17 ms |
23916 KB |
Output is correct |
36 |
Correct |
16 ms |
23916 KB |
Output is correct |
37 |
Correct |
17 ms |
23916 KB |
Output is correct |
38 |
Correct |
17 ms |
23916 KB |
Output is correct |
39 |
Correct |
196 ms |
54984 KB |
Output is correct |
40 |
Correct |
359 ms |
81440 KB |
Output is correct |
41 |
Correct |
149 ms |
47944 KB |
Output is correct |
42 |
Correct |
180 ms |
49592 KB |
Output is correct |
43 |
Correct |
124 ms |
41524 KB |
Output is correct |
44 |
Correct |
435 ms |
92532 KB |
Output is correct |
45 |
Correct |
407 ms |
89624 KB |
Output is correct |
46 |
Correct |
436 ms |
92568 KB |
Output is correct |
47 |
Correct |
250 ms |
60488 KB |
Output is correct |
48 |
Correct |
317 ms |
77876 KB |
Output is correct |
49 |
Correct |
990 ms |
114160 KB |
Output is correct |
50 |
Correct |
939 ms |
109080 KB |
Output is correct |
51 |
Correct |
998 ms |
114136 KB |
Output is correct |
52 |
Correct |
980 ms |
109216 KB |
Output is correct |
53 |
Correct |
1002 ms |
111532 KB |
Output is correct |
54 |
Correct |
967 ms |
109336 KB |
Output is correct |
55 |
Execution timed out |
1568 ms |
145740 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |