#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];
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<int,int> aa,pair<int,int> bb){
return aa.b<bb.b;
}
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<int,int>> tt;
set<int> kk;
build(0,0,n-1);
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});
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});
}
}
kk.insert(it[i]);
ss.pb({it[i],i});
}
if(std::chrono::system_clock::now().time_since_epoch().count()>1e9){
//cout<<std::chrono::system_clock::now().time_since_epoch().count()<<endl;
return 0;
}
set<pair<int,int>> mm;
for(auto j:tt){
mm.insert(j);
}
sort(tt.begin(),tt.end(),cmp);
int ans=1;
for(auto j:tt){
if(mm.find(j)!=mm.end()){
ans+=1;
while(mm.size()){
if((*mm.begin()).a<=j.b){
mm.erase(mm.begin());
}
else{
break;
}
}
}
}
//cout<<ans<<endl;
//cout<<1.0 * clock()<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |