WY模拟赛13
WY模拟赛13
T1. 洛谷 P12197 Hash Killer I
逆天神仙题。
那么输出长度大于等于 $ 2^{11} $ 的 $ Thue Morse $ 序列即可。
code:
#include <bits/stdc++.h>
#define i8 __int128
#define int long long
#define fuck inline
#define lb long double
using namespace std;
// typedef long long ll;
const int N=5e5+5,M=64,mod=1e9+7;
const int INF=1e9+7;
const int inf=LONG_LONG_MAX/4;
// const int mod1=469762049,mod2=998244353,mod3=1004535809;
// const int G=3,Gi=332748118;
// const int M=mod1*mod2;
fuck int read()
{
int x=0,f=1;
char c=getchar();
while(c<'0'||c>'9'){if(c=='-'){f=-1;}c=getchar();}
while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+(c-'0');c=getchar();}
return x*f;
}
fuck void write(int x)
{
if(x<0){putchar('-');x=-x;}
if(x>9) write(x/10);
putchar(x%10+'0');
}
int n,l;
fuck void solve()
{
n=1<<12,l=n>>1;
cout<<n<<" "<<l<<endl;
for(int i=0;i<n;i++)cout<<(char)('a'+(__builtin_popcount(i)&1));
}
signed main()
{
// ios::sync_with_stdio(false);
// cin.tie(0); cout.tie(0);
// int QwQ=read();
// int fuckccf=read();
// while(QwQ--)solve();
solve();
return 0;
}
// 6666 66666 666666
// 6 6 6 6 6
// 6 6 6666 6
// 6 6 6 6 6
// 6666 6 6 6666666
T2. 洛谷 P1377 [TJOI2011] 树的序
以权重为第一键值,下标为第二键值,跑一遍笛卡尔树,然后输出中序即可。
#include <bits/stdc++.h>
#define i8 __int128
#define int long long
#define fuck inline
#define lb long double
using namespace std;
// typedef long long ll;
const int N=3e5+5,M=64,mod=536870912;
const int INF=1e9+7;
const int inf=LONG_LONG_MAX/4;
// const int mod1=469762049,mod2=998244353,mod3=1004535809;
// const int G=3,Gi=332748118;
// const int M=mod1*mod2;
fuck int read()
{
int x=0,f=1;
char c=getchar();
while(c<'0'||c>'9'){if(c=='-'){f=-1;}c=getchar();}
while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+(c-'0');c=getchar();}
return x*f;
}
fuck void write(int x)
{
if(x<0){putchar('-');x=-x;}
if(x>9) write(x/10);
putchar(x%10+'0');
}
int n,ls[N],rs[N];
struct node
{
int key,val;
}a[N],b[N];
stack<int>s;
fuck bool cmp(node a,node b){return a.val<b.val;}
fuck void build()
{
for(int i=1;i<=n;i++)
{
while(!s.empty()&&a[s.top()].val>a[i].val)
{
ls[i]=s.top();
s.pop();
}
if(!s.empty())rs[s.top()]=i;
s.push(i);
}
}
int vis[N];
vector<int>ans;
fuck void dfs(int u)
{
if(!vis[u])ans.push_back(u),vis[u]=1;
if(ls[u])dfs(ls[u]);
if(rs[u])dfs(rs[u]);
}
int root=0,vmin=inf;
fuck void solve()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>b[i].val;
b[i].key=i;
}
sort(b+1,b+n+1,cmp);
for(int i=1;i<=n;i++)
{
a[i].key=b[i].val,a[i].val=b[i].key;
if(vmin>a[i].val)vmin=a[i].val,root=i;
}
// for(int i=1;i<=n;i++)cout<<a[i].key<<" "<<a[i].val<<endl;
// cout<<"ccccccccccccccc"<<endl;
build();
// cout<<"aaaaaaaaaaaaaa"<<endl;
// for(int i=1;i<=n;i++)cout<<ls[i]<<" "<<rs[i]<<endl;
dfs(root);
// cout<<"bbbbbbbbbbbbbbbb"<<endl;
for(auto v:ans)cout<<v<<" ";
}
signed main()
{
// ios::sync_with_stdio(false);
// cin.tie(0); cout.tie(0);
// int QwQ=read();
// int fuckccf=read();
// while(QwQ--)solve();
solve();
return 0;
}
// 6666 66666 666666
// 6 6 6 6 6
// 6 6 6666 6
// 6 6 6 6 6
// 6666 6 6 6666666
T3. 洛谷 P12194 [NOISG 2025 Prelim] Snacks
平衡树维护一下。一年没写忘光了。
#include <bits/stdc++.h>
#define i8 __int128
#define int long long
#define fuck inline
#define lb long double
using namespace std;
// typedef long long ll;
const int N=1e6+5,M=64,mod=1e9+7;
const int INF=1e9+7,inv2=5e8+4;
const int inf=LONG_LONG_MAX/4;
// const int mod1=469762049,mod2=998244353,mod3=1004535809;
// const int G=3,Gi=332748118;
// const int M=mod1*mod2;
fuck int read()
{
int x=0,f=1;
char c=getchar();
while(c<'0'||c>'9'){if(c=='-'){f=-1;}c=getchar();}
while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+(c-'0');c=getchar();}
return x*f;
}
fuck void write(int x)
{
if(x<0){putchar('-');x=-x;}
if(x>9) write(x/10);
putchar(x%10+'0');
}
int n,q;
int tot,root,sx,sy,sz;
struct node
{
int ls,rs;
int cnt,rnd;
int val,sum,sz;
}p[N];
fuck int newnode(int x,int res)
{
p[++tot].val=x;
p[tot].cnt=res;
p[tot].sum=x*res;
p[tot].rnd=rand();
p[tot].sz=res;
return tot;
}
#define ls(x) p[x].ls
#define rs(x) p[x].rs
fuck void up(int u)
{
p[u].sz=p[ls(u)].sz+p[rs(u)].sz+p[u].cnt;
p[u].sum=p[ls(u)].sum+p[rs(u)].sum+p[u].cnt*p[u].val;
}
fuck void split(int rt,int k,int &L,int &R)
{
if(!rt){L=R=0;return;}
if(p[rt].val<=k)L=rt,split(rs(rt),k,rs(rt),R);
else R=rt,split(ls(rt),k,L,ls(rt));
up(rt);
}
fuck int merge(int x,int y)
{
if(!x||!y)return x+y;
if(p[x].rnd<p[y].rnd)
{
p[x].rs=merge(p[x].rs,y);up(x);
return x;
}
else
{
p[y].ls=merge(x,p[y].ls);up(y);
return y;
}
}
fuck void add(int u,int p)
{
split(root,u,sx,sy);
root=merge(merge(sx,newnode(u,p)),sy);
}
fuck void update(int l,int r,int k)
{
split(root,l-1,sx,sy);
split(sy,r,sy,sz);
int siz=p[sy].sz;
root=merge(sx,sz);
add(k,siz);
}
fuck void solve()
{
srand(time(0));
cin>>n>>q;
for(int i=1,x;i<=n;i++)cin>>x,add(x,1);
cout<<p[root].sum<<"\n";
while(q--)
{
int l,r,k;cin>>l>>r>>k;
update(l,r,k);
cout<<p[root].sum<<"\n";
}
}
signed main()
{
// ios::sync_with_stdio(false);
// cin.tie(0); cout.tie(0);
// int QwQ=read();
// int fuckccf=read();
// while(QwQ--)solve();
solve();
return 0;
}
// 6666 66666 666666
// 6 6 6 6 6
// 6 6 6666 6
// 6 6 6 6 6
// 6666 6 6 6666666
T4. 洛谷 P9588 「MXOI Round 2」队列
手模队列。
code:
#include<bits/stdc++.h>
using namespace std;
const int N = 200005;
int q,que[N],front,back,rt,x,c;
long long id[N],sum[N],p;
int main(){
cin>>c>>q;
while(q--)
{
int x;cin>>x;
if(x==1){
cin>>x;
sum[rt]=sum[rt++]+x;
while(front<=back&&que[back]<=x) back--;
que[++back] =x;
id[back]=sum[rt];
}
else if(x==2) cin>>x,p+=x;
else if(x==3){
cin>>x;
cout<<p+x-sum[lower_bound(sum+1,sum+rt,p+x)-sum-1]<<endl;
}
else if(x==4){
while(front<=back&&id[front]<=p) ++front;
cout<<que[front]<<endl;
}
}
return 0;
}
// 6666 66666 666666
// 6 6 6 6 6
// 6 6 6666 6
// 6 6 6 6 6
// 6666 6 6 6666666
总结
- 该补补板子了。
完结收工!!!!!

看完点赞,养成习惯
\(\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\)

浙公网安备 33010602011771号