link

C-Triangular Relationship

发现要么全部是\(K\)的倍数,要么全部是模\(K\)余\(K/2,(K=2n)\)

#include<bits/stdc++.h>
#define ll long long
#define dbg1(x) cerr<<#x<<"="<<(x)<<" "
#define dbg2(x) cerr<<#x<<"="<<(x)<<"\n"
#define dbg3(x) cerr<<#x<<"\n"
using namespace std;
#define reg register
inline int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
return x*f;
}
ll N,K,num;ll p3(ll x){return x*x*x;}
int main()
{
N=read();K=read();
num=p3(N/K);
if(K%2==0) num+=p3(N/K+((N%K)>=(K/2)));
printf("%lld\n",num);
}

D-All Your Paths are Different Lengths

\(L=2^{a_1}+2^{a_2}+...+2^{a_n},a_1<a_2<...<a_n\)

建立\(n\)个中转点,每个点\(i\)向下一个点连接\(0\)和\(2^{i-1}\)的边

对于\(a_i,i<n\),第\(a_i+1\)个点在向最后一个点连\(\sum_{j=i+1}2^{a_j}\)的边

#include<bits/stdc++.h>
#define ll long long
#define dbg1(x) cerr<<#x<<"="<<(x)<<" "
#define dbg2(x) cerr<<#x<<"="<<(x)<<"\n"
#define dbg3(x) cerr<<#x<<"\n"
using namespace std;
#define reg register
inline int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
return x*f;
}
int L,a[25],cnt;
int main()
{
int L=read();
reg int i,j,N=0,M=0;
for(i=0;i<=20;++i)if(L>>i&1)a[++cnt]=i-1,++M;
N=a[cnt]+2;M=M+N*2-3;
printf("%d %d\n",N,M);
a[0]=-1;
for(i=1;i<=cnt;++i)
{
for(j=a[i-1];j<a[i];++j)
printf("%d %d %d\n",j+2,j+3,0),
printf("%d %d %d\n",j+2,j+3,(1<<(j+1)));
if(i==cnt) break;
printf("%d %d %d\n",a[i]+2,N,L-(1<<a[i]+1));
L-=1<<a[i]+1;
}
return 0;
}

E-Stop. Otherwise

比较简单的计数问题,一个限制相当于有两个数只能选择其中的一个

枚举一下选了多少个这样有限制的组,组合数算一下每个数要多少个

#include<bits/stdc++.h>
#define ll long long
#define dbg1(x) cerr<<#x<<"="<<(x)<<" "
#define dbg2(x) cerr<<#x<<"="<<(x)<<"\n"
#define dbg3(x) cerr<<#x<<"\n"
using namespace std;
#define reg register
inline int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
return x*f;
}
const int Mod=998244353,MN=4004;
int Mul(int x,int y){return (1ll*x*y)%Mod;}
int Add(int x,int y){return (x+y)%Mod;}
int fac[MN],inv[MN],p2[MN];
int C(int i,int j)
{
if(i<0||j<0||i<j)return 0;
return Mul(fac[i],Mul(inv[j],inv[i-j]));
}
int F(int i,int j){return C(i+j-1,j-1);}
int sol(int N,int pr,int nm)
{
reg int i,j=min(N,pr);int r=0;
for(i=0;i<=j;++i)r=Add(r,Mul(p2[i],Mul(C(pr,i),F(N-i,nm-pr+i))));
return r;
}
int main()
{
int N,K;reg int i,Ma;
K=read();N=read();Ma=max(K,N);
for(fac[0]=i=1;i<=Ma*2;++i)fac[i]=Mul(fac[i-1],i);
for(inv[0]=inv[1]=1,i=2;i<=Ma*2;++i) inv[i]=Mul(inv[Mod%i],(Mod-Mod/i));
for(i=2;i<=Ma*2;++i) inv[i]=Mul(inv[i-1],inv[i]);
for(p2[0]=i=1;i<=Ma*2;++i) p2[i]=Mul(p2[i-1],2);
for(i=2;i<=K*2;++i)
{
int ans=0,pr=i/2-max(i-K,1)+1;
if(i%2==0) ans=Add(ans,sol(N-1,pr-1,K-pr));
ans=Add(ans,sol(N,pr-(i%2==0),K-pr));
printf("%d\n",ans);
}
return 0;
}

