# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
480139 | lukameladze | Po (COCI21_po) | C++14 | 20 ms | 7380 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.
# include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
using namespace std;
const int N = 1e5 + 5;
int n,a[N],ff,nxt,ans,cur,le,sf[N];
vector <int> v[N];
set <int > s;
signed main() {
std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>n;
for (int i = 1; i <= n ;i++) {
cin>>a[i];
}
for (int i = n; i >= 1; i --) {
cur = i + 1;
while (cur != n + 1 && a[cur] >= a[i]) {
cur = sf[cur];
}
sf[i] = cur;
}
cur = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < v[i].size(); j++) {
cur -= v[i][j];
}
a[i] -= cur;
if (a[i]) ans++;
nxt = sf[i];
cur += a[i];
v[nxt].pb(a[i]);
}
cout<<ans<<endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |