Submission #464984

# Submission time Handle Problem Language Result Execution time Memory
464984 2021-08-14T19:56:15 Z TeaTime Money (IZhO17_money) C++17
0 / 100
1 ms 332 KB
//#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;
        vec[i]--;
    }
    ll pr = pos[0];
    set<ll> er;
    for (int i = 0; i <= n; i++) er.insert(i);

    used[n] = 1;
    while (vec.size()) {
        ans++;
        ll cur = vec.back();
        vector<ll> ltr;
        ltr.push_back(cur);
        vec.pop_back();

        while (vec.size() > 0 && (*er.upper_bound(vec.back())) == cur) {
            ltr.push_back(vec.back());
            cur = vec.back();
            vec.pop_back();
        }

        for (auto c : ltr) er.erase(c);
    }

    cout << ans;

    return 0;
}

Compilation message

money.cpp: In function 'int main()':
money.cpp:39:8: warning: unused variable 'pr' [-Wunused-variable]
   39 |     ll pr = pos[0];
      |        ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Incorrect 1 ms 204 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Incorrect 1 ms 204 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Incorrect 1 ms 204 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Incorrect 1 ms 204 KB Output isn't correct
5 Halted 0 ms 0 KB -