This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define bug cout << "bug" << endl
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define pll pair <ll, ll>
#define pii pair <int, int>
#define triple pair <pair <ll, ll> , ll>
#define ull unsigned long long
#define ld long double
#define pinode pair <node*, node*>
const ll INF = 9e18 + 5;
const ll inf = 1e9 + 5;
const ll N = 1e6 + 5;
const ll shift = 2e6;
const ll mod = 1e9 + 7;
const ll M = 255000 + 5;
const ll LOG = 21;
const ll sp = 263;
const ll block = 500;
const double eps = 1e-10;
int n, a[N], t[N];
void upd(int pos, int val){
while(pos <= N - 5){
t[pos] += val;
pos = (pos | (pos + 1));
}
}
int get(int pos){
int res = 0;
while(pos >= 0){
res += t[pos];
pos = (pos & (pos + 1)) - 1;
}
return res;
}
int sum(int l, int r){
if(l > r)
return 0;
return get(r) - get(l - 1);
}
int main(){
speed;
cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i];
int st = 1, ans = 0;
while(st <= n){
int nw = st + 1;
ans++;
for(int i = st + 1; i <= n; i++){
if(a[i] >= a[i - 1] && sum(a[st] + 1, a[i] - 1) == 0){
nw = i + 1;
continue;
}
break;
}
for(int i = st; i <= nw - 1; i++)
upd(a[i], 1);
st = nw;
}
cout << ans << endl;
}
/*
%I64d
6
3 5 1 2 4 6
%I64d
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |