A:显然对于起点相同的糖果,应该按终点距离从大到小运。排个序对每个起点取max即可。读题花了一年还wa一发,自闭了。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 20010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,m;
int dis(int x,int y)
{
if (x<=y) return y-x;
else return n-x+y;
}
struct data
{
int x,y;
bool operator <(const data&a) const
{
return x<a.x||x==a.x&&dis(x,y)>dis(a.x,a.y);
}
}a[N<<1];
signed main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
n=read(),m=read();
for (int i=1;i<=m;i++) a[i].x=read(),a[i].y=read();
sort(a+1,a+m+1);
for (int i=1;i<=n;i++)
{
int ans=0;
for (int j=1;j<=m;j++)
{
int t=j;
while (t<m&&a[t+1].x==a[j].x) t++;
ans=max(ans,dis(i,a[t].x)+dis(a[t].x,a[t].y)+(t-j)*n);
j=t;
}
printf("%d ",ans);
}
return 0;
//NOTICE LONG LONG!!!!!
}

  B:考虑构造一个长度为n=2000的序列,前1998项都是0,第1999项是负数,第2000项是正数。设1999项绝对值为y,2000项绝对值为x,则要求n*(x-y)-k=x,也即(n-1)x=k+ny。注意到n和n-1互质,所以y取遍0~n-1后一定能找到一个整数x,其作为答案即可。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 20010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n;
signed main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
n=read();
for (int i=1;i<=10000;i++)
if ((n+2000*i)%1999==0)
{
cout<<2000<<endl;
for (int j=1;j<=1998;j++) cout<<0<<' ';
cout<<-i<<' ';cout<<(n+2000*i)/1999;
return 0;
}
return 0;
//NOTICE LONG LONG!!!!!
}

  C:考虑动态添加01时对每个后缀计算贡献(即可以划分成多少个合法字符串)。如果已经有与其本质相同的子串,则贡献为0,这可以建棵trie(也就是反串未压缩的后缀树)来判断。否则设l~r区间的贡献为f[l][r],其从f[l][r-4~r-1]转移而来即可。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 3010
#define P 1000000007
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,a[N],id[N][N],f[N*N],trie[N*N][2],cnt,ans;
bool isok(int l,int r)
{
if (a[l]==0&&a[l+1]==0&&a[l+2]==1&&a[l+3]==1) return 0;
if (a[l]==0&&a[l+1]==1&&a[l+2]==0&&a[l+3]==1) return 0;
if (a[l]==1&&a[l+1]==1&&a[l+2]==1&&a[l+3]==0) return 0;
if (a[l]==1&&a[l+1]==1&&a[l+2]==1&&a[l+3]==1) return 0;
return 1;
}
//0011 0101 1110 1111 ������ĸ
signed main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
n=read();f[0]=1;
for (int i=1;i<=n;i++)
{
a[i]=read();
int k=0;
for (int j=i;j>=1;j--)
{
if (!trie[k][a[j]])
{
trie[k][a[j]]=++cnt;
k=trie[k][a[j]],id[j][i]=k;
if (i-j+1==1) f[k]=1;
else if (i-j+1==2) f[k]=2;
else if (i-j+1==3) f[k]=4;
else
{
f[k]=(f[id[j][i-1]]+f[id[j][i-2]])%P;
f[k]=(f[k]+f[id[j][i-3]])%P;
if (isok(i-3,i)) f[k]=(f[k]+f[id[j][i-4]])%P;
}
ans=(ans+f[k])%P;
}
else k=trie[k][a[j]],id[j][i]=k;
}
printf("%d\n",ans);
}
return 0;
//NOTICE LONG LONG!!!!!
}

  D:显然可以dp,即f[i]为前i位的划分方案数。考虑优化转移。套路的将每个数字最后一次出现位置设为1,倒数第二次设为-1,其余为0,每次需要的就是后缀和<=m的位置之和。这个东西可以分块维护。然而只有在最后5min才想的到分块的,自闭了。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cassert>
