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;
using ll = long long;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
#define ofk order_of_key
#define ff first
#define ss second
#define pii pair<int, int>
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n);
for (auto &i : a) {
cin >> i;
}
pii p[n];
for (int i = 0; i < n; i++)
p[i] = {a[i], i};
sort(p, p + n);
int cnt = 0;
indexed_set s;
vector<bool> vis(n);
for (int i = 0; i < n; i++) {
if (vis[p[i].ss]) continue;
cnt++;
vector<int> v;
for (int j = p[i].ss; j < n && (j == p[i].ss || a[j - 1] < a[j]) && !vis[j] && s.ofk(p[i].ff) == s.ofk(a[j]); j++) {
vis[j] = true;
v.push_back(a[j]);
if (s.find(a[j]) != s.end()) s.erase(a[j]);
}
for (auto j : v)
s.insert(j);
}
cout << cnt;
}
# | 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... |