F-Revenge of BBuBBBlesort

考虑逆操作的过程

发现\(i-1,i,i+1\)一旦交换过,\(i\)这个点就不会变了

最后,每个有变化的极大区间\([i,j]\)一定满足

  1. \(i,i+2,i+4,...j\)的位置变化
  2. \(i+1,i+3,i+5,...j-1\)的位置不变

我们找到这样一个区间,又因为它无法与周围的其它的数交换,所以这个区间的值的集合应该恰好等于这个区间的每个位置下标的集合

考虑怎样才能移动为有序

首先,如果将一个数向右移动,那么它无法再向左移动,因为与它相邻的数是固定的,所以无法往回走

所以,一个数能朝着它的目标位置方向做单向运动

朝同一个方向运动的数单调递增,否则超越的那一步,前数朝反方向运动

相当于\(a[i]<i\)和\(a[i]>i\)的点的\(a[i]\)值分别单调递增

#include<bits/stdc++.h>
#define ll long long
#define dbg1(x) cerr<<#x<<"="<<(x)<<" "
#define dbg2(x) cerr<<#x<<"="<<(x)<<"\n"
#define dbg3(x) cerr<<#x<<"\n"
using namespace std;
#define reg register
inline int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
return x*f;
}
const int MN=300005;
int a[MN],N;
void No(){puts("No");exit(0);}
void Yes(){puts("Yes");exit(0);}
void chk(int l,int r)
{
reg int i,_1=0,_2=0;
for(i=l+1;i<=r-1;i+=2)if(a[i]!=i)No();
for(i=l;i<=r;i+=2)if(a[i]==i)No();
for(i=l;i<=r;i+=2)
if(i<a[i]){if(_1>a[i])No();_1=a[i];}
else{if(_2>a[i])No();_2=a[i];}
}
main()
{
N=read();reg int i;
for(i=1;i<=N;++i) a[i]=read();
int l=1,r;
while(a[l]==l&&l<N)++l;
while(1)
{
if(a[l]==l)Yes();
if(l+2>N)No();r=l+2;
int Mi=min(a[l],a[r]),Ma=max(a[l],a[r]);
while((r!=Ma||l!=Mi)&&r<=N)r+=2,Mi=min(Mi,a[r]),Ma=max(Ma,a[r]);
if(r>N)No();chk(l,r);
l=r+1;while(a[l]==l&&l<N)++l;
if(l>N)break;
}
Yes();
}

Blog来自PaperCloud,未经允许,请勿转载,TKS!

