# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
156202 |
2019-10-04T11:40:22 Z |
theboatman |
Money (IZhO17_money) |
C++17 |
|
305 ms |
12792 KB |
#include <bits/stdc++.h>
#define y1 theboatman
#define make_struct(args...) {args}
using namespace std;
const int inf = 1e9 + 10;
const int N = 1e6 + 10;
struct tree {
int n;
vector <int> t, f;
void init(int temp) {
n = temp;
t.resize(n);
f.resize(n);
}
void inc(int pos) {
if(f[pos])return;
f[pos] = 1;
for(int i = pos; i <= n; i += i & -i) {
t[i] += 1;
}
}
int get(int pos) {
int res = 0;
for(int i = pos; i > 0; i -= i & -i) {
res += t[i];
}
return res;
}
int get(int l, int r) {
if (l > r) {
return 0;
}
return get(r) - get(l - 1);
}
};
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
int n;
cin >> n;
vector <int> a(n);
for(int i = 0; i < n; i++) {
cin >> a[i];
}
int now = 0, x = 0;
while(now < n && x <= a[now]) {
x = a[now];
now++;
}
tree bank;
bank.init(N);
int l = inf, r = -inf;
for(int i = 0; i < now; i++) {
bank.inc(a[i]);
l = min(l, a[i]);
r = max(r, a[i]);
}
int ans = 0;
for(int i = now; i < n; i++) {
ans++;
if (a[i] >= r) {
int x = 0;
while(i < n && x <= a[i]) {
x = a[i];
l = min(l, a[i]);
r = max(r, a[i]);
bank.inc(x);
i++;
}
i--;
}
else {
vector <int> lazy;
if (a[i] < l) {
int x = 0;
while(i < n && x <= a[i] && a[i] <= l) {
x = a[i];
lazy.push_back(x);
i++;
}
i--;
}
else {
int x = 0;
int les = a[i];
while(i < n && x <= a[i] && a[i] <= r) {
//cout << les << " " << *more << " " << pos << " " << pos1 << " " << i << endl;
if (bank.get(les + 1, a[i] - 1) == 0) {
x = a[i];
lazy.push_back(x);
i++;
}
else {
break;
}
}
i--;
}
for(auto it : lazy) {
bank.inc(it);
l = min(l, it);
r = max(r, it);
}
}
}
cout << ans + 1 << "\n";
return 0;
}
/*
find_by_order(X) k -> элемент, нумерация с нуля
order_of_key(X) кол-во < чем X
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8184 KB |
Output is correct |
2 |
Correct |
11 ms |
8184 KB |
Output is correct |
3 |
Correct |
9 ms |
8184 KB |
Output is correct |
4 |
Correct |
7 ms |
8184 KB |
Output is correct |
5 |
Correct |
9 ms |
8188 KB |
Output is correct |
6 |
Correct |
9 ms |
8184 KB |
Output is correct |
7 |
Correct |
9 ms |
8184 KB |
Output is correct |
8 |
Correct |
9 ms |
8184 KB |
Output is correct |
9 |
Correct |
9 ms |
8184 KB |
Output is correct |
10 |
Correct |
9 ms |
8184 KB |
Output is correct |
11 |
Correct |
9 ms |
8184 KB |
Output is correct |
12 |
Correct |
10 ms |
8184 KB |
Output is correct |
13 |
Correct |
9 ms |
8184 KB |
Output is correct |
14 |
Correct |
9 ms |
8184 KB |
Output is correct |
15 |
Correct |
9 ms |
8184 KB |
Output is correct |
16 |
Correct |
9 ms |
8184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8184 KB |
Output is correct |
2 |
Correct |
11 ms |
8184 KB |
Output is correct |
3 |
Correct |
9 ms |
8184 KB |
Output is correct |
4 |
Correct |
7 ms |
8184 KB |
Output is correct |
5 |
Correct |
9 ms |
8188 KB |
Output is correct |
6 |
Correct |
9 ms |
8184 KB |
Output is correct |
7 |
Correct |
9 ms |
8184 KB |
Output is correct |
8 |
Correct |
9 ms |
8184 KB |
Output is correct |
9 |
Correct |
9 ms |
8184 KB |
Output is correct |
10 |
Correct |
9 ms |
8184 KB |
Output is correct |
11 |
Correct |
9 ms |
8184 KB |
Output is correct |
12 |
Correct |
10 ms |
8184 KB |
Output is correct |
13 |
Correct |
9 ms |
8184 KB |
Output is correct |
14 |
Correct |
9 ms |
8184 KB |
Output is correct |
15 |
Correct |
9 ms |
8184 KB |
Output is correct |
16 |
Correct |
9 ms |
8184 KB |
Output is correct |
17 |
Correct |
9 ms |
8184 KB |
Output is correct |
18 |
Correct |
10 ms |
8184 KB |
Output is correct |
19 |
Correct |
9 ms |
8184 KB |
Output is correct |
20 |
Correct |
9 ms |
8184 KB |
Output is correct |
21 |
Correct |
9 ms |
8184 KB |
Output is correct |
22 |
Correct |
9 ms |
8184 KB |
Output is correct |
23 |
Correct |
9 ms |
8184 KB |
Output is correct |
24 |
Correct |
9 ms |
8184 KB |
Output is correct |
25 |
Correct |
9 ms |
8184 KB |
Output is correct |
26 |
Correct |
9 ms |
8184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8184 KB |
Output is correct |
2 |
Correct |
11 ms |
8184 KB |
Output is correct |
3 |
Correct |
9 ms |
8184 KB |
Output is correct |
4 |
Correct |
7 ms |
8184 KB |
Output is correct |
5 |
Correct |
9 ms |
8188 KB |
Output is correct |
6 |
Correct |
9 ms |
8184 KB |
Output is correct |
7 |
Correct |
9 ms |
8184 KB |
Output is correct |
8 |
Correct |
9 ms |
8184 KB |
Output is correct |
9 |
Correct |
9 ms |
8184 KB |
Output is correct |
10 |
Correct |
9 ms |
8184 KB |
Output is correct |
11 |
Correct |
9 ms |
8184 KB |
Output is correct |
12 |
Correct |
10 ms |
8184 KB |
Output is correct |
13 |
Correct |
9 ms |
8184 KB |
Output is correct |
14 |
Correct |
9 ms |
8184 KB |
Output is correct |
15 |
Correct |
9 ms |
8184 KB |
Output is correct |
16 |
Correct |
9 ms |
8184 KB |
Output is correct |
17 |
Correct |
9 ms |
8184 KB |
Output is correct |
18 |
Correct |
10 ms |
8184 KB |
Output is correct |
19 |
Correct |
9 ms |
8184 KB |
Output is correct |
20 |
Correct |
9 ms |
8184 KB |
Output is correct |
21 |
Correct |
9 ms |
8184 KB |
Output is correct |
22 |
Correct |
9 ms |
8184 KB |
Output is correct |
23 |
Correct |
9 ms |
8184 KB |
Output is correct |
24 |
Correct |
9 ms |
8184 KB |
Output is correct |
25 |
Correct |
9 ms |
8184 KB |
Output is correct |
26 |
Correct |
9 ms |
8184 KB |
Output is correct |
27 |
Correct |
9 ms |
8184 KB |
Output is correct |
28 |
Correct |
9 ms |
8188 KB |
Output is correct |
29 |
Correct |
9 ms |
8184 KB |
Output is correct |
30 |
Correct |
9 ms |
8184 KB |
Output is correct |
31 |
Correct |
9 ms |
8228 KB |
Output is correct |
32 |
Correct |
9 ms |
8228 KB |
Output is correct |
33 |
Correct |
8 ms |
8184 KB |
Output is correct |
34 |
Correct |
9 ms |
8184 KB |
Output is correct |
35 |
Correct |
9 ms |
8184 KB |
Output is correct |
36 |
Correct |
9 ms |
8184 KB |
Output is correct |
37 |
Correct |
9 ms |
8184 KB |
Output is correct |
38 |
Correct |
10 ms |
8184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8184 KB |
Output is correct |
2 |
Correct |
11 ms |
8184 KB |
Output is correct |
3 |
Correct |
9 ms |
8184 KB |
Output is correct |
4 |
Correct |
7 ms |
8184 KB |
Output is correct |
5 |
Correct |
9 ms |
8188 KB |
Output is correct |
6 |
Correct |
9 ms |
8184 KB |
Output is correct |
7 |
Correct |
9 ms |
8184 KB |
Output is correct |
8 |
Correct |
9 ms |
8184 KB |
Output is correct |
9 |
Correct |
9 ms |
8184 KB |
Output is correct |
10 |
Correct |
9 ms |
8184 KB |
Output is correct |
11 |
Correct |
9 ms |
8184 KB |
Output is correct |
12 |
Correct |
10 ms |
8184 KB |
Output is correct |
13 |
Correct |
9 ms |
8184 KB |
Output is correct |
14 |
Correct |
9 ms |
8184 KB |
Output is correct |
15 |
Correct |
9 ms |
8184 KB |
Output is correct |
16 |
Correct |
9 ms |
8184 KB |
Output is correct |
17 |
Correct |
9 ms |
8184 KB |
Output is correct |
18 |
Correct |
10 ms |
8184 KB |
Output is correct |
19 |
Correct |
9 ms |
8184 KB |
Output is correct |
20 |
Correct |
9 ms |
8184 KB |
Output is correct |
21 |
Correct |
9 ms |
8184 KB |
Output is correct |
22 |
Correct |
9 ms |
8184 KB |
Output is correct |
23 |
Correct |
9 ms |
8184 KB |
Output is correct |
24 |
Correct |
9 ms |
8184 KB |
Output is correct |
25 |
Correct |
9 ms |
8184 KB |
Output is correct |
26 |
Correct |
9 ms |
8184 KB |
Output is correct |
27 |
Correct |
9 ms |
8184 KB |
Output is correct |
28 |
Correct |
9 ms |
8188 KB |
Output is correct |
29 |
Correct |
9 ms |
8184 KB |
Output is correct |
30 |
Correct |
9 ms |
8184 KB |
Output is correct |
31 |
Correct |
9 ms |
8228 KB |
Output is correct |
32 |
Correct |
9 ms |
8228 KB |
Output is correct |
33 |
Correct |
8 ms |
8184 KB |
Output is correct |
34 |
Correct |
9 ms |
8184 KB |
Output is correct |
35 |
Correct |
9 ms |
8184 KB |
Output is correct |
36 |
Correct |
9 ms |
8184 KB |
Output is correct |
37 |
Correct |
9 ms |
8184 KB |
Output is correct |
38 |
Correct |
10 ms |
8184 KB |
Output is correct |
39 |
Correct |
95 ms |
10112 KB |
Output is correct |
40 |
Correct |
152 ms |
11212 KB |
Output is correct |
41 |
Correct |
77 ms |
9692 KB |
Output is correct |
42 |
Correct |
72 ms |
9592 KB |
Output is correct |
43 |
Correct |
53 ms |
9080 KB |
Output is correct |
44 |
Correct |
187 ms |
12124 KB |
Output is correct |
45 |
Correct |
189 ms |
12024 KB |
Output is correct |
46 |
Correct |
186 ms |
12248 KB |
Output is correct |
47 |
Correct |
178 ms |
12148 KB |
Output is correct |
48 |
Correct |
172 ms |
12024 KB |
Output is correct |
49 |
Correct |
246 ms |
12144 KB |
Output is correct |
50 |
Correct |
246 ms |
12124 KB |
Output is correct |
51 |
Correct |
246 ms |
12152 KB |
Output is correct |
52 |
Correct |
236 ms |
12248 KB |
Output is correct |
53 |
Correct |
237 ms |
12176 KB |
Output is correct |
54 |
Correct |
239 ms |
12152 KB |
Output is correct |
55 |
Correct |
290 ms |
12152 KB |
Output is correct |
56 |
Correct |
289 ms |
12664 KB |
Output is correct |
57 |
Correct |
298 ms |
12628 KB |
Output is correct |
58 |
Correct |
305 ms |
12628 KB |
Output is correct |
59 |
Correct |
291 ms |
12624 KB |
Output is correct |
60 |
Correct |
284 ms |
12536 KB |
Output is correct |
61 |
Correct |
282 ms |
12664 KB |
Output is correct |
62 |
Correct |
284 ms |
12792 KB |
Output is correct |