# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
464287 | TeaTime | Money (IZhO17_money) | C++17 | 1 ms | 204 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <unordered_map>
using namespace std;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
typedef long long ll;
typedef long double ld;
#define int ll
const ll SZ = 1e6 + 10;
ll n, m, q;
vector<ll> vec;
signed main() {
fastInp;
cin >> n;
vec.resize(n);
ll ans = 0;
for (auto& c : vec) cin >> c;
vector<ll> pos(n);
vector<ll> used(n + 1);
for (int i = 0; i < n; i++) {
pos[vec[i] - 1] = i;
}
ll pr = pos[0];
set<ll> added;
added.insert(n + 1);
used[n] = 1;
for (int i = 0; i < n; i++) {
if (used[i]) continue;
ll cur = pos[i];
ans++;
vector<ll> ltr;
ll mx = 0;
while (cur < n && !used[vec[cur] - 1]) {
if (vec[cur] < mx) break;
if ((*added.upper_bound(i)) < vec[cur]) {
break;
}
used[vec[cur] - 1] = 1;
ltr.push_back(vec[cur]);
mx = max(mx, vec[cur]);
cur++;
}
for (auto c : ltr) added.insert(c);
}
cout << ans;
return 0;
}
/*
3 4
RGWR
GRGG
RGWW
4 4
RGWR
GRRG
WGGW
WWWR
5 5
RGRGW
GRRGW
WGGWR
RWRGW
RGWGW
*/
Compilation message (stderr)
# | 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... |