# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
467143 |
2021-08-21T19:12:29 Z |
aryan12 |
Money (IZhO17_money) |
C++17 |
|
231 ms |
16720 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1e6 + 5;
int bit[N];
//3 5 4 6
//4 5 6 3
//3 4 5 4
void Update(int pos, int val) {
for(int i = pos; i < N; i += (i & (-i))) {
bit[i] += val;
}
}
int Query(int pos) {
int ans = 0;
for(int i = pos; i > 0; i -= (i & (-i))) {
ans += bit[i];
}
return ans;
}
void Solve() {
/*for(int i = 0; i < N; i++) {
bit[i] = 0;
}*/
int n;
cin >> n;
int a[n + 1];
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
int ans = 1, prev = 1;
int cur_low = a[1], cur_high = a[1];
int cnt_low = 1, cnt_high = 1;
Update(a[1], 1);
for(int i = 2; i <= n; i++) {
if(a[i] > cur_high) {
cnt_high = 1;
}
else if(a[i] == cur_high) {
cnt_high++;
}
if(a[i] < cur_low) {
cnt_low = 1;
}
else if(a[i] == cur_low) {
cnt_low++;
}
cur_low = min(cur_low, a[i]);
cur_high = max(cur_high, a[i]);
Update(a[i], 1);
if(a[i - 1] > a[i]) {
ans++; //has to be a breaking point
cur_low = a[i];
cur_high = a[i];
cnt_low = 1;
cnt_high = 1;
prev = i;
}
else {
if(cur_high - cur_low >= 2) { //possible here only
int should_be = i - prev + 1;
should_be -= (cnt_high + cnt_low);
int real = Query(cur_high - 1) - Query(cur_low);
//cout << "should_be = " << should_be << ", real = " << real << "\n";
//cout << "prev = " << prev << ", i = " << i << "\n";
//cout << "cnt_low = " << cnt_low << ", cnt_high = " << cnt_high << "\n";
if(real > should_be) {
prev = i;
cnt_low = 1;
cnt_high = 1;
cur_low = a[i];
cur_high = a[i];
ans++;
}
}
}
//cout << "i = " << i << ", ans = " << ans << "\n";
}
cout << ans << "\n";
}
int32_t main() {
auto begin = std::chrono::high_resolution_clock::now();
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
//cin >> t;
while(t--) {
Solve();
}
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
0 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
0 ms |
460 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
460 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
460 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
288 KB |
Output is correct |
25 |
Correct |
1 ms |
588 KB |
Output is correct |
26 |
Correct |
1 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
0 ms |
460 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
460 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
460 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
288 KB |
Output is correct |
25 |
Correct |
1 ms |
588 KB |
Output is correct |
26 |
Correct |
1 ms |
588 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
0 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
0 ms |
332 KB |
Output is correct |
31 |
Correct |
0 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
460 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
460 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
37 |
Correct |
2 ms |
1996 KB |
Output is correct |
38 |
Correct |
1 ms |
1996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
0 ms |
460 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
460 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
460 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
288 KB |
Output is correct |
25 |
Correct |
1 ms |
588 KB |
Output is correct |
26 |
Correct |
1 ms |
588 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
0 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
0 ms |
332 KB |
Output is correct |
31 |
Correct |
0 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
460 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
460 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
37 |
Correct |
2 ms |
1996 KB |
Output is correct |
38 |
Correct |
1 ms |
1996 KB |
Output is correct |
39 |
Correct |
77 ms |
4068 KB |
Output is correct |
40 |
Correct |
115 ms |
7468 KB |
Output is correct |
41 |
Correct |
58 ms |
4224 KB |
Output is correct |
42 |
Correct |
54 ms |
4020 KB |
Output is correct |
43 |
Correct |
38 ms |
3236 KB |
Output is correct |
44 |
Correct |
149 ms |
9020 KB |
Output is correct |
45 |
Correct |
155 ms |
9024 KB |
Output is correct |
46 |
Correct |
158 ms |
9076 KB |
Output is correct |
47 |
Correct |
144 ms |
8952 KB |
Output is correct |
48 |
Correct |
150 ms |
8908 KB |
Output is correct |
49 |
Correct |
185 ms |
16704 KB |
Output is correct |
50 |
Correct |
187 ms |
16720 KB |
Output is correct |
51 |
Correct |
193 ms |
16708 KB |
Output is correct |
52 |
Correct |
188 ms |
16712 KB |
Output is correct |
53 |
Correct |
181 ms |
16704 KB |
Output is correct |
54 |
Correct |
194 ms |
16720 KB |
Output is correct |
55 |
Correct |
225 ms |
16704 KB |
Output is correct |
56 |
Correct |
229 ms |
16716 KB |
Output is correct |
57 |
Correct |
229 ms |
16712 KB |
Output is correct |
58 |
Correct |
224 ms |
16716 KB |
Output is correct |
59 |
Correct |
218 ms |
16712 KB |
Output is correct |
60 |
Correct |
221 ms |
16708 KB |
Output is correct |
61 |
Correct |
228 ms |
16696 KB |
Output is correct |
62 |
Correct |
231 ms |
16700 KB |
Output is correct |