2021.9.13考试总结[NOIP模拟52]
T1 路径
考虑每一位的贡献,第$i$位每$2^i$个数会变一次,那么答案为$\sum_{i=1}^{log_2n} \frac{n}{2^i}$。
$code:$


1 #include<bits/stdc++.h>
2 #define int unsigned long long
3 using namespace std;
4
5 namespace IO{
6 inline int read(){
7 char ch=getchar(); int x=0,f=1;
8 while(ch<'0'||ch>'9'){ if(ch=='-') f=-1; ch=getchar(); }
9 while(ch>='0'&&ch<='9'){ x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
10 return x*f;
11 }
12 inline void write(int x,char sp){
13 char ch[50]; int len=0;
14 if(x<0){ putchar('-'); x=~x+1; }
15 do{ ch[len++]=x%10+(1<<4)+(1<<5); x/=10; }while(x);
16 for(int i=len-1;~i;--i) putchar(ch[i]); putchar(sp);
17 }
18 inline int max(int x,int y){ return x<y?y:x; }
19 inline int min(int x,int y){ return x<y?x:y; }
20 inline void swap(int &x,int &y){ x^=y^=x^=y; }
21 inline void chmax(int &x,int y){ x=x<y?y:x; }
22 inline void chmin(int &x,int y){ x=x<y?x:y; }
23 } using namespace IO;
24
25 const int NN=70;
26 int x,n,ext,ans;
27
28 signed main(){
29 x=n=read();
30 while(n){ ++ext; n>>=1; }
31 for(int i=0;i<ext;i++) ans+=x/(1ll<<i);
32 write(ans,'\n');
33 return 0;
34 }
T1
考场思路:
考虑式子实际意义,其实为每个数末尾连续$1$的个数加一的和。
于是可以数位$DP$。
但我没有。考虑上界$n-1$,扫描每一二进制位,将每个$1$变成$0$,都会给答案带来贡献。
具体来说,由低数第$i$为是$1$,会给末尾有$j$个连续$1$的数的个数带来$2^(i-j)$的贡献。最后容斥,统计答案。
注意如果扫到的$1$到末尾一直是$1$,则会给当前位带来额外$1$的贡献。以及
左移要写$1LL$!!
$code:$


1 #include<bits/stdc++.h>
2 #define int long long
3 using namespace std;
4
5 namespace IO{
6 inline int read(){
7 char ch=getchar(); int x=0,f=1;
8 while(ch<'0'||ch>'9'){ if(ch=='-') f=-1; ch=getchar(); }
9 while(ch>='0'&&ch<='9'){ x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
10 return x*f;
11 }
12 inline void write(int x,char sp){
13 char ch[20]; int len=0;
14 if(x<0){ putchar('-'); x=~x+1; }
15 do{ ch[len++]=x%10+(1<<4)+(1<<5); x/=10; }while(x);
16 for(int i=len-1;~i;--i) putchar(ch[i]); putchar(sp);
17 }
18 inline int max(int x,int y){ return x<y?y:x; }
19 inline int min(int x,int y){ return x<y?x:y; }
20 inline void swap(int &x,int &y){ x^=y^=x^=y; }
21 inline void chmax(int &x,int y){ x=x<y?y:x; }
22 inline void chmin(int &x,int y){ x=x<y?x:y; }
23 } using namespace IO;
24
25 const int NN=70;
26 int x,n,ans,ext,sum,lmt[NN],num[NN];
27 bool link;
28
29 signed main(){
30 x=ans=n=read(); --n; --x; link=1;
31 while(x){
32 lmt[++ext]=x&1;
33 x>>=1;
34 }
35 for(int i=1;i<=ext;i++){
36 if(!lmt[i]){ link=0; continue;}
37 if(lmt[i]) for(int j=1;j<i;j++) num[j]+=1ll<<(i-j-1);
38 if(link) ++num[i];
39 }
40 for(int i=ext;i;i--){
41 num[i]-=sum;
42 sum+=num[i];
43 ans+=i*num[i];
44 }
45 write(ans,'\n');
46 return 0;
47 }
T1考场
T2 赌神
大力推式子(但我不会
玄学做法:
考虑自己的最优方案,一定是要尽力令颜色数减少,但同时自己不能亏损,所以每次应按比例下注。
幕后黑手要尽力使颜色数不减少,所以每次投出颜色最多的球。
模拟即可。
其实由于自己每次取最优策略,不管幕后黑手怎样处理结果都不会改变。
$code:$


1 #include<bits/stdc++.h>
2 #define int long long
3 using namespace std;
4
5 namespace IO{
6 inline int read(){
7 char ch=getchar(); int x=0,f=1;
8 while(ch<'0'||ch>'9'){ if(ch=='-') f=-1; ch=getchar(); }
9 while(ch>='0'&&ch<='9'){ x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
10 return x*f;
11 }
12 inline void write(int x,char sp){
13 char ch[20]; int len=0;
14 if(x<0){ putchar('-'); x=~x+1; }
15 do{ ch[len++]=x%10+(1<<4)+(1<<5); x/=10; }while(x);
16 for(int i=len-1;~i;--i) putchar(ch[i]); putchar(sp);
17 }
18 inline int max(int x,int y){ return x<y?y:x; }
19 inline int min(int x,int y){ return x<y?x:y; }
20 inline void swap(int &x,int &y){ x^=y^=x^=y; }
21 inline void chmax(int &x,int y){ x=x<y?y:x; }
22 inline void chmin(int &x,int y){ x=x<y?x:y; }
23 } using namespace IO;
24
25 const int NN=1e6+5,p=998244353;
26 int n,ans,sum,num;
27 priority_queue<int>q;
28
29 inline int inv(int x){
30 int res=1,b=p-2;
31 while(b){
32 if(b&1) res=res*x%p;
33 x=x*x%p;
34 b>>=1;
35 }
36 return res;
37 }
38
39 signed main(){
40 n=read(); ans=1;
41 for(int i=1;i<=n;i++){
42 num=read();
43 sum+=num;
44 q.push(num);
45 }
46 while(sum){
47 int x=q.top(); q.pop();
48 if(x-1) q.push(x-1);
49 ans=ans*n%p*x%p*inv(sum)%p;
50 --sum;
51 }
52 write(ans,'\n');
53 return 0;
54 }
T2
T3 路径
数据太弱,$O(n^2log)$点分治都能A。。
点分治带个$fft$或$ntt$可以到$O(nlog^2)$,可A。但不会。
正解斯特林数+换根$DP$。
$x^k=\sum_{i=1}^k \begin{Bmatrix}k\\ i\end{Bmatrix}\times x^{\underline i}$
有$(x+1)^{\underline i}=i\times x^{\underline{i-1}}+x^{\underline i}$。
设$f_{i,j}$为$i$子树中所有点到$i$距离的$j$次下降幂之和,$g_{i,j}$为$i$子树中所有点到$i$父亲距离的$j$次下降幂之和。那么有
$f_{i,j}=\sum_{u\in son_i}g_{u,j}$,$g_{i,j}=j\times f_{i,j-1}+f_{i,j}$。
换根时考虑原来根的$f$,减去新根的$g$;新根的$f$加上由原来根的$f$通过上面式子算出的$g$。
$code:$


1 #include<bits/stdc++.h>
2 using namespace std;
3
4 namespace IO{
5 inline int read(){
6 char ch=getchar(); int x=0,f=1;
7 while(ch<'0'||ch>'9'){ if(ch=='-') f=-1; ch=getchar(); }
8 while(ch>='0'&&ch<='9'){ x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
9 return x*f;
10 }
11 inline void write(int x,char sp){
12 char ch[20]; int len=0;
13 if(x<0){ putchar('-'); x=~x+1; }
14 do{ ch[len++]=x%10+(1<<4)+(1<<5); x/=10; }while(x);
15 for(int i=len-1;~i;--i) putchar(ch[i]); putchar(sp);
16 }
17 inline int max(int x,int y){ return x<y?y:x; }
18 inline int min(int x,int y){ return x<y?x:y; }
19 inline void swap(int &x,int &y){ x^=y^=x^=y; }
20 inline void chmax(int &x,int y){ x=x<y?y:x; }
21 inline void chmin(int &x,int y){ x=x<y?x:y; }
22 } using namespace IO;
23
24 const int NN=1e6+5,p=998244353,inv2=499122177;
25 int n,k,ans,f[NN][105],g[NN][105],sum[105];
26 int idx,to[NN<<1],nex[NN<<1],head[NN],s[105][105];
27
28 inline void add(int a,int b){
29 to[++idx]=b; nex[idx]=head[a]; head[a]=idx;
30 to[++idx]=a; nex[idx]=head[b]; head[b]=idx;
31 }
32
33 void init(){
34 s[1][1]=1;
35 for(int i=2;i<=k;i++) for(int j=1;j<=i;j++)
36 s[i][j]=(s[i-1][j-1]+1ll*j*s[i-1][j]%p)%p;
37 }
38
39 void dfs(int st,int fa){
40 int ext=0;
41 for(int i=head[st];i;i=nex[i]){
42 int v=to[i];
43 if(v==fa) continue;
44 dfs(v,st);
45 for(int i=0;i<=k;i++){
46 if(!g[v][i]) break;
47 chmax(ext,i);
48 (f[st][i]+=g[v][i])%=p;
49 }
50 }
51 ++f[st][0]; ext=min(k,ext+1);
52 for(int i=ext;i;i--)
53 g[st][i]=(1ll*i*f[st][i-1]%p+f[st][i])%p;
54 g[st][0]=f[st][0];
55 }
56
57 void getans(int st,int fa){
58 int ext=0,tmp[105];
59 for(int i=0;i<=k;i++){
60 if(!f[st][i]) break;
61 chmax(ext,i);
62 (sum[i]+=f[st][i])%=p;
63 }
64 ext=min(k,ext+1);
65 for(int i=head[st];i;i=nex[i]){
66 int v=to[i];
67 if(v==fa) continue;
68 for(int j=0;j<=ext;j++) tmp[j]=(f[st][j]-g[v][j]+p)%p;
69 for(int j=ext;j;j--) tmp[j]=(1ll*tmp[j-1]*j%p+tmp[j])%p;
70 for(int j=0;j<=ext;j++) (f[v][j]+=tmp[j])%=p;
71 getans(v,st);
72 }
73 }
74
75 signed main(){
76 n=read(); k=read(); init();
77 for(int a,b,i=1;i<n;i++)
78 a=read(),b=read(), add(a,b);
79 dfs(1,0); getans(1,0);
80 for(int i=0;i<=k;i++) (ans+=1ll*s[k][i]*sum[i]%p)%=p;
81 ans=1ll*ans*inv2%p;
82 write(ans,'\n');
83 return 0;
84 }
T3
T4 树
暴力分层动态开点线段树:
$code:$


1 #include<bits/stdc++.h>
2 using namespace std;
3
4 namespace IO{
5 inline int read(){
6 char ch=getchar(); int x=0,f=1;
7 while(ch<'0'||ch>'9'){ if(ch=='-') f=-1; ch=getchar(); }
8 while(ch>='0'&&ch<='9'){ x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
9 return x*f;
10 }
11 inline void write(int x,char sp){
12 char ch[20]; int len=0;
13 if(x<0){ putchar('-'); x=~x+1; }
14 do{ ch[len++]=x%10+(1<<4)+(1<<5); x/=10; }while(x);
15 for(int i=len-1;~i;--i) putchar(ch[i]); putchar(sp);
16 }
17 inline int max(int x,int y){ return x<y?y:x; }
18 inline int min(int x,int y){ return x<y?x:y; }
19 inline void swap(int &x,int &y){ x^=y^=x^=y; }
20 inline void chmax(int &x,int y){ x=x<y?y:x; }
21 inline void chmin(int &x,int y){ x=x<y?x:y; }
22 } using namespace IO;
23
24 const int NN=3e5+5;
25 int n,q,x,y,z,v,mx,op,cnt,idx,siz[NN],dfn[NN],to[NN<<1],nex[NN<<1],head[NN],w[NN],dep[NN];
26
27 inline void add(int a,int b){
28 to[++idx]=b; nex[idx]=head[a]; head[a]=idx;
29 to[++idx]=a; nex[idx]=head[b]; head[b]=idx;
30 }
31
32 void dfs(int s,int f){
33 dfn[s]=++cnt; dep[s]=dep[f]+1; siz[s]=1;
34 chmax(mx,dep[s]);
35 for(int i=head[s];i;i=nex[i])
36 if(to[i]!=f) dfs(to[i],s), siz[s]+=siz[to[i]];
37 }
38
39 namespace segment_tree{
40 int tot,root[NN],lc[NN*80],rc[NN*80],val[NN*80];
41 void insert(int &rt,int l,int r,int opl,int opr,int vv){
42 if(!rt) rt=++tot;
43 if(l>=opl&&r<=opr) return val[rt]+=vv,void();
44 int mid=l+r>>1;
45 if(opl<=mid) insert(lc[rt],l,mid,opl,opr,vv);
46 if(opr>mid) insert(rc[rt],mid+1,r,opl,opr,vv);
47 }
48 int query(int rt,int l,int r,int pos,int ans){
49 ans+=val[rt];
50 if(l==r) return ans;
51 int mid=l+r>>1;
52 if(pos<=mid) return query(lc[rt],l,mid,pos,ans);
53 else return query(rc[rt],mid+1,r,pos,ans);
54 }
55 } using namespace segment_tree;
56
57 signed main(){
58 n=read(); q=read();
59 for(int a,b,i=1;i<n;i++)
60 a=read(),b=read(), add(a,b);
61 dfs(1,0);
62 while(q--){
63 op=read();
64 if(op==1){
65 v=read(); x=read(); y=read(); z=read();
66 int tmp=y+dep[v];
67 while(tmp<=mx){
68 insert(root[tmp],1,n,dfn[v],dfn[v]+siz[v]-1,z);
69 tmp+=x;
70 }
71 }
72 else{
73 v=read();
74 write(query(root[dep[v]],1,n,dfn[v],0),'\n');
75 }
76 }
77 return 0;
78 }
T4暴力
正解离线分块,待补(不补
2021.9.13考试总结[NOIP模拟52]的更多相关文章
- 2021.8.13考试总结[NOIP模拟38]
T1 a 入阵曲.枚举矩形上下界,之后从左到右扫一遍.用树状数组维护前缀和加特判可以$A$,更保险要脸的做法是双指针扫,因为前缀和单调不减. $code:$ 1 #include<bits/st ...
- 2021.9.17考试总结[NOIP模拟55]
有的考试表面上自称NOIP模拟,背地里却是绍兴一中NOI模拟 吓得我直接文件打错 T1 Skip 设状态$f_i$为最后一次选$i$在$i$时的最优解.有$f_i=max_{j<i}[f_j+a ...
- 2021.8.11考试总结[NOIP模拟36]
T1 Dove玩扑克 考场并查集加树状数组加桶期望$65pts$实际$80pts$,考后多开个数组记哪些数出现过,只扫出现过的数就切了.用$set$维护可以把被删没的数去掉,更快. $code:$ 1 ...
- 2021.7.29考试总结[NOIP模拟27]
T1 牛半仙的妹子图 做法挺多的,可以最小生成树或者最短路,复杂度O(cq),c是颜色数. 我考场上想到了原来做过的一道题影子,就用了并查集,把边权排序后一个个插入,记录权值的前缀和,复杂度mlogm ...
- 2021.7.15考试总结[NOIP模拟16]
ZJ模拟D2就是NB.. T1 Star Way To Heaven 谁能想到这竟是个最小生成树呢?(T1挂分100的高人JYF就在我身边 把上边界和下边界看成一个点和星星跑最小生成树,从上边界开始跑 ...
- 2021.9.14考试总结[NOIP模拟53]
T1 ZYB和售货机 容易发现把每个物品都买成$1$是没有影响的. 然后考虑最后一个物品的方案,如果从$f_i$向$i$连边,发现每个点有一个出度多个入度,可以先默认每个物品都能买且最大获利,这样可以 ...
- 2021.9.12考试总结[NOIP模拟51]
T1 茅山道术 仔细观察发现对于每个点只考虑它前面第一个与它颜色相同的点即可. 又仔细观察发现对一段区间染色后以这个区间内点为端点的区间不能染色. 于是对区间右端点而言,区间染色的贡献为遍历到区间左端 ...
- 2021.9.9考试总结[NOIP模拟50]
T1 第零题 神秘结论:从一个点满体力到另一个点的复活次数与倒过来相同. 于是预处理出每个点向上走第$2^i$个死亡点的位置,具体实现可以倍增或二分. 每次询问先从两个点同时向上倍增,都转到离$LCA ...
- 2021.9.7考试总结[NOIP模拟49]
T1 Reverse $BFS$暴力$O(n^2)$ 过程中重复枚举了很多点,考虑用链表记录当前点后面可到达的第一个未更新点. 搜索时枚举翻转子串的左端点,之后便可以算出翻转后$1$的位置. $cod ...
随机推荐
- footer沉底效果
介绍一个简单直接的方法: flex布局 heml,body{ height: 100%; min-height: 100%; display: flex; flex-direction: column ...
- RocketMQ详解(四)核心设计原理
专题目录 RocketMQ详解(一)原理概览 RocketMQ详解(二)安装使用详解 RocketMQ详解(三)启动运行原理 RocketMQ详解(四)核心设计原理 RocketMQ详解(五)总结提高 ...
- Tars | 第2篇 TarsJava SpingBoot启动与负载均衡源码初探
目录 前言 1. Tars客户端启动 @EnableTarsServer 2. Communicator通信器 3. 客户端的负载均衡调用器LoadBalance 最后 前言 通过源码分析可以得出这样 ...
- 离散化模板题 I ——重复元素离散化后的数字相同
离散化模板题 I --重复元素离散化后的数字相同 题目描述 现有数列A1, A2, ⋯, An,数列中可能有重复元素. 现在要求输出该数列的离散化数列,重复元素离散化后的数字相同. 输入 第一行,一 ...
- 3.17学习总结.listview用法总结
今天复习了listview控件的用法. 1.activity_main.xml 中的代码,如下: <?xml version="1.0" encoding="utf ...
- Elasticsearch(ES)的高级搜索(DSL搜索)(上篇)
1. 概述 之前聊了一下 Elasticsearch(ES)的基本使用,今天我们聊聊 Elasticsearch(ES)的高级搜索(DSL搜索),由于DSL搜索内容比较多,因此分为两篇文章完成. 2. ...
- Django学习day02随堂笔记
每日测验 """ 今日考题 1.谈谈你对web框架的认识,简述web框架请求流程 2.python三大主流web框架的区别 3.安装django需要注意的事项有哪些(最少 ...
- vs code安装leetcode插件
vs code 安装不成功啊 1.首先确保有node.js 10+,没有的话去官网下载,安装就可以,安装好之后在cmd命令行中输入: node -v 若出现相关版本信息说明安装成功 2.由于leetc ...
- 关于selenium中的三种等待方式与EC模块的知识
1. 强制等待 第一种也是最简单粗暴的一种办法就是强制等待sleep(xx),强制让闪电侠等xx时间,不管凹凸曼能不能跟上速度,还是已经提前到了,都必须等xx时间. 看代码: 1 2 3 4 5 6 ...
- Pycharm新建模板默认添加作者时间等信息(逼格更高,好像很历害的样子)
在pycharm使用过程中,关于代码编写者的一些个人信息快捷填写,使用模板的方式比较方便. 方法如下: 1.打开pycharm,选择File-Settings 2.选择Editor--Color&am ...