网太卡只好做划水选手,只做EF。

E

很容易发现第一个数是2k或者是3*2k-1,因为消去因子次数要尽可能多,然后可以直接dp一发转移还剩几个2/3即可,写起来有些麻烦

#include<bits/stdc++.h>
using namespace std;
const int N=1e6+,mod=1e9+;
int n,k,ans,a[][],f[N][][];
int count(int x)
{
int ret=;
while(x%==)ret++,x/=;
return ret;
}
int main()
{
scanf("%d",&n);
if(n<=){puts("");return ;}
for(int i=;i;i--)if((<<i)<=n){k=i;break;}
for(int i=;i<=n;i++)a[count(i)][]++;
for(int i=k-;~i;i--)a[i][]+=a[i+][];
f[][k][]=;
for(int i=;i<=n;i++)
for(int j=;j<=k;j++)
{
f[i][j][]=(f[i][j][]+1ll*f[i-][j+][]*(a[j][]-a[j+][]))%mod;
f[i][j][]=(f[i][j][]+1ll*f[i-][j][]*(a[j][]-i+))%mod;
}
ans=f[n][][];
if((<<k-)*<=n)
{
memset(f,,sizeof f);
memset(a,,sizeof a);
for(int i=;i<=n;i++)a[count(i)][i%==]++;
for(int i=k-;~i;i--)a[i][]+=a[i+][],a[i][]+=a[i+][];
f[][k-][]=;
for(int i=;i<=n;i++)
for(int j=;j<k;j++)
{
f[i][j][]=(f[i][j][]+1ll*f[i-][j+][]*(a[j][]-a[j+][]))%mod;
f[i][j][]=(f[i][j][]+1ll*f[i-][j][]*(a[j][]-i+))%mod;
f[i][j][]=(f[i][j][]+1ll*f[i-][j+][]*(a[j][]+a[j][]-a[j+][]-a[j+][]))%mod;
f[i][j][]=(f[i][j][]+1ll*f[i-][j][]*(a[j][]+a[j][]-i+))%mod;
f[i][j][]=(f[i][j][]+1ll*f[i-][j][]*a[j][])%mod;
}
ans=(ans+f[n][][])%mod;
}
printf("%d",ans);
}

F

可以考虑树剖,然后询问时,若询问的lca不在重儿子上,则大小/2,反之下logn次即可,容易证明这个询问次数是log级别的

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+;
int n,dis,dep[N],sz[N],son[N],ed[N];
vector<int>G[N];
void dfs(int u,int fa)
{
sz[u]=;
for(int i=;i<G[u].size();i++)
if(G[u][i]!=fa)
{
dep[G[u][i]]=dep[u]+,dfs(G[u][i],u),sz[u]+=sz[G[u][i]];
if(sz[G[u][i]]>sz[son[u]])son[u]=G[u][i];
}
ed[u]=son[u]?ed[son[u]]:u;
}
int askd(int x)
{
printf("d %d\n",x),fflush(stdout);
scanf("%d",&x);
return x;
}
int asks(int x)
{
printf("s %d\n",x),fflush(stdout);
scanf("%d",&x);
return x;
}
int solve(int u)
{
if(dep[u]==dis)return u;
if(dis-dep[u]==)return asks(u);
int lca=dep[ed[u]]+dis-askd(ed[u])>>;
if(dep[u]==lca)return solve(asks(u));
while(dep[u]!=lca&&dep[u]!=dis)u=son[u];
return solve(u);
}
int main()
{
scanf("%d",&n);
for(int i=,x,y;i<n;i++)scanf("%d%d",&x,&y),G[x].push_back(y),G[y].push_back(x);
dfs(,),dis=askd();
printf("! %d",solve());
}

