# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
464459 |
2021-08-13T08:54:12 Z |
TheScrasse |
Po (COCI21_po) |
C++14 |
|
31 ms |
32500 KB |
#include <bits/stdc++.h>
using namespace std;
#define nl "\n"
#define nf endl
#define ll long long
#define pb push_back
#define _ << ' ' <<
#define INF (ll)1e18
#define mod 998244353
#define maxn 100010
ll i, i1, j, k, k1, t, n, m, res, flag[10], a[maxn], b, p2[maxn];
array<ll, 2> st[20][maxn];
array<ll, 2> rmq(ll l, ll r) {
ll k = p2[r - l + 1];
return min(st[k][l], st[k][r - (1 << k) + 1]);
}
void solve(ll l, ll r, ll d) {
// cout << "solve " << l _ r _ d << nl;
if (l > r) return;
array<ll, 2> o = rmq(l, r);
if (o[0] != d) res++;
solve(l, o[1] - 1, o[0]);
solve(o[1] + 1, r, o[0]);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
/* #if !ONLINE_JUDGE && !EVAL
ifstream cin("input.txt");
ofstream cout("output.txt");
#endif */
cin >> n;
for (i = 1; i <= n; i++) {
cin >> a[i];
}
for (j = 1; j <= n; j++) st[0][j] = {a[j], j};
for (i = 1; i <= 20; i++) {
k = (1 << (i - 1));
for (j = 1; j <= n - k; j++) {
st[i][j] = min(st[i - 1][j], st[i - 1][j + k]);
}
}
p2[1] = 0;
for (i = 2; i <= n; i++) p2[i] = p2[i / 2] + 1;
solve(1, n, 0);
cout << res << nl;
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 |
460 KB |
Output is correct |
4 |
Correct |
14 ms |
13588 KB |
Output is correct |
5 |
Correct |
21 ms |
20816 KB |
Output is correct |
6 |
Correct |
30 ms |
31344 KB |
Output is correct |
7 |
Correct |
31 ms |
32500 KB |
Output is correct |