版本比较
大构交∩蕉(通信版)
正文
增加 212 行删除 11 行
1234567123422 行未改动2728293038313240333435363723 行未改动6162636472656667686970717273747576777879858081828384857 行未改动93949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302# 警告⚠️!!!下面有队✌️出没!# 本文包含内容:构造,交互,通信交互分两种,函数式(grader)和 IO式。## 函数交互### [P15652 Perm](https://www.luogu.com.cn/problem/P15652)22 行未改动
然后你发现,这个同样适用于本地测试 SPJ。## IO 交互### [CF727C Guess the Array](https://www.luogu.com.cn/problem/CF727C)
::::info[做法]非常简单的解方程,问 $a_1+a_2$,$a_2+a_3$,$a_1+a_3$,然后作差就知道 $a_1,a_2,a_3$ 的值了,然后任选一个和后面的一直问下去就没了。
::::## 下面是一些选题### [P17055 ](https://www.luogu.com.cn/problem/P17055)::::info[形式化题意]有一个由 $n$ 节车厢组成的环,满足23 行未改动```::::### [P12822 ](https://www.luogu.com.cn/problem/P12822)::::info[做法]# [Fire_flys 是队✌](https://www.luogu.com.cn/article/xdmaujn5)# [](https://www.luogu.com.cn/article/xdmaujn5)::::### [P17140 ](https://www.luogu.com.cn/problem/P17140)::::info[做法]1. 分析树的性质2. 画图感知状态3. 设计DP4. 卡常5. 膜拜这个人::::## 通信### [AT_stpc2025_1_k Two-Way Communication](https://www.luogu.com.cn/problem/AT_stpc2025_1_k)
### 然后是一点点私货::::info[我是哈希]### [P8868](https://www.luogu.com.cn/problem/P8868)::::info[我是哈希]```cppstruct custom_hash { static constexpr ull P = (1ULL << 61) - 1; static ull rnd() {7 行未改动 }};```::::::::info[8分]```cpp#include<bits/stdc++.h>using namespace std;#define int long long#define ull unsigned long long#define F(i,a,b) for(int i=(a);i<=(b);i++)#define DF(i,a,b) for(int i=(a);i>=(b);i--)#define pt array<int,2>const int N=2.5e5+5,B=500;int T,n,Q,a[N],b[N],lg[N];pt sta[20][N],stb[20][N];pt aska(int l,int r){ int k=lg[r-l+1]; return max(sta[k][l],sta[k][r-(1<<k)+1]);}pt askb(int l,int r){ int k=lg[r-l+1]; return max(stb[k][l],stb[k][r-(1<<k)+1]);}ull solve(int l,int r){ if(l>r)return 0; if(r-l+1<=B){ ull res=0; F(L,l,r){ int ma=0,mb=0; F(R,L,r){ ma=max(ma,sta[0][R][0]); mb=max(mb,stb[0][R][0]); res+=(ull)ma*mb; } } return res; } auto [v1,p1]=aska(l,r); auto [v2,p2]=askb(l,r); if(p1>p2)swap(p1,p2); ull res=v1*v2*(p1-l+1)*(r-p2+1)+solve(l,p2-1)-solve(p1+1,p2-1)+solve(p1+1,r); return res;}signed main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>T>>n; F(i,1,n)cin>>sta[0][i][0],sta[0][i][1]=i; F(i,1,n)cin>>stb[0][i][0],stb[0][i][1]=i; F(i,2,n)lg[i]=lg[i>>1]+1; F(j,1,19)for(int i=1;i+(1<<j)-1<=n;i++)sta[j][i]=max(sta[j-1][i],sta[j-1][i+(1<<(j-1))]),stb[j][i]=max(stb[j-1][i],stb[j-1][i+(1<<(j-1))]); cin>>Q; F(i,1,Q){ int l,r;cin>>l>>r; cout<<solve(l,r)<<"\n"; } return 0;}```::::::::info[36]```cpp#include<bits/stdc++.h>#include <ext/pb_ds/assoc_container.hpp>#include <ext/pb_ds/hash_policy.hpp>using namespace std;using namespace __gnu_pbds;#define ll long long#define ull unsigned long long#define F(i,a,b) for(int i=(a);i<=(b);i++)#define DF(i,a,b) for(int i=(a);i>=(b);i--)#define vi vector<int>#define pt array<int,2>gp_hash_table<ull,ull>mp;const int N=2.5e5+5,M=1e9;int T,n,Q,a[N],b[N],lg[N],B;vector<vector<ull>>f;pt sta[19][N],stb[19][N];pt aska(int l,int r){ int k=lg[r-l+1]; return max(sta[k][l],sta[k][r-(1<<k)+1]);}pt askb(int l,int r){ int k=lg[r-l+1]; return max(stb[k][l],stb[k][r-(1<<k)+1]);}ull solve(int l,int r){ if(l>r)return 0; if(r-l+1<=B)return f[l][r-l+1]; ull ky=((ull)l<<32)|r; if(mp.find(ky)!=mp.end())return mp[ky]; auto [v1,p1]=aska(l,r); auto [v2,p2]=askb(l,r); if(p1>p2)swap(p1,p2); ull res=(ull)v1*v2*(p1-l+1)*(r-p2+1)+solve(l,p2-1)-solve(p1+1,p2-1)+solve(p1+1,r); return mp[ky]=res;}signed main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>T>>n; B=sqrt(M/n); f.resize(n+1,vector<ull>(B+1)); F(i,1,n)cin>>sta[0][i][0],sta[0][i][1]=i; F(i,1,n)cin>>stb[0][i][0],stb[0][i][1]=i; F(l,1,n){ vi ma(B+2),mb(B+2);ull now=0; F(r,l,n){ if(r-l+1>B)break; int len=r-l+1; F(L,l,r){ int id=L-l+1; ma[id]=max(ma[id],sta[0][r][0]); mb[id]=max(mb[id],stb[0][r][0]); } F(i,1,len)now+=(ull)ma[i]*mb[i]; f[l][len]=now; } } F(i,2,n)lg[i]=lg[i>>1]+1; F(j,1,18)for(int i=1;i+(1<<j)-1<=n;i++)sta[j][i]=max(sta[j-1][i],sta[j-1][i+(1<<(j-1))]),stb[j][i]=max(stb[j-1][i],stb[j-1][i+(1<<(j-1))]); cin>>Q; F(i,1,Q){ int l,r;cin>>l>>r; cout<<solve(l,r)<<"\n"; } return 0;}```::::::::info[52]```cpp#include<bits/stdc++.h>#include <ext/pb_ds/assoc_container.hpp>#include <ext/pb_ds/hash_policy.hpp>using namespace std;using namespace __gnu_pbds;#define ll long long#define ull unsigned long long#define F(i,a,b) for(int i=(a);i<=(b);i++)#define DF(i,a,b) for(int i=(a);i>=(b);i--)#define vi vector<int>#define pt array<int,2>struct custom_hash { static constexpr ull P = (1ULL << 61) - 1; static ull rnd() { static mt19937_64 rng(time(0)); return rng(); } size_t operator()(ull x) const { static const ull a = rnd() % (P - 1) + 1; static const ull b = rnd() % P; return (size_t)(((__uint128_t)(x % P) * a + b) % P); }};gp_hash_table<ull,ull,custom_hash>mp;const int N=2.5e5+5,M=1e9;int T,n,Q,a[N],b[N],lg[N],B;vector<vector<ull>>f;pt sta[19][N],stb[19][N];pt aska(int l,int r){ int k=lg[r-l+1]; return max(sta[k][l],sta[k][r-(1<<k)+1]);}pt askb(int l,int r){ int k=lg[r-l+1]; return max(stb[k][l],stb[k][r-(1<<k)+1]);}ull solve(int l,int r){ if(l>r)return 0; if(r-l+1<=B)return f[l][r-l+1]; ull ky=((ull)l<<32)|r; if(mp.find(ky)!=mp.end())return mp[ky]; auto [v1,p1]=aska(l,r); auto [v2,p2]=askb(l,r); if(p1>p2)swap(p1,p2); ull res=(ull)v1*v2*(p1-l+1)*(r-p2+1)+solve(l,p2-1)-solve(p1+1,p2-1)+solve(p1+1,r); return mp[ky]=res;}signed main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>T>>n; B=sqrt(M/n); f.resize(n+1,vector<ull>(B+1)); F(i,1,n)cin>>sta[0][i][0],sta[0][i][1]=i; F(i,1,n)cin>>stb[0][i][0],stb[0][i][1]=i; F(l,1,n){ vi ma(B+2),mb(B+2);ull now=0; F(r,l,n){ if(r-l+1>B)break; int len=r-l+1; F(L,l,r){ int id=L-l+1; ma[id]=max(ma[id],sta[0][r][0]); mb[id]=max(mb[id],stb[0][r][0]); } F(i,1,len)now+=(ull)ma[i]*mb[i]; f[l][len]=now; } } F(i,2,n)lg[i]=lg[i>>1]+1; F(j,1,18)for(int i=1;i+(1<<j)-1<=n;i++)sta[j][i]=max(sta[j-1][i],sta[j-1][i+(1<<(j-1))]),stb[j][i]=max(stb[j-1][i],stb[j-1][i+(1<<(j-1))]); cin>>Q; F(i,1,Q){ int l,r;cin>>l>>r; cout<<solve(l,r)<<"\n"; } return 0;}```::::