This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/// wa
#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:36777216")
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define sz(x) (int) x.size()
#define all(z) (z).begin(), (z).end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 1e2;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void fin() {
#ifdef AM
freopen(".in", "r", stdin);
#endif
}
const bool flag = 0;
const int N = 1e5+10;
void ma1n() {
int n;
cin >> n;
vector<int> a(n);
for (int& x : a) {
cin >> x;
}
int cnt = 0;
set<int> s;
vector<int> cur;
a.pb(-INF), n++;
for (int i = 0; i < n; ++i) {
if (i && a[i] >= a[i-1]) {
cur.pb(a[i]);
} else {
/*cerr << "set: ";
for (auto it : s) cerr << it << " ";
cerr << "\n";
cerr << "cur: ";
for (int x : cur) cerr << x << " ";
cerr << "\n"; */
for (int j = 0; j < sz(cur);) {
auto it = s.upper_bound(cur[j]);
cnt++;
if (it == s.end()) {
for (int k = j; k < sz(cur); ++k) {
s.insert(cur[k]);
}
break;
}
int x = *it;
while (j < sz(cur) && cur[j] <= x) {
s.insert(cur[j]), j++;
}
}
cur = {a[i]};
}
}
cout << cnt;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(nullptr), fin();
int ts = 1;
if (flag) {
cin >> ts;
}
while (ts--) {
ma1n();
}
return 0;
}
# | 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... |