Submission #375150

# Submission time Handle Problem Language Result Execution time Memory
375150 2021-03-09T03:44:33 Z vonatlus Po (COCI21_po) C++14
70 / 70
40 ms 7916 KB
/// vonat1us 

#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;
    }
    stack<int> s;
    vector<int> l(n, -1);
    for (int i = 0; i < n; ++i) {
        while (!s.empty() && a[s.top()] >= a[i]) {
            s.pop();
        }
        if (!s.empty()) l[i] = s.top();
        s.push(i);
    }
    while (!s.empty()) s.pop();
    vector<int> r(n, n);
    for (int i = n-1; ~i; --i) {
        while (!s.empty() && a[s.top()] >= a[i]) {
            s.pop();
        }
        if (!s.empty()) r[i] = s.top();
        s.push(i);
    }
    map<pii, int> mp;
    for (int i = 0; i < n; ++i) {
        if (a[i] == 0) continue;
        mp[{l[i], r[i]}] = 1;
    }
    cout << sz(mp);
} 

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
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 14 ms 3512 KB Output is correct
5 Correct 20 ms 5228 KB Output is correct
6 Correct 29 ms 4588 KB Output is correct
7 Correct 40 ms 7916 KB Output is correct