이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <iomanip>
#include <unordered_map>
#define SWS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define ppb pop_back
#define ft first
#define sd second
#define readf freopen("input.txt", "r", stdin)
#define writef freopen("output.txt", "w", stdout)
#define files readf; writef
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int Z = 1000 * 1000;
const int N = (int)1e6 + 228;
const int INF = (int)1e9 + 5;
const int MOD = (int)1e9 + 7;
int a[N], t[4 * N];
void update(int v, int tl, int tr, int pos) {
    if (tl == tr) {
        t[v]++;
        return;
    }
    int mid = (tl + tr) / 2;
    if (pos <= mid) update(2 * v, tl, mid, pos);
    else update(2 * v + 1, mid + 1, tr, pos);
    t[v] = t[2 * v] + t[2 * v + 1];
}
int get(int v, int tl, int tr, int l, int r) {
    if (tl >= l && tr <= r) {
        return t[v];
    }
    if (tl > r || tr < l) {
        return 0;
    }
    int mid = (tl + tr) / 2;
    return get(2 * v, tl, mid, l, r) + get(2 * v + 1, mid + 1, tr, l, r);
}
int main() {
	SWS;
	srand(time(0));
	//files;
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
	int ans = 0;
	for (int i = 1; i <= n; i++) {
        vector<int> kek;
        kek.pb(a[i]);
        int r = i + 1;
        while (r <= n) {
            if (a[r] < a[r - 1]) break;
            if (get(1, 1, Z, a[i] + 1, a[r] - 1)) break;
            kek.pb(a[r]);
            r++;
        }
        i = r - 1;
        ans++;
        for (int q : kek) {
            update(1, 1, Z, q);
        }
	}
	cout << ans;
    return 0;
}
| # | 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... |