using namespace std;
#define ll long long
#define N 100010
#define P 998244353
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,m,a[N],f[N],pre[N],p[N],s[400][N],lazy[400][400],sum[N],L[N],R[N],pos[N],delta[N],v[N],tree[N],num,block;
void tree_add(int k,int x){v[k]+=x;while (k) tree[k]+=x,k-=k&-k;}
int tree_query(int k){int s=0;while (k<=n) s+=tree[k],k+=k&-k;return s;}
void build(int k)
{
for (int i=1;i<=R[k]-L[k]+1;i++) s[k][lazy[k][i]]=0;
delta[k]=0;sum[k]=0;
int S=tree_query(R[k]+1);
for (int i=R[k];i>=L[k];i--)
{
S+=v[i];
s[k][S]=(s[k][S]+f[i-1])%P;
lazy[k][R[k]-i+1]=S;
if (S<=m) sum[k]=(sum[k]+f[i-1])%P;
}
}
void modify(int l,int r,int op)
{
if (l>r) return;
if (pos[l]==pos[r]) build(pos[l]);
else
{
for (int i=pos[l]+1;i<pos[r];i++)
{
if (op==1) {if (m-delta[i]>=0) sum[i]=(sum[i]-s[i][m-delta[i]]+P)%P;}
else {if (m-delta[i]+1>=0) sum[i]=(sum[i]+s[i][m-delta[i]+1])%P;}
delta[i]+=op;
}
build(pos[l]),build(pos[r]);
}
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
n=read(),m=read();block=sqrt(n);num=(n-1)/block+1;
for (int i=1;i<=n;i++)
{
a[i]=read();
pre[i]=p[a[i]];p[a[i]]=i;
}
for (int i=1;i<=num;i++)
{
L[i]=R[i-1]+1;R[i]=min(n,L[i]+block-1);
for (int j=L[i];j<=R[i];j++) pos[j]=i;
}
f[0]=1;build(1);
for (int i=1;i<=n;i++)
{
tree_add(i,1);if (pre[i]>0) tree_add(pre[i],-2);if (pre[pre[i]]>0) tree_add(pre[pre[i]],1);
modify(pre[i]+1,i,1);
modify(pre[pre[i]]+1,pre[i],-1);
for (int j=1;j<=num;j++) f[i]=(f[i]+sum[j])%P;
build(pos[i]);
}
cout<<f[n];
return 0;
//NOTICE LONG LONG!!!!!
}

  E:首先随便找个根。考虑我们能干什么。感觉上两个点集都不止一个点的话问出来的东西没什么意义,于是仅考虑一个点到一些点。显然可以问出每个点所拥有的子树大小。

  我们按子树大小从小到大考虑每个点,考虑完一个点后即确定其所有儿子。显然只需要找到在其子树内的还没有确定父亲的点,也相当于这些点和根在该点两侧。如果只有一个点在其子树内,显然可以通过分治确定。有多个点的话,每次找一个再删掉就行了。

  如果写的丑注意特判n=2。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cassert>
#include<vector>
using namespace std;
#define ll long long
#define N 510
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,p[N],size[N],fa[N],id[N],t,root;
vector<int> nofa;
struct data{int to,nxt;
}edge[N<<1];
void addedge(int x,int y){t++;edge[t].to=y,edge[t].nxt=p[x],p[x]=t;}
int belongtox(int x)
{
cout<<1<<endl<<root<<endl;
cout<<n-2<<endl;
for (int i=2;i<=n;i++) if (i!=x) cout<<i<<' ';cout<<endl;
cout<<x<<endl;
return read()+1;
}
bool cmp(const int &a,const int&b)
{
return size[a]<size[b];
}
int calc(int x,int l,int r)
{
cout<<1<<endl<<root<<endl;
cout<<r-l+1<<endl;
for (int i=l;i<=r;i++) cout<<nofa[i]<<' ';cout<<endl;
cout<<x<<endl;
return read();
}
int find(int x)
{
int l=0,r=nofa.size()-1,ans;
while (l<=r)
{
int mid=l+r>>1;
if (calc(x,l,mid)) ans=mid,r=mid-1;
else l=mid+1;
}
return ans;
}
signed main()
{
n=read();if (n==2) {cout<<"ANSWER"<<endl<<1<<' '<<2;return 0;}
root=1;size[1]=n;
for (int i=2;i<=n;i++) size[i]=belongtox(i);
for (int i=1;i<=n;i++) id[i]=i;
sort(id+1,id+n+1,cmp);
for (int i=1;i<=n;i++)
{
if (!nofa.empty())
{
do
{
if (nofa.empty()) break;
int x=calc(id[i],0,nofa.size()-1);
if (!x) break;
int y=find(id[i]);fa[nofa[y]]=id[i];
nofa.erase(nofa.begin()+y);
}while (1);
}
nofa.push_back(id[i]);
}
cout<<"ANSWER"<<endl;
for (int i=2;i<=n;i++) cout<<i<<' '<<fa[i]<<endl;
return 0;
//NOTICE LONG LONG!!!!!
}

  result:rank 25 rating +121 上红辣!!!???

