# AtCoder Beginner Contest 194 D-E

Journey

#include<iostream>
#include<cstdio>
using namespace std;

#define ll long long
const int MAX_N = 100025;
double dp[MAX_N];

int main()
{
int n;
scanf("%d",&n);
dp[n] = 0;
for(int i = n-1;i>=0;--i)
{
dp[i] = dp[i+1] + ((1.0*(n)/(n-i)));
}
printf("%.6f\n",dp[0]-1);
}



Mex Min

#include<cstdio>
#include<iostream>
using namespace std;
const int MAX_N = 2000005;

#define dbg(x) cout << #x << " = " << (x) << endl;
#define dbg2(x,y) cout << #x << " = " << (x) << " " << #y << " = " << (y) << endl;
#define dbg3(x,y,z) cout << #x << " = " << (x) << " " << #y << " = " << (y) << " " << #z << " = " << (z) << endl;

int arr[MAX_N],cnt[MAX_N],S[MAX_N<<1];

void add(int x,int v)
{
for(;x<MAX_N;x+=x&(-x))
{
S[x]+=v;
}
}

int get(int x)
{
int sum = 0;
for(;x;x-=x&(-x))
{
sum+=S[x];
}
return sum;
}

int main()
{

int n,m;
scanf("%d%d",&n,&m);
for(int i = 1;i<=n;++i)
{
scanf("%d",&arr[i]);
arr[i]++;
}
int minn = 0x3f3f3f3f;
for(int i = 1;i<=n;++i)
{
cnt[arr[i]]++;
if(i>=m)
{
if(i>m) cnt[arr[i-m]]--;
int l = 1,r = n+1;
while(l<=r)
{
if(get(1)!=1)
{
r = 1;
break;
}
int mid = l + r >> 1;
if(get(mid)==mid) l = mid + 1;
else r = mid - 1;
}
if(get(r)==r) r++;
minn = min(minn,r);
}
}
printf("%d\n",minn-1);
return 0;
}



03-10 268
04-13 31
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客