# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
375143 | vonatlus | Po (COCI21_po) | C++17 | 1100 ms | 8940 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/// vonat1us
#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:36777216")
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define sz(x) (int) x.size()
#define all(z) (z).begin(), (z).end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 1e2;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void fin() {
#ifdef AM
freopen(".in", "r", stdin);
#endif
}
const bool flag = 0;
const int N = 1e5+10;
const int K = 18;
int a[N], dp[K][N], lg[N];
int get(int l, int r) {
int k = lg[r-l+1];
return min(dp[k][l], dp[k][r-(1<<k)+1]);
}
int f(int l, int r) {
if (l > r) return 0;
int mn = get(l, r);
int res = (mn != 0 ? 1 : 0);
for (int i = l; i <= r; ++i) {
if (a[i] == mn) continue;
int j = i;
while (j <= r && a[j] != mn) {
j++;
}
res += f(i, j-1);
i = j-1;
}
return res;
}
void ma1n() {
int n;
cin >> n;
for (int i = 2; i <= n; ++i) lg[i] = lg[i>>1]+1;
for (int i = 0; i < n; ++i) cin >> a[i], dp[0][i] = a[i];
for (int j = 1; j < K; ++j) {
int k = (1<<(j-1));
for (int i = 0; i < n-k; ++i) {
dp[j][i] = min(dp[j-1][i], dp[j-1][i+k]);
}
}
cout << f(0, n-1);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(nullptr), fin();
int ts = 1;
if (flag) {
cin >> ts;
}
while (ts--) {
ma1n();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |