Submission #38219

# Submission time Handle Problem Language Result Execution time Memory
38219 2018-01-03T04:37:05 Z Talant Money (IZhO17_money) C++14
100 / 100
296 ms 13732 KB
#include <bits/stdc++.h>

#define fr first
#define sc second
#define OK puts("OK");
#define pb push_back
#define mk make_pair

using namespace std;

typedef long long ll;

const ll inf = (ll)1e9 + 7;
const int N = (int)1e6 + 1;

int n;
int b[N + 5],a[N + 5],t[N + 5],lst = 1,id = 1;
int ans;

void update (int pos) {
        for (; pos <= N; pos += (pos & (-pos)))
                t[pos] ++;
}

int get (int pos) {
        int res = 0;
        for (; pos > 0; pos -= (pos & (-pos)))
                res += t[pos];
        return res;
}

int main () {
        scanf ("%d", &n);

        for (int i = 1; i <= n; i ++)
                scanf ("%d", &b[i]);

        for (int i = 1; i <= n; i ++) {
                if (b[i - 1] != b[i])
                        a[id] = b[i],id ++;
        }
        n = id - 1;

        for (int i = 2; i <= n; i ++) {
                if (a[i] >= a[i - 1]) {
                        int o = get(a[i] - 1) - get(a[lst]);
                        if (o) {
                                for (int j = lst; j < i; j ++)
                                        update (a[j]);
                                lst = i;
                                ans ++;
                        }
                }
                else {
                        for (int j = lst; j < i; j ++)
                                update (a[j]);
                        lst = i;
                        ans ++;
                }
        }
        ans ++;

        cout << ans << endl;
}
/**
6
3 6 4 5 1 2
**/

Compilation message

money.cpp: In function 'int main()':
money.cpp:33:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf ("%d", &n);
                         ^
money.cpp:36:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
                 scanf ("%d", &b[i]);
                                    ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 13732 KB Output is correct
