# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
873101 |
2023-11-14T12:57:12 Z |
c2zi6 |
Money (IZhO17_money) |
C++14 |
|
405 ms |
23428 KB |
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
struct SEGTREE {
int n;
VI tree;
int _get(int N, int L, int R, int l, int r) {
if (R < l || L > r) return 0;
if (l <= L && R <= r) return tree[N];
int M = (L + R) / 2;
return _get(2*N+1, L, M, l, r) + _get(2*N+2, M+1, R, l, r);
}
int _upd(int N, int L, int R, int i) {
if (i < L || i > R) return tree[N];
if (L == R) return ++tree[N];
int M = (L + R) / 2;
return tree[N] = _upd(2*N+1, L, M, i) + _upd(2*N+2, M+1, R, i);
}
int get(int l, int r) {
return _get(0, 0, n-1, l, r);
}
void upd(int i) {
_upd(0, 0, n-1, i);
}
SEGTREE(int sz) {
n = 1;
while (n < sz) n *= 2;
tree = VI(2*n);
}
};
int solve(VI a) {
int n = a.size();
SEGTREE ka(1e6+1);
int ans = 1;
ka.upd(a[0]);
int s = 0;
for (int i = 1; i < n; i++) {
if (a[i] < a[i-1]) {
ans++;
for (int j = s; j < i; j++) ka.upd(a[j]);
s = i;
} else {
int l = a[s]+1;
int r = a[i]-1;
if (l <= r && ka.get(l, r)) {
/* replr(j, a[s]+1, a[i]-1) fl |= ka[j]; */
/* if (fl) { */
ans++;
for (int j = s; j < i; j++) ka.upd(a[j]);
s = i;
}
}
}
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
/* SEGTREE seg(10); */
/* VI test(10); */
/* while (true) { */
/* char ch; */
/* cin >> ch; */
/* if (ch == '?') { */
/* int l, r; */
/* cin >> l >> r; */
/* l--, r--; */
/* cout << seg.get(l, r) << endl; */
/* } else { */
/* int i; */
/* cin >> i; */
/* i--; */
/* seg.upd(i); */
/* test[i]++; */
/* } */
/* for (int x : test) cout << x << " "; cout << endl; */
/* } */
int n;
cin >> n;
VI a(n);
for (int& x : a) cin >> x;
int ans = solve(a);
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8536 KB |
Output is correct |
2 |
Correct |
2 ms |
8792 KB |
Output is correct |
3 |
Correct |
2 ms |
8540 KB |
Output is correct |
4 |
Correct |
2 ms |
8540 KB |
Output is correct |
5 |
Correct |
2 ms |
8540 KB |
Output is correct |
6 |
Correct |
2 ms |
8540 KB |
Output is correct |
7 |
Correct |
4 ms |
8536 KB |
Output is correct |
8 |
Correct |
2 ms |
8540 KB |
Output is correct |
9 |
Correct |
3 ms |
8540 KB |
Output is correct |
10 |
Correct |
2 ms |
8540 KB |
Output is correct |
11 |
Correct |
2 ms |
8540 KB |
Output is correct |
12 |
Correct |
2 ms |
8540 KB |
Output is correct |
13 |
Correct |
2 ms |
8540 KB |
Output is correct |
14 |
Correct |
2 ms |
8644 KB |
Output is correct |
15 |
Correct |
3 ms |
8540 KB |
Output is correct |
16 |
Correct |
2 ms |
8540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8536 KB |
Output is correct |
2 |
Correct |
2 ms |
8792 KB |
Output is correct |
3 |
Correct |
2 ms |
8540 KB |
Output is correct |
4 |
Correct |
2 ms |
8540 KB |
Output is correct |
5 |
Correct |
2 ms |
8540 KB |
Output is correct |
6 |
Correct |
2 ms |
8540 KB |
Output is correct |
7 |
Correct |
4 ms |
8536 KB |
Output is correct |
8 |
Correct |
2 ms |
8540 KB |
Output is correct |
9 |
Correct |
3 ms |
8540 KB |
Output is correct |
10 |
Correct |
2 ms |
8540 KB |
Output is correct |
11 |
Correct |
2 ms |
8540 KB |
Output is correct |
12 |
Correct |
2 ms |
8540 KB |
Output is correct |
13 |
Correct |
2 ms |
8540 KB |
Output is correct |
14 |
Correct |
2 ms |
8644 KB |
Output is correct |
15 |
Correct |
3 ms |
8540 KB |
Output is correct |
16 |
Correct |
2 ms |
8540 KB |
Output is correct |
17 |
Correct |
2 ms |
8540 KB |
Output is correct |
18 |
Correct |
2 ms |
8536 KB |
Output is correct |
19 |
Correct |
2 ms |
8540 KB |
Output is correct |
20 |
Correct |
2 ms |
8540 KB |
Output is correct |
21 |
Correct |
2 ms |
8540 KB |
Output is correct |
22 |
Correct |
2 ms |
8540 KB |
Output is correct |
23 |
Correct |
2 ms |
8540 KB |
Output is correct |
24 |
Correct |
2 ms |
8540 KB |
Output is correct |
25 |
Correct |
2 ms |
8540 KB |
Output is correct |
26 |
Correct |
2 ms |
8608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8536 KB |
Output is correct |
2 |
Correct |
2 ms |
8792 KB |
Output is correct |
3 |
Correct |
2 ms |
8540 KB |
Output is correct |
4 |
Correct |
2 ms |
8540 KB |
Output is correct |
5 |
Correct |
2 ms |
8540 KB |
Output is correct |
6 |
Correct |
2 ms |
8540 KB |
Output is correct |
7 |
Correct |
4 ms |
8536 KB |
Output is correct |
8 |
Correct |
2 ms |
8540 KB |
Output is correct |
9 |
Correct |
3 ms |
8540 KB |
Output is correct |
10 |
Correct |
2 ms |
8540 KB |
Output is correct |
11 |
Correct |
2 ms |
8540 KB |
Output is correct |
12 |
Correct |
2 ms |
8540 KB |
Output is correct |
13 |
Correct |
2 ms |
8540 KB |
Output is correct |
14 |
Correct |
2 ms |
8644 KB |
Output is correct |
15 |
Correct |
3 ms |
8540 KB |
Output is correct |
16 |
Correct |
2 ms |
8540 KB |
Output is correct |
17 |
Correct |
2 ms |
8540 KB |
Output is correct |
18 |
Correct |
2 ms |
8536 KB |
Output is correct |
19 |
Correct |
2 ms |
8540 KB |
Output is correct |
20 |
Correct |
2 ms |
8540 KB |
Output is correct |
21 |
Correct |
2 ms |
8540 KB |
Output is correct |
22 |
Correct |
2 ms |
8540 KB |
Output is correct |
23 |
Correct |
2 ms |
8540 KB |
Output is correct |
24 |
Correct |
2 ms |
8540 KB |
Output is correct |
25 |
Correct |
2 ms |
8540 KB |
Output is correct |
26 |
Correct |
2 ms |
8608 KB |
Output is correct |
27 |
Correct |
2 ms |
8536 KB |
Output is correct |
28 |
Correct |
2 ms |
8540 KB |
Output is correct |
29 |
Correct |
2 ms |
8540 KB |
Output is correct |
30 |
Correct |
2 ms |
8536 KB |
Output is correct |
31 |
Correct |
2 ms |
8540 KB |
Output is correct |
32 |
Correct |
2 ms |
8540 KB |
Output is correct |
33 |
Correct |
2 ms |
8540 KB |
Output is correct |
34 |
Correct |
2 ms |
8796 KB |
Output is correct |
35 |
Correct |
2 ms |
8540 KB |
Output is correct |
36 |
Correct |
2 ms |
8540 KB |
Output is correct |
37 |
Correct |
3 ms |
8644 KB |
Output is correct |
38 |
Correct |
2 ms |
8536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8536 KB |
Output is correct |
2 |
Correct |
2 ms |
8792 KB |
Output is correct |
3 |
Correct |
2 ms |
8540 KB |
Output is correct |
4 |
Correct |
2 ms |
8540 KB |
Output is correct |
5 |
Correct |
2 ms |
8540 KB |
Output is correct |
6 |
Correct |
2 ms |
8540 KB |
Output is correct |
7 |
Correct |
4 ms |
8536 KB |
Output is correct |
8 |
Correct |
2 ms |
8540 KB |
Output is correct |
9 |
Correct |
3 ms |
8540 KB |
Output is correct |
10 |
Correct |
2 ms |
8540 KB |
Output is correct |
11 |
Correct |
2 ms |
8540 KB |
Output is correct |
12 |
Correct |
2 ms |
8540 KB |
Output is correct |
13 |
Correct |
2 ms |
8540 KB |
Output is correct |
14 |
Correct |
2 ms |
8644 KB |
Output is correct |
15 |
Correct |
3 ms |
8540 KB |
Output is correct |
16 |
Correct |
2 ms |
8540 KB |
Output is correct |
17 |
Correct |
2 ms |
8540 KB |
Output is correct |
18 |
Correct |
2 ms |
8536 KB |
Output is correct |
19 |
Correct |
2 ms |
8540 KB |
Output is correct |
20 |
Correct |
2 ms |
8540 KB |
Output is correct |
21 |
Correct |
2 ms |
8540 KB |
Output is correct |
22 |
Correct |
2 ms |
8540 KB |
Output is correct |
23 |
Correct |
2 ms |
8540 KB |
Output is correct |
24 |
Correct |
2 ms |
8540 KB |
Output is correct |
25 |
Correct |
2 ms |
8540 KB |
Output is correct |
26 |
Correct |
2 ms |
8608 KB |
Output is correct |
27 |
Correct |
2 ms |
8536 KB |
Output is correct |
28 |
Correct |
2 ms |
8540 KB |
Output is correct |
29 |
Correct |
2 ms |
8540 KB |
Output is correct |
30 |
Correct |
2 ms |
8536 KB |
Output is correct |
31 |
Correct |
2 ms |
8540 KB |
Output is correct |
32 |
Correct |
2 ms |
8540 KB |
Output is correct |
33 |
Correct |
2 ms |
8540 KB |
Output is correct |
34 |
Correct |
2 ms |
8796 KB |
Output is correct |
35 |
Correct |
2 ms |
8540 KB |
Output is correct |
36 |
Correct |
2 ms |
8540 KB |
Output is correct |
37 |
Correct |
3 ms |
8644 KB |
Output is correct |
38 |
Correct |
2 ms |
8536 KB |
Output is correct |
39 |
Correct |
115 ms |
15492 KB |
Output is correct |
40 |
Correct |
178 ms |
20052 KB |
Output is correct |
41 |
Correct |
94 ms |
14420 KB |
Output is correct |
42 |
Correct |
80 ms |
13672 KB |
Output is correct |
43 |
Correct |
62 ms |
12212 KB |
Output is correct |
44 |
Correct |
236 ms |
23032 KB |
Output is correct |
45 |
Correct |
220 ms |
23380 KB |
Output is correct |
46 |
Correct |
222 ms |
23120 KB |
Output is correct |
47 |
Correct |
209 ms |
23156 KB |
Output is correct |
48 |
Correct |
221 ms |
23304 KB |
Output is correct |
49 |
Correct |
294 ms |
23120 KB |
Output is correct |
50 |
Correct |
308 ms |
23412 KB |
Output is correct |
51 |
Correct |
299 ms |
23172 KB |
Output is correct |
52 |
Correct |
349 ms |
23268 KB |
Output is correct |
53 |
Correct |
297 ms |
23120 KB |
Output is correct |
54 |
Correct |
318 ms |
23112 KB |
Output is correct |
55 |
Correct |
368 ms |
23376 KB |
Output is correct |
56 |
Correct |
388 ms |
23428 KB |
Output is correct |
57 |
Correct |
397 ms |
23028 KB |
Output is correct |
58 |
Correct |
385 ms |
23220 KB |
Output is correct |
59 |
Correct |
405 ms |
23176 KB |
Output is correct |
60 |
Correct |
388 ms |
23304 KB |
Output is correct |
61 |
Correct |
405 ms |
23220 KB |
Output is correct |
62 |
Correct |
388 ms |
23212 KB |
Output is correct |