版本比较
2024暑期模拟赛总结
正文
增加 77 行删除 77 行
24 行未改动2526272829293031323342 行未改动767778798080818283846 行未改动9192939495959697989971 行未改动17117217317417517517617717817915 行未改动1951961971981991992002012022039 行未改动21321421521621721721821922022169 行未改动29129229329429529529629729829969 行未改动369370371372373373374375376377188 行未改动全部展开5665675685695705705715725735747 行未改动58258358458558658658758858959039 行未改动63063163263363463463563663663763863964064164264364364464564664764664764864965065112 行未改动66466566666766866866967067167259 行未改动7327337347357367367377387397402 行未改动743744745746747747748749750751108 行未改动全部展开86086186286386486486586686786865 行未改动93493593693793893893994094194235 行未改动978979980981982982983984985986117 行未改动全部展开110411051106110711081108110911101111111238 行未改动115111521153115411551155115611571158115998 行未改动12581259126012611262126212631264126512665 行未改动127212731274127512761276127712781279128092 行未改动137313741375137613771377137813791380138120 行未改动140214031404140514061406140714081409141055 行未改动146614671468146914701470147114721473147439 行未改动151415151516151715181518151915201521152216 行未改动1539154015411542154315431544154515461547158 行未改动全部展开1706170717081709171017101711171217131714120 行未改动全部展开18351836183718381839183918401841184218421843184418451846303 行未改动全部展开215021512152215321542154215521562157215813 行未改动2172217321742175217621762177217821792180291 行未改动全部展开24722473247424752476247624772478247924803 行未改动2484248524862487248824882489249024912492105 行未改动全部展开25982599260026012602260226032604260526066 行未改动2613261426152616261726172618261926202621112 行未改动全部展开273427352736273727382738273927402741274214 行未改动275727582759276027612761276227632764276547 行未改动281328142815281628172818281928172818281928202821282228238 行未改动283228332834283528362836283728382839284029 行未改动2870287128722873287428742875287628772878108 行未改动全部展开2987298829892990299129912992299329942995132 行未改动全部展开312831293130313131323132313331343135313649 行未改动31863187318831893190319031913192319331943195319631953196319731983199320052 行未改动325332543255325632573258325932603261325732583259326032613262326332643265326332643265326632673268326919 行未改动32893290329132923293329432933294329532963296329732983299330033013301330233033304330533063306330733083309331033113311331233133314331512 行未改动332833293330333133323332333333343335333616 行未改动335333543355335633573357335833593360336172 行未改动34343435343634373438343834393440344134423 行未改动3446344734483449345034503451345234533454198 行未改动全部展开3653365436553656365736573658365936603661200 行未改动全部展开386238633864386538663866386738683869387068 行未改动393939403941394239433943394439453946394763 行未改动401140124013401440154015401640174018401932 行未改动405240534054405540564057405640574058405940604061129 行未改动全部展开419141924193419441954195419641974198419942004201420242034203420442054206420771 行未改动24 行未改动总结:暴力写的太弱了,T3、T4写不出正解,暴力一分没捞到。T2结论猜的过于自信,没有多多考虑,比较可惜。
反思:多打暴力,对于猜想结论学会手搓样例。
#### T1 #### T1
简化题意:
给定 $n$ 首歌曲和对应时间,循环播放,问经过 $t$ 个单位时间后在播放那首歌曲和距离当前歌曲结束还有多长时间。42 行未改动 idx = d[now.t]; break; } else{ if(!d[now.t+a[idx]]) d[now.t+a[idx]] = ++tot; if(!d[now.t+a[idx]]) d[now.t+a[idx]] = ++tot; //cout<<tot<<endl; s[d[now.t+a[idx]]].insert(d[now.t]); now.t+=a[idx]; q.pop();6 行未改动 return 0;}```
#### [T3](https://www.luogu.com.cn/problem/P7114) #### [T3](https://www.luogu.com.cn/problem/P7114)
~~(7.20挖坑,还没补,字符串太菜了)~~(7.21补坑,顺便打算开个字符串的坑)
简化题意71 行未改动```
Ex-kmp : (7.21 挖坑,还没学,8.10把坑挖深一些)
#### [T4](https://www.luogu.com.cn/problem/P7519) #### [T4](https://www.luogu.com.cn/problem/P7519)
题意:
ICPC 竞赛滚榜环节,竞赛共有 $n$ 支队伍参赛,$i$ 号队伍在封榜前通过的题数为 $a_i$。排行榜上队伍按照过题数从大到小进行排名,若两支队伍过题数相同,则编号小的队伍排名靠前。15 行未改动int n,m;int a[N],c[N][N],f[1<<N][N][M],id[1<<N],ans,mx,all;int popcount(int x){ int tot = 0; while(x){tot++;x -= x&(-x);} while(x){tot++;x -= x&(-x);} return tot;}signed main(){ ios::sync_with_stdio(false);9 行未改动 for(int j = 1;j<=n;j++) c[i][j] = max(0ll,a[i]-a[j]+(i<j)); for(int i = 1;i<=n;i++){ int d = n*(a[mx]-a[i]+(mx<i)); if(d<=m) f[1<<(i-1)][i][d] = 1; if(d<=m) f[1<<(i-1)][i][d] = 1; } for(int S = 0;S<=all;S++){ int cnt = popcount(S); for(int t = S;t;t-=(t&(-t))){69 行未改动 int cnt = d[i]*j; for(int k = 0;k<=m-cnt;k++){ f[i][j][k+cnt] = ((long long)(f[i][j][k+cnt]%M+(long long)f[i-1][j][k]*(j+1)%M)+M)%M; if(j != n) f[i][j+1][k+cnt] = ((long long)(f[i][j+1][k+cnt]%M+f[i-1][j][k]%M)+M)%M; if(j != 0) f[i][j-1][k+cnt] = ((long long)(f[i][j-1][k+cnt]%M+((long long)f[i-1][j][k]*j)%M)+M)%M; if(j != 0) f[i][j-1][k+cnt] = ((long long)(f[i][j-1][k+cnt]%M+((long long)f[i-1][j][k]*j)%M)+M)%M; } } } for(int i = 0;i<=m;i++) ans = ((long long)ans+f[n][0][i]%M+M)%M;69 行未改动int c[N],d[N],a[N];bool vis[N],vis1,vis2;struct edge{int v,w;};vector<edge> g[N];queue<int> q; queue<int> q;void bfs(int s){ for(int i = 1;i<=n;i++) d[i] = inf; d[s] = 1; q.push(s);188 行未改动全部展开首先考虑操作2(比较简单),记录下最后一次(对于当前而言的)操作2的时间,再为操作1的对应节点打上时间戳,操作3判断即可。
然后考虑操作1,从 $x$ 先上跳祖先,如果祖先没被标记,则记录其标记时间($dis[x][j]+i$,即到祖先的距离+当前时间,前一项在建树期间预处理)
操作3几乎等同操作1,跳祖先,如果每个祖先标记时间加上传递时间 $(dis[x][j]+d[u]\le i)$ 则“Yes”,否则“No” 操作3几乎等同操作1,跳祖先,如果每个祖先标记时间加上传递时间 $(dis[x][j]+d[u]\le i)$ 则“Yes”,否则“No”
一些解释:点分树与原树形态几乎没什么关系,父子关系几乎崩坏,当然修改过程中原树形态不变故点分树形态不变。
那么这棵点分树对于我们做题有什么帮助呢?7 行未改动有一说一:这好像是讲的最多的一题。
```cpp#include<bits/stdc++.h>#define int long long #define int long long
using namespace std;
const int N = 1e5+10;39 行未改动
signed main(){ ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
cin>>n>>m;
for(int i = 1;i<n;i++){ int u,v; cin>>u>>v; g[u].push_back(v); g[v].push_back(u); }
a[rt] = sum = n; getrt(1,0); build(rt); build(rt);
memset(d,63,sizeof(d)); for(int i = 1;i<=n;i++) reverse(dis[i].begin(),dis[i].end()); for(int i = 1;i<=m;i++){ cin>>op>>x;12 行未改动 } cout<<(ans?"wrxcsd":"orzFsYo")<<endl; } }
return 0;}```“-------------------------------------------------------------------(分割线)”59 行未改动}int find(int x){ if(x != f[x]) f[x] = find(f[x]); return f[x];} }
void merge(int x,int y){ //x = find(x); y = find(y); f[x] = y;2 行未改动 pb[y]+=pb[x];}
signed main(){
cin>>n; for(int i = 1;i<n;i++){ cin>>u>>v; add_edge(u,v); add_edge(v,u);} for(int i = 1;i<=n;i++) f[i] = i; dfs(1,0);108 行未改动全部展开 for(int i = 1;i<=cnt;i++){ while(idx<=n && a[idx].s == p[i].id){ if(vis[i] == 1){ cout<<a[idx].id<<" "; } } idx++; } } return 0;65 行未改动~~如果以后看不懂,参照代码理解。~~
```cpp#include<bits/stdc++.h>#define int long long #define int long longusing namespace std;const int N = 5e5+10;const int M = 1e9+7;int n,m,l,r,k,a[N],b[N],c[N],ans,tot,cnt,s[N];35 行未改动具体的,预处理每条边经过的次数(两个端点为根的子树中关键点乘积),再统计下每个点所连边的次数总和即可。实现上注意排列和逆元。
```cpp#include<bits/stdc++.h>#define int long long #define int long longusing namespace std;const int N = 5e5+10;const int M = 998244353;int n,m,x,k,deep[N],d[N],f[N],ans,q,inv,p[N];117 行未改动全部展开 if(x<0) return 0; long long cnt = query(x); for(int i = 1;i<=B;i++){ cnt+=(x/i)*d[i][i-1]; cnt+=d[i][x-(x/i)*i]; cnt+=d[i][x-(x/i)*i]; } return cnt;}int main(){38 行未改动好像有跟简单易懂~~暴力~~的做法,以后补。
---
### TY-ICPC-Round1 2024.8.7 ### TY-ICPC-Round1 2024.8.7
(8.7 挖坑,实在太多了)
躺平的一场,也没人带飞qwq98 行未改动 dep[u] = dep[fa]+1; cnt[dep[u]]++; md = max(md,dep[u]); for(auto v:g[u]) if(v != fa) if(v != fa) dfs(v,u);}signed main(){ scanf("%lld",&n);5 行未改动 for(int j = 1;j<=n;j++) f[j] = s[j] = 0; dep[u] = 0; for(auto v:g[u]){ for(int i = 1;i<=md;i++) cnt[i] = 0; md = 0; md = 0; dfs(v,u); for(int i = 1;i<=md;i++){ ans+=s[i]*cnt[i]; s[i]+=f[i]*cnt[i];92 行未改动
signed main(){ scanf("%s",s+1); n = strlen(s+1); f[1][0] = 0; f[1][0] = 0; f[1][1] = 1; f[1][2] = s[1]-'0'; /* f[i][0] 表示当前的完成计算的各个积式,即...*...+...*...*...20 行未改动 f[i][1] = f[i-1][2]; f[i][2] = 0; } } printf("%lld",ans); printf("%lld",ans); return 0;}```
55 行未改动 // * f[i][0] += f[i-1][0]; f[i][1] += f[i-1][2]; f[i][2] += f[i-1][2]*a;
//inv; f[i][0] = (f[i][0]*inv)%M; f[i][1] = (f[i][1]*inv)%M; f[i][2] = (f[i][2]*inv)%M;39 行未改动queue<node> q;signed main(){ freopen("boundary.in","r",stdin); freopen("boundary.out","w",stdout); scanf("%lld%lld%lld",&n,&m,&k); scanf("%lld%lld%lld",&n,&m,&k); for(int i = 1;i<=k;i++) scanf("%lld%lld",&x,&y),q.push(node{x,y,0,i}),vis[x][y] = pt{0,i},Vis[x][y] = 2; scanf("%lld",&Q); for(int i = 1;i<=Q;i++) scanf("%lld%lld",&x,&y),mp[x][y] = -1; while(q.size()){16 行未改动 if(mp[i][j] == 2) ans++; } } printf("%lld",ans); return 0; return 0;}```
#### T2:[题面](https://oiclass.com/d/tigao/p/41)158 行未改动全部展开 int cnt = s1[v]+w; if(cnt>s1[u]){ s2[u] = s1[u]; s1[u] = cnt; p2[u] = p1[u]; p2[u] = p1[u]; p1[u] = v; } else if(cnt>s2[u]){ s2[u] = cnt;120 行未改动全部展开 rep(i,1,n-1){ cin>>u>>v>>w; add_edge(u,v,w);} dfs(1,0); maxd = -1; rep(i,1,n) if(maxd<d[i]){maxd = d[i],L = i;} a.d[L] = 0; a.dfs(L,0); a.d[L] = 0; a.dfs(L,0); maxd = -1; rep(i,1,n) if(maxd<a.d[i]){maxd = a.d[i],R = i;} b.d[R] = 0; b.dfs(R,0); b.d[R] = 0; b.dfs(R,0); a.init(); b.init(); a.getans(L,L); b.getans(R,R); rep(i,1,n) cout<<max(a.ans[i],b.ans[i])<<'\n'; return 0;303 行未改动全部展开 f[1] = d[3][1];f[2] = d[4][1];f[3] = d[6][3];f[4] = d[6][4];f[5] = d[3][6];f[6] = d[4][6];f[7] = d[1][3];f[8] = d[1][4];d[6][3] = f[1];d[6][4] = f[2];d[4][6] = f[3];d[3][6] = f[4];d[1][3] = f[5];d[1][4] = f[6];d[4][1] = f[7];d[3][1] = f[8]; xz(3,7,0); } } } } check();}int main(){ dfs(1);cin>>t;cnt = tot;13 行未改动 } n = 6,m = 8;vis1 = vis2 = 0; while(tot){ for(int i = 1;i<=n;i++) for(int j =1 ;j<=m;j++) for(int j =1 ;j<=m;j++) d[i][j] = c[i][j]; work();tot--; if(vis1){cout<<"No problem"<<'\n';break;} if(vis2){cout<<ans1<<" "<<ans2<<" "<<ans3<<'\n';break;}291 行未改动全部展开 B = ceil(sqrt(n)); rep(i,0,n-1){ if(!dis[i]) continue; b[dis[i]/B].push_back(i); d[dis[i]%B].push_back(i); d[dis[i]%B].push_back(i); } for(int i = B-1;i>=0;i--){ if(b[i].size()){ tot+=b[i].size();3 行未改动 if(i){ if(!tot) continue; ans[++cnt].push_back(3); ans[cnt].push_back(B); } } } rep(i,0,B-1){ if(i){ if(!tot) continue;105 行未改动全部展开 mw = w; ans[u] = ((ans[v]+w)*29)%M; } if(dis[v]>mdis){ mdis = dis[v]; mdis = dis[v]; mw = w; ans[u] = ((ans[v]+w)*29)%M; } }6 行未改动 scanf("%lld%lld",&n,&m); for(int i = 1;i<=m;i++){ scanf("%lld%lld%lld",&u,&v,&w); Q[i] = edge{v,w,u}; } } sort(Q+1,Q+1+m,cmp); for(int i = 1;i<=m;i++){ if(Q[i].u == Q[i-1].u && Q[i].to == Q[i-1].to) continue; else g[Q[i].u].push_back(edge{Q[i].to,Q[i].w,0}),f[Q[i].to].push_back(Q[i].u),in[Q[i].u]++;112 行未改动全部展开 gep_g(_,u){ int v = _.to,w = _.w; if(dp[v] == dp[u]-1 && mw == w && mx == rk[v]){ ans[u] = (ans[v]+w)*29%M; //cout<<u<<" "<<v<<" "<<ans[u]<<" "<<ans[v]<<" "<<w<<endl; //cout<<u<<" "<<v<<" "<<ans[u]<<" "<<ans[v]<<" "<<w<<endl; q.push(node{w,rk[v],u}); break; } }14 行未改动#### T3:[题面](https://oiclass.com/d/tigao/p/59)
最难绷的一题,花了2h啥也没有
**暴力死因**:忽略了 $t_i$ 的限制,挂于 $t_i = 0$ **暴力死因**:忽略了 $t_i$ 的限制,挂于 $t_i = 0$
30pts
```cpp47 行未改动手玩样例的链容易发现,随操作时间增加,系数分布情况如上图杨辉三角(说实在真难发现)
注意此处从上往下行的编号和从左往右列的编号( $C_{n}^{r}$ 中的 $n$ 和 $r$ )从 $0$ 开始
那么可以推出具体的系数为$a_i = \begin{pmatrix} x+d_i-2 \\ d_i-1 那么可以推出具体的系数为$a_i = \begin{pmatrix} x+d_i-2 \\ d_i-1\end{pmatrix} $ , 由于异或的性质,此处不考虑系数具体取值,仅考虑其奇偶性即可。
由此引入[**卢卡斯定理**](https://oi-wiki.org/math/number-theory/lucas/) && [**Lucas Theorem板子题**](https://www.luogu.com.cn/problem/P3807)
8 行未改动推一下其实就是 (n-r) & r = 0,对应的就是$(d_i-1 )AND (x-1) = 0$
这是题目第一个难点
接下来考虑统计,对于每个深度先求异或和,再对时间 $t[i]$ 求其补集的所有子集和 接下来考虑统计,对于每个深度先求异或和,再对时间 $t[i]$ 求其补集的所有子集和
关于子集遍历:
29 行未改动
A是B的子集,B是A的超集。
```cppfor(int i = 0; i < n; i++) for(int i = 0; i < n; i++) for(int j = 0; j < 1 << n; j++) if(!(j >> i & 1)) f[j] += f[j ^ (i << j)];```
108 行未改动全部展开枚举 $a[i]$ , 算出它的补集,按位从大往小取,如果一个集合的超集中下标第二大的元素下标 $>i$ 则可取。
```cpp#include<bits/stdc++.h>#define int long long #define int long long#define rep(i,a,b) for(int i = (a);i<=(b);i++)using namespace std;const int N = 3e6+10;int n,a[N],ans,S;132 行未改动全部展开}```---
### TY-ICPC-Round3 2024.8.14 ### TY-ICPC-Round3 2024.8.14
躺平的一场,以后再说。
---49 行未改动 }*/ ans = 1; /*rep(i,1,n){ if(a[i] == 2*top) ans = (ans*(top+1)%M)%M,top--; top++; top++; } rep(i,1,top) ans = (ans*i)%M;*/ rep(i,1,n){ if(st.size() && a[i] == st.top()+1){ ans = (ans*(st.size()+1)%M)%M; } ans = (ans*(st.size()+1)%M)%M; } else{ if(!(a[i]&1)) a[i]--; st.push(a[i]); }52 行未改动
给定一个$[1,n]$的排列,依照下面的代码运行
```cppwhile (1) { for (int j = 1; j < n; j ++) { if (a[j] > a[j + 1]) { swap(a[j], a[j + 1]); } while (1) { for (int j = 1; j < n; j ++) { if (a[j] > a[j + 1]) { swap(a[j], a[j + 1]); } } if (a[n] > a[1]) { // 正常的冒泡排序没有这个if swap(a[n], a[1]); } if (a[n] > a[1]) { // 正常的冒泡排序没有这个if swap(a[n], a[1]); }}```
将初始数组 $a[1...n]$ 称为一个版本,之后每次执行 $swap$ 之后的数组作为一个新的版本,求可能出现的本质不同的版本数量。19 行未改动 rep(i,1,n) scanf("%lld",&a[i]); rep(i,1,n) d[i] = rnd(),cnt = (cnt+d[i]*a[i]); mp[cnt] = 1,ans = 1; while(1){ rep(i,1,n-1){ if(a[i]>a[i+1]){ rep(i,1,n-1){ if(a[i]>a[i+1]){ cnt = (cnt-(a[i+1]*d[i+1]+a[i]*d[i])); swap(a[i],a[i+1]); swap(a[i],a[i+1]); cnt = (cnt+(a[i+1]*d[i+1]+a[i]*d[i])); if(mp[cnt]){vis = 1;break;} else mp[cnt] = 1; ans++; } } } if(vis) break; if(a[n]>a[1]){ cnt = (cnt-(a[n]*d[n]+a[1]*d[1])); swap(a[n], a[1]); swap(a[n], a[1]); cnt = (cnt+(a[n]*d[n]+a[1]*d[1])); if(mp[cnt]){vis = 1;break;} else mp[cnt] = 1; ans++; } } if(vis) break; } printf("%lld",ans); return 0;12 行未改动
对于 $n \ge 3$ 而言,假设有一种情况在前后都出现:
1) 如果 $n$ 在初始状态不在末尾,除开 $n$ 的数构成的环不同,故无需去重
2) 如果 $n$ 在初始状态的末尾,那么在遇到 $n$ 之前,$n-1$ 肯定会搬到 $n-1$ 的位置,如果 $n-1$ 不在首项,那环的形态仍然会变,如果在首项则会有一次重合。
综上:$ans = 第一轮遇到n前swap的次数+n(n-1)-[n \ge 3 且 a[1] = n-1 且 a[n] = n]$
16 行未改动 swap(a[i],a[i+1]); ans++; } } ans+=(n-1)*n; ans+=(n-1)*n; printf("%lld",ans); return 0;}```72 行未改动 //freopen("run.in","r",stdin); //freopen("run.out","w",stdout); ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cin>>n>>m; cin>>n>>m; rep(i,1,n) rep(j,1,m){ cin>>c; if(c == '#') l[i][j] = i;3 行未改动 rep(j,1,m){ cnt = 0,idx = 0; for(int k = j;k>=1;k--){ if(l[i][k] == i) break; else idx = max(idx,l[i][k]),cnt = max(cnt,i-(idx+1)+1+(j-k+1)); else idx = max(idx,l[i][k]),cnt = max(cnt,i-(idx+1)+1+(j-k+1)); } ans[cnt]++; } }*/198 行未改动全部展开 while(q.size()){ int now = q.front(); q.pop(); G[now] = ((~(g[now]&T))&g[now]); for(int j = G[now]._Find_first();j!=(int)G[now].size();j = G[now]._Find_next(j)) for(int j = G[now]._Find_first();j!=(int)G[now].size();j = G[now]._Find_next(j)) q.push(j),T[j] = 1,e[++cnt].u = now,e[cnt].v = j; } tot = 0; rep(j,1,n) Vis[j] = 0;200 行未改动全部展开
```cpp#include<bits/stdc++.h>#define int long long #define int long long#define rep(i,a,b) for(int i = (a);i<=(b);i++)using namespace std;const int N = 1e5+10;int n,k,ans;68 行未改动显然的,有前缀和优化。
```cpp#include<bits/stdc++.h>#define int long long #define int long long#define rep(i,a,b) for(int i = (a);i<=(b);i++)using namespace std;const int N = 306;const int M = 998244353;63 行未改动不太懂早上在干啥,可能是太久没吃早饭,真饿了QwQ
```cpp#include<bits/stdc++.h>#define int long long #define int long long#define rep(i,a,b) for(int i = (a);i<=(b);i++)using namespace std;const int N = 1e6+10;const int M = 998244353;32 行未改动一眼二分,然后没了
```cpp#include<bits/stdc++.h>#define int long long #define rep(i,a,b) for(int i = (a);i<=(b);i++) #define int long long#define rep(i,a,b) for(int i = (a);i<=(b);i++)#define gep(v,u) for(auto v:g[u])using namespace std;const int N = 1e5+10;int n,m,S,l,r,ans,u,v,w;129 行未改动全部展开然后差不多就会了,一个点出现在虚树上只有两种可能,它自己被选上了或者有至少两个不在同一子树的儿子被选中(即作为LCA)。
分讨一下:
第一类:显然就是题目所给概率 $p_i$ 第一类:显然就是题目所给概率 $p_i$
第二类:直接不好求,考虑从反面来,因为至少两个不在同一子树的子节点,所以要么所选的点在同一子树,要么一个不选。(预处理即可)
mxz说卡逆元,不懂。
```cpp#include<bits/stdc++.h>#define int long long #define int long long#define rep(i,a,b) for(int i = (a);i<=(b);i++)#define gep(v,u) for(auto v:g[u])using namespace std;const int N = 1e5+10;71 行未改动