# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
50306 | mra2322001 | Money (IZhO17_money) | C++14 | 1592 ms | 113396 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 f0(i, n) for(int i(0); i<(n); i++)
#define f1(i, n) for(int i(1); i<=(n); i++)
using namespace std;
typedef long long ll;
const int N = 1e6 + 5;
int n, a[N], f[N];
set <int> s;
int solve(int u, int sl){
if(u== n + 1) return printf("%d", sl), 0;
int v = f[u];
int l = u, r = v, ans = u;
auto it = s.upper_bound(a[u]);
while(l <= r){
int mid = (l + r)/2;
if(a[mid] <= *it) l = mid + 1, ans = mid;
else r = mid - 1;
}
for(int i = u; i <= ans; i++) s.insert(a[i]);
solve(ans + 1, sl + 1);
}
int main(){
ios_base::sync_with_stdio(0);
scanf("%d", &n);
f1(i, n) scanf("%d", &a[i]);
for(int i = n; i >= 1; i--){
if(i==n) f[i] = n;
else{
if(a[i] <= a[i + 1]) f[i] = f[i + 1];
else f[i] = i;
}
}
s.insert(0); s.insert(1e6 + 5);
solve(1, 0);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |