답안 #340402

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
340402 2020-12-27T14:10:52 Z balanda Money (IZhO17_money) C++17
100 / 100
708 ms 45292 KB
/*
             _   _                    _           _                 _         __   _____ _____ _
            | | | |               _  | |         | |               | |       /  | |____ |  ___(_)
  __ _ _   _| |_| |__   ___  _ __(_) | |__   __ _| | __ _ _ __   __| | __ _  `| |     / /___ \ _  __ _
 / _` | | | | __| '_ \ / _ \| '__|   | '_ \ / _` | |/ _` | '_ \ / _` |/ _` |  | |     \ \   \ \ |/ _` |
| (_| | |_| | |_| | | | (_) | |   _  | |_) | (_| | | (_| | | | | (_| | (_| | _| |_.___/ /\__/ / | (_| |
 \__,_|\__,_|\__|_| |_|\___/|_|  (_) |_.__/ \__,_|_|\__,_|_| |_|\__,_|\__,_| \___/\____/\____/|_|\__, |
                                                                                                    | |
                                                                                                    |_|
  __ _  __ _   _ __ ___   __ ___   _________  ___
 / _` |/ _` | | '_ ` _ \ / _` \ \ / /_  / _ \/ __|
| (_| | (_| | | | | | | | (_| |\ V / / /  __/\__ \
 \__, |\__, | |_| |_| |_|\__,_| \_/ /___\___||___/
    | |   | |
    |_|   |_|
 * */
#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define int long long

template<class T>
istream& operator>>(istream &in, vector<T> &v){
    for(auto &to: v) in >> to;
    return in;
}

template<class T>
ostream& operator<<(ostream &out, const vector<T> &v){
    for(auto &to: v) out << v << ' ';
    return out;
}


template<class U, class V>
istream& operator>>(istream &in, pair<U, V> &v){
    in >> v.first >> v.second;
    return in;
}

template<class U, class V>
ostream& operator<<(ostream &out, const pair<U, V> &v){
    out << v.first << ' ' << v.second;
    return out;
}

#ifdef DEBUG
#define dbg(x) cout << "debug:" << __LINE__ << ' ' << #x << "=" << x
#else
#define dbg(x) 42
#endif

vector<int> tree;

void upd(int v, int tl, int tr, int ind){
    if(tl + 1 == tr) {
        tree[v] += 1;
        return;
    }
    int tm = tl + tr >> 1;
    if(ind >= tm)
        upd(2 * v + 2, tm, tr, ind);
    else upd(2 * v + 1, tl, tm, ind);
    tree[v] = tree[2 * v + 1] + tree[2 * v + 2];
}

int get(int v, int tl, int tr, int l, int r){
    if(l >= r) return 0;
    if(tl == l && tr == r) return tree[v];
    int tm = tl + tr >> 1;
    return  get(2 * v + 1, tl, tm, l, min(r, tm)) +
            get(2 * v + 2, tm, tr, max(l, tm), r);
}