【AtCoder】 ARC 102的更多相关文章

  1. 【AtCoder】ARC 081 E - Don't Be a Subsequence

    [题意]给定长度为n(<=2*10^5)的字符串,求最短的字典序最小的非子序列字符串. http://arc081.contest.atcoder.jp/tasks/arc081_c [算法]字 ...

  2. 【Atcoder】ARC 080 E - Young Maids

    [算法]数学+堆 [题意]给定n个数的排列,每次操作可以取两个数按序排在新序列的头部,求最小字典序. [题解] 转化为每次找字典序最小的两个数按序排在尾部,则p1和p2的每次选择都必须满足:p1在当前 ...

  3. 【Atcoder】ARC 080 F - Prime Flip

    [算法]数论,二分图最大匹配 [题意]有无限张牌,给定n张面朝上的牌的坐标(N<=100),其它牌面朝下,每次操作可以选定一个>=3的素数p,并翻转连续p张牌,求最少操作次数使所有牌向下. ...

  4. 【AtCoder】 ARC 097

    link C-K-th Substring 题意:找出已知串中第\(k\)大的子串,子串相同的不算 \(k\)好小啊,要怎么做啊 不是[Tjoi2015]弦论吗 算了,直接SAM吧 #include& ...

  5. 【AtCoder】 ARC 096

    link C-Half and Half 题意:三种pizza,可以花\(A\)价钱买一个A-pizza,花\(B\)价钱买一个B-pizza,花\(C*2\)价钱买A-pizza和B-pizza各一 ...

  6. 【AtCoder】 ARC 098

    link C-Attention 题意:一个字符队列,每个位置是\(W\)或\(E\),计算最小的修改数量,使得存在一个位置,它之前的都是\(E\),之后的都是\(F\) #include<bi ...

  7. 【AtCoder】 ARC 099

    link C-Minimization 枚举覆盖\(1\)的区间,两边的次数直接算 #include<bits/stdc++.h> #define ll long long #define ...

  8. 【AtCoder】 ARC 100

    link C-Linear Approximation 给出\(N\)个数\(A_1,A_2,...,A_N\) ,求一个数\(d\),最小化\(\sum_{i=1}^N|A_i-(d+i)|\) 把 ...

  9. 【AtCoder】 ARC 101

    link 搬来了曾经的题解 C-Candles 题意:数轴上有一些点,从原点开始移动到达这些点中的任意\(K\)个所需要的最短总路程 \(K\)个点必然是一个区间,枚举最左边的就行了 #include ...

随机推荐

  1. Implicit super constructor Array() is undefined for default constructor. Must define an explicit constructor

    因为你的父类已经创建了一个带参的构造函数并且父类中没有无参的构造函数,此时编译器不会为你调用默认的构造函数, 所以子类在继承父类的时候需要在自己的构造函数中显式的调用父类的构造函数,这样才能确保子类在 ...

  2. eclipse中启动tomcat后, 无法访问localhost:8080

    问题: 今天老师讲了Servlet路径问题, 做了个测试在eclipse中启动tomcat后,在浏览器地址栏输入 http://localhost8080无法访问, 提示404错误, 正常情况是可以访 ...

  3. Flexbox布局入门笔记

    1.display:flex 设定为Flexbox布局容器. 2.flex-direction: row表示在水平方向展开可伸缩项:column表示在垂直方向展开可伸缩项:总之就是定义主轴(侧轴方向) ...

  4. 学习笔记之Slurm

    Slurm Workload Manager - Overview https://slurm.schedmd.com/overview.html Slurm is an open source, f ...

  5. Python人工智能第二篇:人脸检测和图像识别

    Python人工智能第二篇:人脸检测和图像识别 人脸检测 详细内容请看技术文档:https://ai.baidu.com/docs#/Face-Python-SDK/top from aip impo ...

  6. python 中json和字符串互相转换

      string =" {  "status": "error",  "messages": ["Could not f ...

  7. Linux--重要文件

    目录 /etc/resolv.conf /etc/host /etc/sysconfig/network /etc/fstab /etc/rc.local /etc/profile /etc/bash ...

  8. vmstat 内存信息

    vmstat - Report virtual memory statistics 报告虚拟内存统计信息. 展示的信息可以用做系统资源监控. 语法格式: vmstat [options] [delay ...

  9. vsftpd配置文件

    一.默认配置 1. 允许匿名用户和本地用户登录 anonymous_enable=YES local_enable=YES 2. 匿名用户使用的登录名为ftp或anonymous,密码为空:匿名用户不 ...

  10. 微信小程序~TabBar底部导航切换栏

    底部导航栏这个功能是非常常见的一个功能,基本上一个完成的app,都会存在一个导航栏,那么微信小程序的导航栏该怎么实现呢?经过无数的踩坑,终于实现了,好了,先看看效果图. 对于底部导航栏,小程序上给出的 ...