Submission #831709

# Submission time Handle Problem Language Result Execution time Memory
831709 2023-08-20T12:34:48 Z Chal1shkan Money (IZhO17_money) C++14
100 / 100
470 ms 31440 KB
//Bismillahir-Rahmanir-Rahim
 
# include <bits/stdc++.h>
 
# define pb push_back
# define ff first
# define ss second
# define nl "\n"
# define sz(x) ((int)(x).size())
# define all(x) (x).begin(), (x).end()
# define deb(x) cerr << #x  << " = " << x << endl; 
# define pll pair <ll, ll>
# define pii pair <int, int>
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
const ll maxn = 1e6 + 7;
const ll inf = 2e18 + 0;
const ll mod = 1e9 + 7;
const ll dx[] = {-1, 1, 0, 0};
const ll dy[] = {0, 0, -1, 1};
 
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
struct segtree {
	ll t[maxn * 4];
	void update (ll pos, ll x, ll v = 1, ll tl = 1, ll tr = 1000000) {
		if (tl == tr) {
			t[v] += x;
			return;
		}
		ll tm = (tl + tr) >> 1;
		if (pos <= tm) {
			update(pos, x, v * 2, tl, tm);
		}
		else {
			update(pos, x, v * 2 + 1, tm + 1, tr);
		}
		t[v] = t[v * 2] + t[v * 2 + 1];
	}
	ll get (ll l, ll r, ll v = 1, ll tl = 1, ll tr = 1000000) {
		if (tr < l || r < tl) return 0;
		if (l <= tl && tr <= r) return t[v];
		ll tm = (tl + tr) >> 1;
		return get (l, r, v * 2, tl, tm) + get(l, r, v * 2 + 1, tm + 1, tr);
	}
} st;
 
void ma1n (/* SABR */) {
	ll n;
	cin >> n;
	ll a[n + 3];
	for (ll i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	ll ans = 0;
	for (ll i = 1; i <= n; ++i) {
		ll j = i;
		while (1) {
			if (j + 1 > n) break;
			if (a[j] > a[j + 1]) break;
			if (st.get(a[i] + 1, a[j + 1] - 1)) break;
			++j;
		}
		ans++;
		for (ll k = i; k <= j; ++k) st.update(a[k], 1);
		i = j;
	}
	cout << ans << nl;
}
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
//  freopen("file.in", "r", stdin);
//  freopen("file.out", "w", stdout);
    int ttt = 1;
//  cin >> ttt;
    for (int test = 1; test <= ttt; ++test) {
//      cout << "Case " << test << ":" << '\n';
        ma1n();
    }
    return 0;
}
 
// 998batrr | BbIWEJI 3A TObOU!!!
// tourist  | BbIWEJI 3A TObOU!!!
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 464 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 468 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 1 ms 464 KB Output is correct
12 Correct 0 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 0 ms 596 KB Output is correct
16 Correct 0 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 464 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 468 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 1 ms 464 KB Output is correct
12 Correct 0 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 0 ms 596 KB Output is correct
16 Correct 0 ms 596 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 588 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 440 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 388 KB Output is correct
24 Correct 1 ms 464 KB Output is correct
25 Correct 1 ms 720 KB Output is correct
26 Correct 1 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 464 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 468 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 1 ms 464 KB Output is correct
12 Correct 0 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 0 ms 596 KB Output is correct
16 Correct 0 ms 596 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 588 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 440 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 388 KB Output is correct
24 Correct 1 ms 464 KB Output is correct
25 Correct 1 ms 720 KB Output is correct
26 Correct 1 ms 724 KB Output is correct
27 Correct 0 ms 336 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 596 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 2 ms 3284 KB Output is correct
38 Correct 2 ms 3284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 464 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 468 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 1 ms 464 KB Output is correct
12 Correct 0 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 0 ms 596 KB Output is correct
16 Correct 0 ms 596 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 588 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 440 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 388 KB Output is correct
24 Correct 1 ms 464 KB Output is correct
25 Correct 1 ms 720 KB Output is correct
26 Correct 1 ms 724 KB Output is correct
27 Correct 0 ms 336 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 596 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 2 ms 3284 KB Output is correct
38 Correct 2 ms 3284 KB Output is correct
39 Correct 77 ms 7400 KB Output is correct
40 Correct 140 ms 12220 KB Output is correct
41 Correct 70 ms 6104 KB Output is correct
42 Correct 62 ms 5840 KB Output is correct
43 Correct 44 ms 4404 KB Output is correct
44 Correct 171 ms 15184 KB Output is correct
45 Correct 164 ms 15052 KB Output is correct
46 Correct 169 ms 15324 KB Output is correct
47 Correct 155 ms 15104 KB Output is correct
48 Correct 153 ms 15048 KB Output is correct
49 Correct 279 ms 31304 KB Output is correct
50 Correct 339 ms 31440 KB Output is correct
51 Correct 273 ms 31180 KB Output is correct
52 Correct 270 ms 31360 KB Output is correct
53 Correct 268 ms 31284 KB Output is correct
54 Correct 289 ms 31192 KB Output is correct
55 Correct 418 ms 31304 KB Output is correct
56 Correct 438 ms 31320 KB Output is correct
57 Correct 424 ms 31296 KB Output is correct
58 Correct 417 ms 31304 KB Output is correct
59 Correct 357 ms 31304 KB Output is correct
60 Correct 403 ms 31300 KB Output is correct
61 Correct 441 ms 31308 KB Output is correct
62 Correct 470 ms 31296 KB Output is correct