Codeforces Round #563 (Div. 2) 划水记的更多相关文章

  1. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

  2. Codeforces Round #394 (Div. 2) 颓废记

    昨天晚上(今天凌晨),又忍不住去打CF.(本蒟弱到只能打Div.2)... 我觉得我可以用一个词概括我这次的CF: 呵呵 刚一开赛,我就codeforces访问失败.. 后来好不容易能上了,两三分钟才 ...

  3. Codeforces Round#500 Div.2 翻车记

    A:签到 #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> # ...

  4. Codeforces Round #402 (Div. 2) 阵亡记

    好长时间没有打Codeforces了,今天被ysf拉过去打了一场. lrd也来参(nian)加(ya)比(zhong)赛(sheng) Problem A: 我去,这不SB题吗.. 用桶统计一下每个数 ...

  5. Codeforces Round #563 (Div. 2) C. Ehab and a Special Coloring Problem

    链接:https://codeforces.com/contest/1174/problem/C 题意: You're given an integer nn. For every integer i ...

  6. Codeforces Round #563 (Div. 2) B. Ehab Is an Odd Person

    链接:https://codeforces.com/contest/1174/problem/B 题意: You're given an array aa of length nn. You can ...

  7. Codeforces Round #563 (Div. 2) A. Ehab Fails to Be Thanos

    链接:https://codeforces.com/contest/1174/problem/A 题意: You're given an array aa of length 2n2n. Is it ...

  8. Codeforces Round #563 (Div. 2)C

    C. Ehab and a Special Coloring Problem 题目链接:http://codeforces.com/contest/1174/problem/C 题目 You're g ...

  9. Codeforces Round #563 (Div. 2)B

    B.Ehab Is an Odd Person 题目链接:http://codeforces.com/contest/1174/problem/B 题目 You’re given an array a ...

随机推荐

  1. Django 异常处理

    我们新建一个py文件 # 在restful中导入exception_handler from rest_framework.views import exception_handler from dj ...

  2. UVA - 1149 Bin Packing(装箱)(贪心)

    题意:给定N(N<=10^5)个物品的重量Li,背包的容量M,同时要求每个背包最多装两个物品.求至少要多少个背包才能装下所有的物品. 分析:先排序,从最重的开始装,如果重量小于M,则如果能装一个 ...

  3. 16 ~ express ~ 添加博客分类

    一,创建表结构  /schemas/categories.js var mongoose = require('mongoose')   module.exports = new mongoose.S ...

  4. 17 —— 服务端渲染 —— art-template

    一,前端渲染数据 的弊端 仿 apache 服务器与客户端的几次交互: 1,加载静态页面 2,加载静态资源 3,发送 ajax 请求 ,接收请求并处理返回 . 4,前端浏览器接收数据循环遍历. 存在的 ...

  5. Toolbar融入状态栏实现沉浸式遇到的问题

    这里写一个纠结我一下午的问题,目的是写一个toolbar和状态栏相融合的沉浸式的样子,遇到各种各样的问题,还好最后慢慢解决了. 一.首先在活动中将状态栏设为透明 @Override protected ...

  6. Linux command line and shell scripting buble

    Chapter 4 More bash shell Commands 1. ps ps -ef 2. top 3. kill 3940 kill -s HUP 3940 killall http* 4 ...

  7. 如何做好Essay Proofreading?

    终于写完了一篇Essay,瞬间感觉人生轻松了好多!别急,想要Essay最终得到高分,你还需要最后一步:论文润色! 换句话说,就是我们需要写完的Essay进行检查校对.那么我们一般需要校对的部分有哪些呢 ...

  8. qt 程序发布打包

    1. 首先把 release 版本的 exe 复制到其他文件夹,比如 Desktop\test 2. 使用开始菜单中 qt 里面的控制台窗口,使用 cd 命令打开到 Desktop\test 位置,然 ...

  9. 直线电机设计与优化(TFLM,FSLM)论文阅读笔记3

    2.21-(2.7论文引出)傅里叶对开关磁通电机建模 Modeling of Flux Switching Permanent Magnet Machines With Fourier Analysi ...

  10. Caused by: com.mysql.cj.exceptions.DataReadException: Zero date value prohibited

    原因:数据库日期出现零值,即0000-00-00 属于一个无效日期. 解决方案:重新赋值,或者在jdbc链接后加参数zeroDateTimeBehavior=convertToNull