2 Correct 0 ms 13732 KB Output is correct
3 Correct 0 ms 13732 KB Output is correct
4 Correct 0 ms 13732 KB Output is correct
5 Correct 0 ms 13732 KB Output is correct
6 Correct 0 ms 13732 KB Output is correct
7 Correct 0 ms 13732 KB Output is correct
8 Correct 0 ms 13732 KB Output is correct
9 Correct 0 ms 13732 KB Output is correct
10 Correct 0 ms 13732 KB Output is correct
11 Correct 0 ms 13732 KB Output is correct
12 Correct 0 ms 13732 KB Output is correct
13 Correct 0 ms 13732 KB Output is correct
14 Correct 0 ms 13732 KB Output is correct
15 Correct 0 ms 13732 KB Output is correct
16 Correct 0 ms 13732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 13732 KB Output is correct
2 Correct 0 ms 13732 KB Output is correct
3 Correct 0 ms 13732 KB Output is correct
4 Correct 0 ms 13732 KB Output is correct
5 Correct 0 ms 13732 KB Output is correct
6 Correct 0 ms 13732 KB Output is correct
7 Correct 0 ms 13732 KB Output is correct
8 Correct 0 ms 13732 KB Output is correct
9 Correct 0 ms 13732 KB Output is correct
10 Correct 0 ms 13732 KB Output is correct
11 Correct 0 ms 13732 KB Output is correct
12 Correct 0 ms 13732 KB Output is correct
13 Correct 0 ms 13732 KB Output is correct
14 Correct 0 ms 13732 KB Output is correct
15 Correct 0 ms 13732 KB Output is correct
16 Correct 0 ms 13732 KB Output is correct
17 Correct 0 ms 13732 KB Output is correct
18 Correct 0 ms 13732 KB Output is correct
19 Correct 0 ms 13732 KB Output is correct
20 Correct 0 ms 13732 KB Output is correct
21 Correct 0 ms 13732 KB Output is correct
22 Correct 0 ms 13732 KB Output is correct
23 Correct 0 ms 13732 KB Output is correct
24 Correct 0 ms 13732 KB Output is correct
25 Correct 0 ms 13732 KB Output is correct
26 Correct 0 ms 13732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 13732 KB Output is correct
2 Correct 0 ms 13732 KB Output is correct
3 Correct 0 ms 13732 KB Output is correct
4 Correct 0 ms 13732 KB Output is correct
5 Correct 0 ms 13732 KB Output is correct
6 Correct 0 ms 13732 KB Output is correct
7 Correct 0 ms 13732 KB Output is correct
8 Correct 0 ms 13732 KB Output is correct
9 Correct 0 ms 13732 KB Output is correct
10 Correct 0 ms 13732 KB Output is correct
11 Correct 0 ms 13732 KB Output is correct
12 Correct 0 ms 13732 KB Output is correct
13 Correct 0 ms 13732 KB Output is correct
14 Correct 0 ms 13732 KB Output is correct
15 Correct 0 ms 13732 KB Output is correct
16 Correct 0 ms 13732 KB Output is correct
17 Correct 0 ms 13732 KB Output is correct
18 Correct 0 ms 13732 KB Output is correct
19 Correct 0 ms 13732 KB Output is correct
20 Correct 0 ms 13732 KB Output is correct
21 Correct 0 ms 13732 KB Output is correct
22 Correct 0 ms 13732 KB Output is correct
23 Correct 0 ms 13732 KB Output is correct
24 Correct 0 ms 13732 KB Output is correct
25 Correct 0 ms 13732 KB Output is correct
26 Correct 0 ms 13732 KB Output is correct
27 Correct 0 ms 13732 KB Output is correct
28 Correct 0 ms 13732 KB Output is correct
29 Correct 0 ms 13732 KB Output is correct
30 Correct 0 ms 13732 KB Output is correct
31 Correct 0 ms 13732 KB Output is correct
32 Correct 0 ms 13732 KB Output is correct
33 Correct 0 ms 13732 KB Output is correct
34 Correct 0 ms 13732 KB Output is correct
35 Correct 0 ms 13732 KB Output is correct
36 Correct 0 ms 13732 KB Output is correct
37 Correct 0 ms 13732 KB Output is correct
38 Correct 0 ms 13732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 13732 KB Output is correct
2 Correct 0 ms 13732 KB Output is correct
3 Correct 0 ms 13732 KB Output is correct
4 Correct 0 ms 13732 KB Output is correct
5 Correct 0 ms 13732 KB Output is correct
6 Correct 0 ms 13732 KB Output is correct
7 Correct 0 ms 13732 KB Output is correct
8 Correct 0 ms 13732 KB Output is correct
9 Correct 0 ms 13732 KB Output is correct
10 Correct 0 ms 13732 KB Output is correct
11 Correct 0 ms 13732 KB Output is correct
12 Correct 0 ms 13732 KB Output is correct
13 Correct 0 ms 13732 KB Output is correct
14 Correct 0 ms 13732 KB Output is correct
15 Correct 0 ms 13732 KB Output is correct
16 Correct 0 ms 13732 KB Output is correct
17 Correct 0 ms 13732 KB Output is correct
18 Correct 0 ms 13732 KB Output is correct
19 Correct 0 ms 13732 KB Output is correct
20 Correct 0 ms 13732 KB Output is correct
21 Correct 0 ms 13732 KB Output is correct
22 Correct 0 ms 13732 KB Output is correct
23 Correct 0 ms 13732 KB Output is correct
24 Correct 0 ms 13732 KB Output is correct
25 Correct 0 ms 13732 KB Output is correct
26 Correct 0 ms 13732 KB Output is correct
27 Correct 0 ms 13732 KB Output is correct
28 Correct 0 ms 13732 KB Output is correct
29 Correct 0 ms 13732 KB Output is correct
30 Correct 0 ms 13732 KB Output is correct
31 Correct 0 ms 13732 KB Output is correct
32 Correct 0 ms 13732 KB Output is correct
33 Correct 0 ms 13732 KB Output is correct
34 Correct 0 ms 13732 KB Output is correct
35 Correct 0 ms 13732 KB Output is correct
36 Correct 0 ms 13732 KB Output is correct
37 Correct 0 ms 13732 KB Output is correct
38 Correct 0 ms 13732 KB Output is correct
39 Correct 103 ms 13732 KB Output is correct
40 Correct 183 ms 13732 KB Output is correct
41 Correct 89 ms 13732 KB Output is correct
42 Correct 73 ms 13732 KB Output is correct
43 Correct 49 ms 13732 KB Output is correct
44 Correct 219 ms 13732 KB Output is correct
45 Correct 249 ms 13732 KB Output is correct
46 Correct 229 ms 13732 KB Output is correct
47 Correct 179 ms 13732 KB Output is correct
48 Correct 189 ms 13732 KB Output is correct
49 Correct 259 ms 13732 KB Output is correct
50 Correct 243 ms 13732 KB Output is correct
51 Correct 259 ms 13732 KB Output is correct
52 Correct 243 ms 13732 KB Output is correct
53 Correct 226 ms 13732 KB Output is correct
54 Correct 239 ms 13732 KB Output is correct
55 Correct 296 ms 13732 KB Output is correct
56 Correct 283 ms 13732 KB Output is correct
57 Correct 276 ms 13732 KB Output is correct
58 Correct 229 ms 13732 KB Output is correct
59 Correct 246 ms 13732 KB Output is correct
60 Correct 259 ms 13732 KB Output is correct
61 Correct 266 ms 13732 KB Output is correct
62 Correct 266 ms 13732 KB Output is correct