int solve(){
    int n;
    cin >> n;
    vector<int> v(n);
    cin >> v;
    tree.resize((int)4e6, 0);
    for(int i = 0; i < n; i++) v[i]--;
    int l = 0;
    int ans = 0;
    int r = 1;
    while(l < n){
        if(r == n){
            ans++;
            break;
        }
        if(v[r] < v[r - 1]){
            for(int i = l; i < r; i++)
                upd(0, 0, 1e6, v[i]);
            l = r;
            r = l + 1;
            ans++;
        } else {
            if(get(0, 0, 1e6, v[l] + 1, v[r])){
                for(int i = l; i < r; i++)
                    upd(0, 0, 1e6, v[i]);
                l = r;
                r = l + 1;
                ans++;
            } else{
                r++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}
signed main() {
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
//        freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
//    cin >> t;
    while(t  --> 0){
        assert(solve() == 0);
        cout << endl;
    }
    return 0;
}

Compilation message

money.cpp: In function 'void upd(long long int, long long int, long long int, long long int)':
money.cpp:61:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   61 |     int tm = tl + tr >> 1;
      |              ~~~^~~~
money.cpp: In function 'long long int get(long long int, long long int, long long int, long long int, long long int)':
money.cpp:71:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   71 |     int tm = tl + tr >> 1;
      |              ~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 31596 KB Output is correct
2 Correct 18 ms 31596 KB Output is correct
3 Correct 19 ms 31596 KB Output is correct
4 Correct 18 ms 31596 KB Output is correct
5 Correct 18 ms 31596 KB Output is correct
6 Correct 18 ms 31616 KB Output is correct
7 Correct 18 ms 31596 KB Output is correct
8 Correct 17 ms 31596 KB Output is correct
9 Correct 18 ms 31616 KB Output is correct
10 Correct 18 ms 31596 KB Output is correct
11 Correct 18 ms 31596 KB Output is correct
12 Correct 18 ms 31692 KB Output is correct
13 Correct 18 ms 31596 KB Output is correct
14 Correct 17 ms 31596 KB Output is correct
15 Correct 18 ms 31616 KB Output is correct
16 Correct 18 ms 31612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 31596 KB Output is correct
2 Correct 18 ms 31596 KB Output is correct
3 Correct 19 ms 31596 KB Output is correct
4 Correct 18 ms 31596 KB Output is correct
5 Correct 18 ms 31596 KB Output is correct
6 Correct 18 ms 31616 KB Output is correct
7 Correct 18 ms 31596 KB Output is correct
8 Correct 17 ms 31596 KB Output is correct
9 Correct 18 ms 31616 KB Output is correct
10 Correct 18 ms 31596 KB Output is correct
11 Correct 18 ms 31596 KB Output is correct
12 Correct 18 ms 31692 KB Output is correct
13 Correct 18 ms 31596 KB Output is correct
14 Correct 17 ms 31596 KB Output is correct
15 Correct 18 ms 31616 KB Output is correct
16 Correct 18 ms 31612 KB Output is correct
17 Correct 18 ms 31724 KB Output is correct
18 Correct 17 ms 31596 KB Output is correct
19 Correct 18 ms 31596 KB Output is correct
20 Correct 18 ms 31596 KB Output is correct
21 Correct 20 ms 31596 KB Output is correct
22 Correct 18 ms 31596 KB Output is correct
23 Correct 18 ms 31596 KB Output is correct
24 Correct 18 ms 31596 KB Output is correct
25 Correct 18 ms 31596 KB Output is correct
26 Correct 18 ms 31596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 31596 KB Output is correct
2 Correct 18 ms 31596 KB Output is correct
3 Correct 19 ms 31596 KB Output is correct
4 Correct 18 ms 31596 KB Output is correct
5 Correct 18 ms 31596 KB Output is correct
6 Correct 18 ms 31616 KB Output is correct
7 Correct 18 ms 31596 KB Output is correct
8 Correct 17 ms 31596 KB Output is correct
9 Correct 18 ms 31616 KB Output is correct
10 Correct 18 ms 31596 KB Output is correct
11 Correct 18 ms 31596 KB Output is correct
12 Correct 18 ms 31692 KB Output is correct
13 Correct 18 ms 31596 KB Output is correct
14 Correct 17 ms 31596 KB Output is correct
15 Correct 18 ms 31616 KB Output is correct
16 Correct 18 ms 31612 KB Output is correct
17 Correct 18 ms 31724 KB Output is correct
18 Correct 17 ms 31596 KB Output is correct
19 Correct 18 ms 31596 KB Output is correct
20 Correct 18 ms 31596 KB Output is correct
21 Correct 20 ms 31596 KB Output is correct
22 Correct 18 ms 31596 KB Output is correct
23 Correct 18 ms 31596 KB Output is correct
24 Correct 18 ms 31596 KB Output is correct
25 Correct 18 ms 31596 KB Output is correct
26 Correct 18 ms 31596 KB Output is correct
27 Correct 22 ms 31596 KB Output is correct
28 Correct 17 ms 31596 KB Output is correct
29 Correct 18 ms 31596 KB Output is correct
30 Correct 18 ms 31616 KB Output is correct
31 Correct 18 ms 31596 KB Output is correct
32 Correct 19 ms 31596 KB Output is correct
33 Correct 18 ms 31596 KB Output is correct
34 Correct 18 ms 31596 KB Output is correct
35 Correct 19 ms 31596 KB Output is correct
36 Correct 18 ms 31744 KB Output is correct
37 Correct 18 ms 31596 KB Output is correct
38 Correct 18 ms 31596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 31596 KB Output is correct
2 Correct 18 ms 31596 KB Output is correct
3 Correct 19 ms 31596 KB Output is correct
4 Correct 18 ms 31596 KB Output is correct
5 Correct 18 ms 31596 KB Output is correct
6 Correct 18 ms 31616 KB Output is correct
7 Correct 18 ms 31596 KB Output is correct
8 Correct 17 ms 31596 KB Output is correct
9 Correct 18 ms 31616 KB Output is correct
10 Correct 18 ms 31596 KB Output is correct
11 Correct 18 ms 31596 KB Output is correct
12 Correct 18 ms 31692 KB Output is correct
13 Correct 18 ms 31596 KB Output is correct
14 Correct 17 ms 31596 KB Output is correct
15 Correct 18 ms 31616 KB Output is correct
16 Correct 18 ms 31612 KB Output is correct
17 Correct 18 ms 31724 KB Output is correct
18 Correct 17 ms 31596 KB Output is correct
19 Correct 18 ms 31596 KB Output is correct
20 Correct 18 ms 31596 KB Output is correct
21 Correct 20 ms 31596 KB Output is correct
22 Correct 18 ms 31596 KB Output is correct
23 Correct 18 ms 31596 KB Output is correct
24 Correct 18 ms 31596 KB Output is correct
25 Correct 18 ms 31596 KB Output is correct
26 Correct 18 ms 31596 KB Output is correct
27 Correct 22 ms 31596 KB Output is correct
28 Correct 17 ms 31596 KB Output is correct
29 Correct 18 ms 31596 KB Output is correct
30 Correct 18 ms 31616 KB Output is correct
31 Correct 18 ms 31596 KB Output is correct
32 Correct 19 ms 31596 KB Output is correct
33 Correct 18 ms 31596 KB Output is correct
34 Correct 18 ms 31596 KB Output is correct
35 Correct 19 ms 31596 KB Output is correct
36 Correct 18 ms 31744 KB Output is correct
37 Correct 18 ms 31596 KB Output is correct
38 Correct 18 ms 31596 KB Output is correct
39 Correct 191 ms 38656 KB Output is correct
40 Correct 332 ms 42988 KB Output is correct
41 Correct 155 ms 37240 KB Output is correct
42 Correct 158 ms 36716 KB Output is correct
43 Correct 115 ms 35180 KB Output is correct
44 Correct 396 ms 45036 KB Output is correct
45 Correct 404 ms 45036 KB Output is correct
46 Correct 390 ms 45292 KB Output is correct
47 Correct 395 ms 45292 KB Output is correct
48 Correct 362 ms 45292 KB Output is correct
49 Correct 551 ms 45292 KB Output is correct
50 Correct 551 ms 44176 KB Output is correct
51 Correct 563 ms 44140 KB Output is correct
52 Correct 543 ms 44120 KB Output is correct
53 Correct 552 ms 44268 KB Output is correct
54 Correct 548 ms 44140 KB Output is correct
55 Correct 706 ms 44140 KB Output is correct
56 Correct 701 ms 45200 KB Output is correct
57 Correct 702 ms 45164 KB Output is correct
58 Correct 708 ms 45164 KB Output is correct
59 Correct 706 ms 44560 KB Output is correct
60 Correct 701 ms 44780 KB Output is correct
61 Correct 708 ms 44780 KB Output is correct
62 Correct 707 ms 44780 KB Output is correct