Dwango Programming Contest V 翻车记

时间:2021-10-28 15:11:02

  A:签到。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 110
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<''||c>'')) c=getchar();return c;}
int gcd(int n,int m){return m==?n:gcd(m,n%m);}
int read()
{
int x=,f=;char c=getchar();
while (c<''||c>'') {if (c=='-') f=-;c=getchar();}
while (c>=''&&c<='') x=(x<<)+(x<<)+(c^),c=getchar();
return x*f;
}
int n,a[N],s,ans=;
int calc(int k){return abs(s-a[k]*n);}
int main()
{
/*#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
const char LL[]="%I64d\n";
#else
const char LL[]="%lld\n";
#endif*/
n=read();
for (int i=;i<=n;i++) s+=a[i]=read();
for (int i=;i<=n;i++)
if (calc(i)<calc(ans+)) ans=i-;
cout<<ans;
return ;
}

  B:按位从高到低贪心,对当前位数一下有多少个子区间和该位为1,如果能满足要求就将其统计入答案并删掉所有该位为0的子区间和。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 1010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<''||c>'')) c=getchar();return c;}
int gcd(int n,int m){return m==?n:gcd(m,n%m);}
int read()
{
int x=,f=;char c=getchar();
while (c<''||c>'') {if (c=='-') f=-;c=getchar();}
while (c>=''&&c<='') x=(x<<)+(x<<)+(c^),c=getchar();
return x*f;
}
int n,m,b[N],cnt=;
ll a[N*N],c[N*N],ans;
int main()
{
/*#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
const char LL[]="%I64d\n";
#else
const char LL[]="%lld\n";
#endif*/
n=read(),m=read();
for (int i=;i<=n;i++) b[i]=read();
for (int i=;i<=n;i++)
{
a[++cnt]=b[i];
for (int j=i+;j<=n;j++)
cnt++,a[cnt]=a[cnt-]+b[j];
}
n=cnt;
for (int j=;~j;j--)
{
int s=;
for (int i=;i<=n;i++)
if (a[i]&(1ll<<j)) c[++s]=a[i];
if (s>=m)
{
ans+=1ll<<j;n=s;
for (int i=;i<=s;i++) a[i]=c[i];
}
}
cout<<ans;
return ;
}

  C:指针从左到右扫一遍,两个队列分别维护指针左方D的出现位置和右方C的出现位置,并记录跨过当前位置的合法D~C区间有多少个。如果指针扫到M就更新答案,扫到D将其加入左边队列并统计以该位置为左端点的合法D~C区间数量,扫到C将其弹出右边队列并统计以该位置为右端点的合法D~C区间数量,拿两个指针记录两个队列中能产生贡献的边界位置即可做到线性。为啥atcoder不define ONLINE_JUDGE啊白交了一发。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 1000010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<''||c>'')) c=getchar();return c;}
int gcd(int n,int m){return m==?n:gcd(m,n%m);}
int read()
{
int x=,f=;char c=getchar();
while (c<''||c>'') {if (c=='-') f=-;c=getchar();}
while (c>=''&&c<='') x=(x<<)+(x<<)+(c^),c=getchar();
return x*f;
}
int n,q,m,a[N],b[N],c[N];
char s[N];
int main()
{
n=read();scanf("%s",s+);
for (int i=;i<=n;i++)
if (s[i]=='D') a[i]=;
else if (s[i]=='M') a[i]=;
else if (s[i]=='C') a[i]=;
else a[i]=-;
q=read();
while (q--)
{
m=read();
int hb=,tb=,hc=,t=,tc=;ll ans=,cur=;
for (int i=;i<=n;i++) if (a[i]==) b[++tb]=i;
for (int i=;i<=n;i++)
if (a[i]==) ans+=cur;
else if (a[i]==)
{
c[++tc]=i;
while (t<tb&&b[t+]-i+<=m) t++;
cur+=t-hb+;
}
else if (a[i]==)
{
while (hc<=tc&&i-c[hc]+>m) hc++;
cur-=tc-hc+;
hb++;
}
cout<<ans<<endl;
}
return ;
}

  D:可以发现每个点最终可以被移动到该剩余类的任意位置。那么数一下每个剩余类有多少个点。这些点最后应该排成a*(a-1)的长方形或a*a的正方形。可以枚举最终矩形左下角坐标并二分边长check一发,这样就能拿到部分分了。然后好像还不太会。

  E:没看。

  感觉atcoder赛制不是非常友好啊。result:rank 185 rating +352