This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
struct SEGTREE {
int n;
VI tree;
int _get(int N, int L, int R, int l, int r) {
if (R < l || L > r) return 0;
if (l <= L && R <= r) return tree[N];
int M = (L + R) / 2;
return _get(2*N+1, L, M, l, r) + _get(2*N+2, M+1, R, l, r);
}
int _upd(int N, int L, int R, int i) {
if (i < L || i > R) return tree[N];
if (L == R) return ++tree[N];
int M = (L + R) / 2;
return tree[N] = _upd(2*N+1, L, M, i) + _upd(2*N+2, M+1, R, i);
}
int get(int l, int r) {
return _get(0, 0, n-1, l, r);
}
void upd(int i) {
_upd(0, 0, n-1, i);
}
SEGTREE(int sz) {
n = 1;
while (n < sz) n *= 2;
tree = VI(2*n);
}
};
int solve(VI a) {
int n = a.size();
SEGTREE ka(1e6+1);
int ans = 1;
ka.upd(a[0]);
int s = 0;
for (int i = 1; i < n; i++) {
if (a[i] < a[i-1]) {
ans++;
for (int j = s; j < i; j++) ka.upd(a[j]);
s = i;
} else {
int l = a[s]+1;
int r = a[i]-1;
if (l <= r && ka.get(l, r)) {
/* replr(j, a[s]+1, a[i]-1) fl |= ka[j]; */
/* if (fl) { */
ans++;
for (int j = s; j < i; j++) ka.upd(a[j]);
s = i;
}
}
}
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
/* SEGTREE seg(10); */
/* VI test(10); */
/* while (true) { */
/* char ch; */
/* cin >> ch; */
/* if (ch == '?') { */
/* int l, r; */
/* cin >> l >> r; */
/* l--, r--; */
/* cout << seg.get(l, r) << endl; */
/* } else { */
/* int i; */
/* cin >> i; */
/* i--; */
/* seg.upd(i); */
/* test[i]++; */
/* } */
/* for (int x : test) cout << x << " "; cout << endl; */
/* } */
int n;
cin >> n;
VI a(n);
for (int& x : a) cin >> x;
int ans = solve(a);
cout << ans << endl;
}
# | 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... |