#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pi pair <int, int>
#define pii pair <pi, int>
#define rep(i,n) for(ll i = 1; i <= n; i++)
#define fi first
#define se second
using namespace std;
int n, a[1000010],mx,mi;
bool vis[1000010];
#define debug(x) cout<<#x<<' '<<x<<endl;
int fw[1000010];
void update(int x, int v) {
for (; x<n+1; x+=x&(-x)) fw[x] += v;
}
int sum(int x) {
int res = 0;
for(; x; x-=x&(-x)) res += fw[x];
return res;
}
int range_sum(int x, int y) { //inclusive
return sum(y)-sum(x-1);
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin>>n;
rep(i,n)cin>>a[i];
int ans=1;
vector<int> v;
for(int i=n; i>1; i--){
//debug(i);
v.pb(a[i]);
if(a[i-1]>a[i]){
for(auto it: v){
update(it,1);
//cout<<it<<endl;
}
v.clear();
mx=a[i-1];
ans++;
//cout<<"this\n";
}else{
mi=a[i-1];
if(range_sum(a[i-1],a[i])!=a[i]-a[i-1]-1){
ans++;
for(auto it: v){
update(it,1);
//cout<<it<<endl;
}
v.clear();
//cout<<"other\n";
}
}
//rep(i,n)cout<<range_sum(i,i);cout<<endl;
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |