답안 #338549

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
338549 2020-12-23T11:34:03 Z IZhO_2021_I_want_Silver Money (IZhO17_money) C++14
100 / 100
353 ms 19072 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <stack>
#include <queue>
#include <deque>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

// template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//  order_of_key (k) : Number of items strictly smaller than k .
//  find_by_order(k) : K-th element in a set (counting from zero).
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define show(a) cerr << #a <<" -> "<< a <<" "
#define nl cerr <<"\n"
//#define int ll

const int N = (1 << 20) - 1;
const int oo = 1e9 + 5;

int n, a[N], ans, t[N*2];

void upd(int pos, int x) {
    pos += N;
    t[pos] += x;
    while ((pos /= 2) >= 1) { t[pos] = t[pos*2] + t[pos*2+1]; }
}

int get(int l, int r) {
    int res = 0;
    for (l += N, r += N; l <= r; l /= 2, r /= 2) {
        if (l % 2 == 1) { res += t[l++]; }
        if (r % 2 == 0) { res += t[r--]; }
        if (l > r) { break; }
    }
    return res;
}

void solve() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    for (int l = 1; l <= n; ++l) {
        int r = l;
        while (r+1<=n && a[r] <= a[r+1] && get(a[l]+1, a[r+1]-1) == 0) { ++r; }
        for (int i = l; i <= r; ++i) { upd(a[i], 1); }
        l = r;
        ++ans;
    }
    cout << ans;
}

 main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int tests = 1;
	//cin >> tests;
	while (tests --) {
		solve();
	}
	return 0;
}
/*
    Just Chalish!
*/

Compilation message

money.cpp:74:8: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   74 |  main () {
      |        ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 640 KB Output is correct
16 Correct 1 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 640 KB Output is correct
16 Correct 1 ms 620 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 620 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 748 KB Output is correct
26 Correct 1 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 640 KB Output is correct
16 Correct 1 ms 620 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 620 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 748 KB Output is correct
26 Correct 1 ms 748 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 492 KB Output is correct
33 Correct 1 ms 492 KB Output is correct
34 Correct 1 ms 620 KB Output is correct
35 Correct 1 ms 492 KB Output is correct
36 Correct 1 ms 492 KB Output is correct
37 Correct 2 ms 2804 KB Output is correct
38 Correct 2 ms 2796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 640 KB Output is correct
16 Correct 1 ms 620 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 620 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 748 KB Output is correct
26 Correct 1 ms 748 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 492 KB Output is correct
33 Correct 1 ms 492 KB Output is correct
34 Correct 1 ms 620 KB Output is correct
35 Correct 1 ms 492 KB Output is correct
36 Correct 1 ms 492 KB Output is correct
37 Correct 2 ms 2804 KB Output is correct
38 Correct 2 ms 2796 KB Output is correct
39 Correct 87 ms 5612 KB Output is correct
40 Correct 159 ms 9068 KB Output is correct
41 Correct 70 ms 4588 KB Output is correct
42 Correct 71 ms 4588 KB Output is correct
43 Correct 50 ms 3456 KB Output is correct
44 Correct 189 ms 11392 KB Output is correct
45 Correct 190 ms 11116 KB Output is correct
46 Correct 190 ms 11372 KB Output is correct
47 Correct 184 ms 11244 KB Output is correct
48 Correct 181 ms 11372 KB Output is correct
49 Correct 272 ms 18924 KB Output is correct
50 Correct 271 ms 18924 KB Output is correct
51 Correct 274 ms 18924 KB Output is correct
52 Correct 269 ms 18924 KB Output is correct
53 Correct 265 ms 19052 KB Output is correct
54 Correct 271 ms 18808 KB Output is correct
55 Correct 345 ms 18924 KB Output is correct
56 Correct 353 ms 18924 KB Output is correct
57 Correct 345 ms 18924 KB Output is correct
58 Correct 353 ms 19072 KB Output is correct
59 Correct 345 ms 18924 KB Output is correct
60 Correct 346 ms 18924 KB Output is correct
61 Correct 344 ms 18796 KB Output is correct
62 Correct 345 ms 18924 KB Output is correct