Codeforces Round #542 Div. 1的更多相关文章

  1. Codeforces Round 542 (Div. 2)

    layout: post title: Codeforces Round 542 (Div. 2) author: "luowentaoaa" catalog: true tags ...

  2. Codeforces Round #542(Div. 2) CDE 思维场

    C https://codeforces.com/contest/1130/problem/C 题意 给你一个\(n*m\)(n,m<=50)的矩阵,每个格子代表海或者陆地,给出在陆地上的起点终 ...

  3. Codeforces Round #542(Div. 2) B.Two Cakes

    链接:https://codeforces.com/contest/1130/problem/B 题意: 给定n和 2 * n个数,表示i位置卖ai层蛋糕, 有两个人在1号,必须严格按照1-n的顺序买 ...

  4. Codeforces Round #542(Div. 2) A.Be Positive

    链接:https://codeforces.com/contest/1130/problem/A 题意: 给n个数,找出一个非0整数d,使所有n个数除以整数d后,数组中正数的数量>= n/2. ...

  5. Codeforces Round #542(Div. 2) D1.Toy Train

    链接:https://codeforces.com/contest/1130/problem/D1 题意: 给n个车站练成圈,给m个糖果,在车站上,要被运往某个位置,每到一个车站只能装一个糖果. 求从 ...

  6. Codeforces Round #542(Div. 2) C.Connect

    链接:https://codeforces.com/contest/1130/problem/C 题意: 给一个n*n的图,0表示地面,1表示水,给出起点和终点, 现要从起点到达终点,有一次在两个坐标 ...

  7. Codeforces Round #542 (Div. 1) 题解

    开学了住校了打不了深夜场 好难受啊QwQ A 显然对于每个起点,我们只需要贪心记录这个起点出发出去的糖果数量以及离自己最近的糖果 因为这个起点最后一次装载糖果一定是装载终点离自己最近的那个糖果 $ O ...

  8. Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2) 题解

    Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2) 题目链接:https://codeforces.com/contest/1130 ...

  9. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

随机推荐

  1. 52ABP模板 ASP.Net Core 与 Angular的开源实例项目

    阅读文本大概需要 5 分钟. 开始之前 自从上一篇文章".NET:持续进化的统一开发平台"发布后,已经有三个月的时间没有写过文章了. 这段时间,做了两场线下活动,一场在上海,一场在 ...

  2. PySpider框架的基本用法

    pyspider安装: 3.7之后无法正常使用,使用可以下载Python3.6或以下,或者修改pyspider内部代码 ———————————————————————————————————————— ...

  3. Python-os模块-60

    os 模块: 和操作系统打交道的模块 os模块是与操作系统交互的一个接口 os.makedirs('dirname1/dirname2') 可生成多层递归目录 os.removedirs('dirna ...

  4. H5 62-浮动元素字围现象

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. 牛客国庆集训派对Day2

    题目链接:https://www.nowcoder.com/acm/contest/202/A A 题意:给出最大4096*64和64*4096的矩阵,其中有一个矩阵只含有0和1,问你它们相乘所得到得 ...

  6. long double

    long double 输入输出 scanf("%Lf",&a); printf("%.20Lf\n",a);

  7. c++入门之——const在函数名前面和函数后面的区别

    class Test(){ public: Test(){} const int foo(int a); const int foo(int a) const; }; 一.概念 当const在函数名前 ...

  8. ImportError: DLL load failed: 找不到指定的模块。

    这里用的anacoda,报错是找不到DLL,可能是该DLL的环境变量没配置,配置系统环境变量: 重启一下pycharm,OK.

  9. CentOS 7.2 yum安装LAMP环境

    https://www.linuxidc.com/Linux/2016-11/136766.htm 详见以上链接,用yum安装方便省事. 尤其注意,mysql数据要设置远程连接.

  10. MongoDB之修改器

    MongoDB之修改器 $set  简单粗暴  {name: valuel} 直接将key对应的值赋值给value. db.xxoo.insert({}, {set: {key: value}}) / ...