Submission #384150

# Submission time Handle Problem Language Result Execution time Memory
384150 2021-03-31T14:42:38 Z nguyen31hoang08minh2003 Po (COCI21_po) C++14
20 / 70
35 ms 8300 KB
#include <bits/stdc++.h>
#define fore(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define fort(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define ford(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;

template<class A, class B> bool maxi(A &a, const B &b) {return (a < b) ? (a = b, true):false;};
template<class A, class B> bool mini(A &a, const B &b) {return (a > b) ? (a = b, true):false;};

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

const int maxN = 100005, inf = 1e9 + 31082003;

int n, a[maxN], res, r[maxN];
vi idx[maxN];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    vi v(n);
    fort(i, 1, n) {
        cin >> a[i];
        v[i - 1] = a[i];
    }
    sort(all(v));
    v.resize(distance(v.begin(), unique(all(v))));
    const int m = sz(v);
    fort(i, 1, n) {
        a[i] = (lower_bound(all(v), a[i]) - v.begin()) + 1;
        idx[a[i]].pb(i);
    }
    stack<int> st;
    ford(i, n, 1) {
        while (!st.empty() && a[st.top()] >= a[i])
            st.pop();
        r[i] = st.empty() ? inf : st.top();
        st.push(i);
    }
//    fort(i, 1, n)
//        cerr << r[i] << ' ';
//    cerr << '\n';
    fort(i, 1, m) {
        int x = 0;
        for (const int &j : idx[i]) {
            if (x < j) {
                x = r[j];
                ++res;
            }
        }
    }
    cout << res << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2668 KB Output is correct
2 Incorrect 3 ms 2668 KB Output isn't correct
3 Incorrect 3 ms 2668 KB Output isn't correct
4 Incorrect 11 ms 3820 KB Output isn't correct
5 Incorrect 15 ms 4204 KB Output isn't correct
6 Correct 35 ms 6636 KB Output is correct
7 Incorrect 28 ms 8300 KB Output isn't correct