답안 #180293

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
180293 2020-01-08T16:29:44 Z Nightmar Money (IZhO17_money) C++17
45 / 100
1500 ms 17644 KB
#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 = 999;
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;
	vector<int> v;
	v.pb(0);
	for (int i = 1; i <= n; i++) {
        cin >> a[i];
        v.pb(a[i]);
	}
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
	int ans = 0;
	for (int i = 1; i <= n; i++) {
        vector<int> kek;
        int L = upper_bound(v.begin(), v.end(), a[i]) - v.begin();
        int now = lower_bound(v.begin(), v.end(), a[i]) - v.begin();
        int r = i + 1;
        kek.pb(now);
        while (r <= n) {
            if (a[r] < a[r - 1]) break;
            int R = lower_bound(v.begin(), v.end(), a[r]) - v.begin() - 1;
            if (get(1, 1, v.size(), L, R)) break;
            now = lower_bound(v.begin(), v.end(), a[r]) - v.begin();
            kek.pb(now);
            r++;
        }
        //cout << i << ' ' << r - 1 << endl;
        i = r - 1;
        ans++;
        for (int q : kek) {
            update(1, 1, v.size(), q);
        }
	}
	cout << ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 1 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 1 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 380 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 1 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 1 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 380 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 1 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 292 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 1 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 1 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 380 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 1 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 292 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 508 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 3 ms 376 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
38 Correct 2 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 1 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 1 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 380 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 1 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 292 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 508 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 3 ms 376 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
38 Correct 2 ms 380 KB Output is correct
39 Correct 128 ms 5292 KB Output is correct
40 Correct 232 ms 7592 KB Output is correct
41 Correct 99 ms 4720 KB Output is correct
42 Correct 107 ms 4492 KB Output is correct
43 Correct 77 ms 3312 KB Output is correct
44 Correct 275 ms 9300 KB Output is correct
45 Correct 265 ms 9184 KB Output is correct
46 Correct 274 ms 9212 KB Output is correct
47 Correct 225 ms 9184 KB Output is correct
48 Correct 237 ms 9188 KB Output is correct
49 Correct 889 ms 13256 KB Output is correct
50 Correct 880 ms 13312 KB Output is correct
51 Correct 899 ms 13288 KB Output is correct
52 Correct 885 ms 13276 KB Output is correct
53 Correct 893 ms 13436 KB Output is correct
54 Correct 915 ms 13284 KB Output is correct
55 Correct 1364 ms 17504 KB Output is correct
56 Correct 1395 ms 17644 KB Output is correct
57 Correct 1416 ms 17452 KB Output is correct
58 Correct 1393 ms 17408 KB Output is correct
59 Correct 1400 ms 17404 KB Output is correct
60 Execution timed out 1510 ms 17512 KB Time limit exceeded
61 Halted 0 ms 0 KB -