# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
375165 |
2021-03-09T03:54:22 Z |
SeDunion |
Po (COCI21_po) |
C++17 |
|
26 ms |
21356 KB |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 66;
const int LOG = 20;
pair<int,int> sp[LOG][N];
int lg[N];
pair<int,int> mn(int l, int r) {
int j = lg[r - l];
return min(sp[j][l], sp[j][r - (1 << j)]);
}
int solve(int l, int r, int h = 0) {
if (l >= r) return 0;
auto [val, i] = mn(l, r);
return solve(l, i, val) + solve(i + 1, r, val) + (val != h);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
lg[1] = 0; for (int i = 2 ; i < N ; ++ i) lg[i] = lg[i>>1] + 1;
int n;
cin >> n;
for (int i = 0 ; i < n ; ++ i) {
cin >> sp[0][i].first; sp[0][i].second = i;
}
for (int j = 1 ; j < LOG ; ++ j) {
for (int i = 0 ; i + (1 << j) <= n ; ++ i) {
sp[j][i] = min(sp[j - 1][i], sp[j - 1][i + (1 << (j - 1))]);
}
}
cout << solve(0, n);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4204 KB |
Output is correct |
2 |
Correct |
3 ms |
4332 KB |
Output is correct |
3 |
Correct |
4 ms |
4332 KB |
Output is correct |
4 |
Correct |
12 ms |
10220 KB |
Output is correct |
5 |
Correct |
19 ms |
13420 KB |
Output is correct |
6 |
Correct |
26 ms |
21356 KB |
Output is correct |
7 |
Correct |
25 ms |
20204 KB |
Output is correct |