Submission #38237

# Submission time Handle Problem Language Result Execution time Memory
38237 2018-01-03T05:09:28 Z mirbek01 Money (IZhO17_money) C++14
100 / 100
949 ms 21548 KB
# include <bits/stdc++.h>

# define pb push_back
# define fr first
# define sc second
# define mk make_pair

using namespace std;

const long long linf = 1e18 + 7;
const int inf = 1e9 + 7;
const int N = 1e6 + 5;

typedef long long ll;

int n, a[N], t[N * 4], ans = 1;

void update(int pos, int v = 1, int tl = 1, int tr = N - 1){
      if(tl == tr)
            t[v] ++;
      else{
            int tm = (tl + tr) >> 1;
            if(pos <= tm)
                  update(pos, v << 1, tl, tm);
            else
                  update(pos, (v << 1) | 1, tm + 1, tr);
            t[v] = t[v << 1] + t[(v << 1) | 1];
      }
}

int get(int l, int r, int v = 1, int tl = 1, int tr = N - 1){
      if(l > tr || tl > r) return 0;
      if(l <= tl && tr <= r) return t[v];
      int tm = (tl + tr) >> 1;
      return get(l, r, v << 1, tl, tm) +
                  get(l, r, (v << 1) | 1, tm + 1, tr);
}

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

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

      for(int i = 2; i <= n; i ++){
            if(a[i] < a[i - 1]){
                  ans ++;
                  while(f + 1 <= i)
                        update(a[f ++]);

            }
            else {
                  int sum = get(a[f] + 1, a[i] - 1);
//                  cout << a[f + 1] + 1 << " " << a[i] - 1 << " " << sum << endl;
                  if(sum){
                        ans ++;
                        while(f + 1 <= i)
                              update(a[f ++]);
                  }
            }
      }

      cout << ans << endl;
}

Compilation message

money.cpp: In function 'int main()':
money.cpp:40:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d", &n);
                      ^
money.cpp:43:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &a[i]);
                               ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 21548 KB Output is correct
