Submission #464459

#TimeUsernameProblemLanguageResultExecution timeMemory
464459TheScrassePo (COCI21_po)C++14
70 / 70
31 ms32500 KiB
#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 timeMemoryGrader output
Fetching results...