Submission #36950

#TimeUsernameProblemLanguageResultExecution timeMemory
36950nickyrioMoney (IZhO17_money)C++14
100 / 100
223 ms9836 KiB
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i<=b ; i++)
#define FORD(i, a, b) for (int i = a; i>=b; i--)
#define REP(i, a) for (int i = 0; i<a; i++)
#define N 1001000
#define pp pair<int, int>
#define IO cin.tie(NULL);cout.tie(NULL);
#define bit(S, i) (((S) >> i) & 1)
template<typename T> inline void read(T &x) {
    char c;
    bool neg = false;
    while (!isdigit(c = getchar()) && c != '-');
    x = 0;
    if (c == '-') {
        neg = true;
        c = getchar();
    }
    do {
        x = x * 10 + c - '0';
    } while (isdigit(c = getchar()));
    if (neg) x = -x;
}
template<typename T> inline void write(T x) {
    if (x < 0) {
        putchar('-');
        write(-x);return;
    }
    if (x < 10) {
        putchar(char(x + 48));
    }
    else {
        write(x/10);
        putchar(char(48 + x%10));
    }
}
template<typename T> inline void writeln(T x) {
    write(x);
    putchar('\n');
}
using namespace std;
int n, a[N];
set<int> used;

int BIT[N];

void Up(int u, int val) {
    for(; u > 0; u -= u & -u) BIT[u] = min(BIT[u], val);
}

int Get(int u) {
    int ans = 1e9;
    for(; u < N ; u += u & -u) ans = min(ans, BIT[u]);
    return ans;
}

int main() {
    IO;
    read(n);
    FOR(i, 1, n) read(a[i]);
    FOR(i, 1, N - 1) BIT[i] = 1e9;
    int start = 1;
    int cnt = 0;
    while (start <= n) {
        cnt++;
        int last = start + 1;
        Up(a[start], a[start]);
        int lim = Get(a[start] + 1);
    //    cerr << lim << ' ';
        while (last <= n && a[last] <= lim && a[last] >= a[last - 1]) {
            Up(a[last], a[last]); last++; 
        }
        start = last;
    }
    writeln(cnt);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...