2 Correct 0 ms 21548 KB Output is correct
3 Correct 0 ms 21548 KB Output is correct
4 Correct 0 ms 21548 KB Output is correct
5 Correct 0 ms 21548 KB Output is correct
6 Correct 0 ms 21548 KB Output is correct
7 Correct 0 ms 21548 KB Output is correct
8 Correct 0 ms 21548 KB Output is correct
9 Correct 0 ms 21548 KB Output is correct
10 Correct 0 ms 21548 KB Output is correct
11 Correct 0 ms 21548 KB Output is correct
12 Correct 0 ms 21548 KB Output is correct
13 Correct 0 ms 21548 KB Output is correct
14 Correct 0 ms 21548 KB Output is correct
15 Correct 0 ms 21548 KB Output is correct
16 Correct 0 ms 21548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 21548 KB Output is correct
2 Correct 0 ms 21548 KB Output is correct
3 Correct 0 ms 21548 KB Output is correct
4 Correct 0 ms 21548 KB Output is correct
5 Correct 0 ms 21548 KB Output is correct
6 Correct 0 ms 21548 KB Output is correct
7 Correct 0 ms 21548 KB Output is correct
8 Correct 0 ms 21548 KB Output is correct
9 Correct 0 ms 21548 KB Output is correct
10 Correct 0 ms 21548 KB Output is correct
11 Correct 0 ms 21548 KB Output is correct
12 Correct 0 ms 21548 KB Output is correct
13 Correct 0 ms 21548 KB Output is correct
14 Correct 0 ms 21548 KB Output is correct
15 Correct 0 ms 21548 KB Output is correct
16 Correct 0 ms 21548 KB Output is correct
17 Correct 0 ms 21548 KB Output is correct
18 Correct 0 ms 21548 KB Output is correct
19 Correct 0 ms 21548 KB Output is correct
20 Correct 0 ms 21548 KB Output is correct
21 Correct 0 ms 21548 KB Output is correct
22 Correct 0 ms 21548 KB Output is correct
23 Correct 0 ms 21548 KB Output is correct
24 Correct 0 ms 21548 KB Output is correct
25 Correct 0 ms 21548 KB Output is correct
26 Correct 0 ms 21548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 21548 KB Output is correct
2 Correct 0 ms 21548 KB Output is correct
3 Correct 0 ms 21548 KB Output is correct
4 Correct 0 ms 21548 KB Output is correct
5 Correct 0 ms 21548 KB Output is correct
6 Correct 0 ms 21548 KB Output is correct
7 Correct 0 ms 21548 KB Output is correct
8 Correct 0 ms 21548 KB Output is correct
9 Correct 0 ms 21548 KB Output is correct
10 Correct 0 ms 21548 KB Output is correct
11 Correct 0 ms 21548 KB Output is correct
12 Correct 0 ms 21548 KB Output is correct
13 Correct 0 ms 21548 KB Output is correct
14 Correct 0 ms 21548 KB Output is correct
15 Correct 0 ms 21548 KB Output is correct
16 Correct 0 ms 21548 KB Output is correct
17 Correct 0 ms 21548 KB Output is correct
18 Correct 0 ms 21548 KB Output is correct
19 Correct 0 ms 21548 KB Output is correct
20 Correct 0 ms 21548 KB Output is correct
21 Correct 0 ms 21548 KB Output is correct
22 Correct 0 ms 21548 KB Output is correct
23 Correct 0 ms 21548 KB Output is correct
24 Correct 0 ms 21548 KB Output is correct
25 Correct 0 ms 21548 KB Output is correct
26 Correct 0 ms 21548 KB Output is correct
27 Correct 0 ms 21548 KB Output is correct
28 Correct 0 ms 21548 KB Output is correct
29 Correct 0 ms 21548 KB Output is correct
30 Correct 0 ms 21548 KB Output is correct
31 Correct 0 ms 21548 KB Output is correct
32 Correct 0 ms 21548 KB Output is correct
33 Correct 0 ms 21548 KB Output is correct
34 Correct 0 ms 21548 KB Output is correct
35 Correct 0 ms 21548 KB Output is correct
36 Correct 0 ms 21548 KB Output is correct
37 Correct 0 ms 21548 KB Output is correct
38 Correct 0 ms 21548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 21548 KB Output is correct
2 Correct 0 ms 21548 KB Output is correct
3 Correct 0 ms 21548 KB Output is correct
4 Correct 0 ms 21548 KB Output is correct
5 Correct 0 ms 21548 KB Output is correct
6 Correct 0 ms 21548 KB Output is correct
7 Correct 0 ms 21548 KB Output is correct
8 Correct 0 ms 21548 KB Output is correct
9 Correct 0 ms 21548 KB Output is correct
10 Correct 0 ms 21548 KB Output is correct
11 Correct 0 ms 21548 KB Output is correct
12 Correct 0 ms 21548 KB Output is correct
13 Correct 0 ms 21548 KB Output is correct
14 Correct 0 ms 21548 KB Output is correct
15 Correct 0 ms 21548 KB Output is correct
16 Correct 0 ms 21548 KB Output is correct
17 Correct 0 ms 21548 KB Output is correct
18 Correct 0 ms 21548 KB Output is correct
19 Correct 0 ms 21548 KB Output is correct
20 Correct 0 ms 21548 KB Output is correct
21 Correct 0 ms 21548 KB Output is correct
22 Correct 0 ms 21548 KB Output is correct
23 Correct 0 ms 21548 KB Output is correct
24 Correct 0 ms 21548 KB Output is correct
25 Correct 0 ms 21548 KB Output is correct
26 Correct 0 ms 21548 KB Output is correct
27 Correct 0 ms 21548 KB Output is correct
28 Correct 0 ms 21548 KB Output is correct
29 Correct 0 ms 21548 KB Output is correct
30 Correct 0 ms 21548 KB Output is correct
31 Correct 0 ms 21548 KB Output is correct
32 Correct 0 ms 21548 KB Output is correct
33 Correct 0 ms 21548 KB Output is correct
34 Correct 0 ms 21548 KB Output is correct
35 Correct 0 ms 21548 KB Output is correct
36 Correct 0 ms 21548 KB Output is correct
37 Correct 0 ms 21548 KB Output is correct
38 Correct 0 ms 21548 KB Output is correct
39 Correct 189 ms 21548 KB Output is correct
40 Correct 353 ms 21548 KB Output is correct
41 Correct 139 ms 21548 KB Output is correct
42 Correct 133 ms 21548 KB Output is correct
43 Correct 99 ms 21548 KB Output is correct
44 Correct 396 ms 21548 KB Output is correct
45 Correct 383 ms 21548 KB Output is correct
46 Correct 393 ms 21548 KB Output is correct
47 Correct 416 ms 21548 KB Output is correct
48 Correct 413 ms 21548 KB Output is correct
49 Correct 586 ms 21548 KB Output is correct
50 Correct 636 ms 21548 KB Output is correct
51 Correct 583 ms 21548 KB Output is correct
52 Correct 676 ms 21548 KB Output is correct
53 Correct 649 ms 21548 KB Output is correct
54 Correct 636 ms 21548 KB Output is correct
55 Correct 833 ms 21548 KB Output is correct
56 Correct 856 ms 21548 KB Output is correct
57 Correct 879 ms 21548 KB Output is correct
58 Correct 819 ms 21548 KB Output is correct
59 Correct 906 ms 21548 KB Output is correct
60 Correct 829 ms 21548 KB Output is correct
61 Correct 929 ms 21548 KB Output is correct
62 Correct 949 ms 21548 KB Output is correct