This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using flt=double;
int main() {
ios::sync_with_stdio(0);cin.tie(0);
int N, K;
cin>>N>>K;
flt l=0, r=2;
vector<int> C(N+1), P(N+1);
cout<<fixed<<setprecision(9);
auto f=[&](flt m) {
vector<double> D(N+1);
vector<int> T(1<<32-__builtin_clz(N));
auto f=[&](int j, int i) {
return D[j]+flt(i-j)/i;
};
auto cmp=[&](int i, int j, int x) {
return f(i, x)>f(j, x);
};
auto add=[&](int a) {
int s=1, e=N, i=1;
while(i) {
int m=s+e>>1, &b=T[i];
if(cmp(a, b, m)) swap(a, b);
if(cmp(a, b, s)) e=m-1, i=i*2;
else if(cmp(a, b, e)) s=m+1, i=i*2+1;
else break;
}
};
auto get=[&](int x) {
int s=1, e=N, i=1, a=0;
while(i) {
int m=s+e>>1, b=T[i];
if(cmp(b, a, x)) a=b;
if(x<m) e=m-1, i=i*2;
else if(x>m) s=m+1, i=i*2+1;
else break;
}
return a;
};
D[0]=0;
for(int i=1; i<=N; i++) {
add(i-1);
int p=get(i);
P[i]=p;
C[i]=C[p]+1;
D[i]=f(p, i)-m;
}
return make_pair(C[N], D[N]+K*m);
};
while(r-l>1e-9) {
flt m=(l+r)/2;
auto[k,x]=f(m);
if(k<K) r=m;
else if(k>K) l=m;
else { l=r=m; break; }
}
cout<<fixed<<setprecision(9)<<f((l+r)/2).second;
}
Compilation message (stderr)
akvizna.cpp: In lambda function:
akvizna.cpp:15:22: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
15 | vector<int> T(1<<32-__builtin_clz(N));
| ~~^~~~~~~~~~~~~~~~~
akvizna.cpp: In lambda function:
akvizna.cpp:25:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
25 | int m=s+e>>1, &b=T[i];
| ~^~
akvizna.cpp: In lambda function:
akvizna.cpp:35:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
35 | int m=s+e>>1, b=T[i];
| ~^~
# | 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... |
# | 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... |
# | 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... |
# | 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... |
# | 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... |
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |