답안 #697003

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
697003 2023-02-07T21:16:50 Z allllekssssa Money (IZhO17_money) C++14
100 / 100
131 ms 14948 KB
#include<bits/stdc++.h>
 
using namespace std;
 
const int maxN = 1e6 + 10;
int a[maxN], bit[maxN];
int n;

void update(int x) {

	for (int i = x; i < maxN; i+=i&-i) {
		bit[i]++;
	}
}

int get(int x) {
	int ans = 0;

	for (int i = x; i > 0; i-=i&-i) {
		ans+=bit[i];
	}

	return ans;
}

void sredi(int l, int r) {
	for (int i = l; i <= r; i++) {
		update(a[i]);
	}
}
 
int main() {
 
	cin >> n;
 
	for (int i = 1; i<=n; i++) {
		scanf("%d", &a[i]);
	}
    
    int ans = 0;
    int pre = 0;
	for (int i = 1; i < n; i++) {
		if (i < n && a[i] > a[i + 1]) {
			++ans;
			sredi(pre + 1, i);
			pre = i;
			continue;
		}
        
		if (a[i] == a[i + 1]) continue;
        
        if (get(a[i + 1] - 1) - get(a[pre + 1]) > 0) {
        	++ans;
        	sredi(pre + 1, i);
        	pre = i;
        }
	}
 
	cout << ans + 1 << endl;
}

Compilation message

money.cpp: In function 'int main()':
money.cpp:37:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |   scanf("%d", &a[i]);
      |   ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 468 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 468 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 1 ms 1620 KB Output is correct
38 Correct 1 ms 1748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 468 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 1 ms 1620 KB Output is correct
38 Correct 1 ms 1748 KB Output is correct
39 Correct 57 ms 2264 KB Output is correct
40 Correct 106 ms 8916 KB Output is correct
41 Correct 48 ms 4472 KB Output is correct
42 Correct 43 ms 4132 KB Output is correct
43 Correct 31 ms 3100 KB Output is correct
44 Correct 124 ms 11084 KB Output is correct
45 Correct 119 ms 10996 KB Output is correct
46 Correct 121 ms 11100 KB Output is correct
47 Correct 109 ms 11088 KB Output is correct
48 Correct 130 ms 11068 KB Output is correct
49 Correct 123 ms 14904 KB Output is correct
50 Correct 121 ms 14880 KB Output is correct
51 Correct 124 ms 14796 KB Output is correct
52 Correct 123 ms 14892 KB Output is correct
53 Correct 125 ms 14880 KB Output is correct
54 Correct 126 ms 14772 KB Output is correct
55 Correct 129 ms 14784 KB Output is correct
56 Correct 126 ms 14812 KB Output is correct
57 Correct 130 ms 14764 KB Output is correct
58 Correct 130 ms 14860 KB Output is correct
59 Correct 126 ms 14848 KB Output is correct
60 Correct 128 ms 14948 KB Output is correct
61 Correct 130 ms 14780 KB Output is correct
62 Correct 131 ms 14824 KB Output is correct