- [KBC003Ex] Sequence 4
这题怎么变 5e3 了
- 2024-12-14 14:23:22 @
原题面
(已经重新搬运,范围 2e5)
std
#include<bits/stdc++.h>
#include<ext/rope>
#define rep(i,a,b) for(int i(a);i<=(b);++i)
#define req(i,a,b) for(int i(a);i>=(b);--i)
using namespace std;
char buf[1<<23],*p1=buf,*p2=buf,ubuf[1<<23],*u=ubuf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template<typename TP> inline TP read(TP &num)
{
TP x=0;
int f=0;
char ch=getchar();
while(ch<48||ch>57) f|=ch=='-',ch=getchar();
while(48<=ch&&ch<=57) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
return num=f?-x:x;
}
template<typename ...Args> inline void read(Args &...args)
{
(read(args),...);
}
template<typename TP> inline void write(TP x)
{
(x<0)?(putchar('-'),x=-x):0;
(x>9)?(write(x/10),0):0;
putchar((x%10)^48);
}
template<typename TP> inline void writeln(TP x)
{
write<TP>(x);
puts("");
}
using namespace __gnu_cxx;
namespace Solve
{
int n,q,opt,x,y,a[200001];
rope<int> tree,rtree;
inline void tree_reverse(int l,int r)
{
rope<int> tmp=tree.substr(tree.begin()+l,tree.begin()+r);
tree=tree.substr(tree.begin(),tree.begin()+l)+tree.substr(tree.begin()+r,tree.end())+rtree.substr(rtree.begin()+n-r,rtree.begin()+n-l);
rtree=tmp+rtree.substr(rtree.begin(),rtree.begin()+n-r)+rtree.substr(rtree.begin()+n-l,rtree.end());
}
inline void main()
{
read(n,q);
rep(i,1,n) read(a[i]),tree.append(a[i]);
req(i,n,1) rtree.append(a[i]);
rep(i,1,q)
{
read(opt,x,y);
if(opt==1)
{
rep(i,x-1,y-1) write(tree[i]),putchar(" \n"[i==y-1]);
}
else if(opt==4)
{
rope<int> treel=tree.substr(tree.begin(),tree.begin()+x-1),
treer=tree.substr(tree.begin()+x,tree.end()),
rtreel=rtree.substr(rtree.begin(),rtree.begin()+n-x),
rtreer=rtree.substr(rtree.begin()+n-x+1,rtree.end());
tree=treel+y+treer,rtree=rtreel+y+rtreer;
}
else if(opt==3) tree_reverse(x-1,y);
else if(opt==2)
{
int ps=tree[x-1],pt=tree[y-1];
rope<int> treel=tree.substr(tree.begin(),tree.begin()+x-1),
treem=tree.substr(tree.begin()+x,tree.begin()+y-1),
treer=tree.substr(tree.begin()+y,tree.end()),
rtreel=rtree.substr(rtree.begin(),rtree.begin()+n-y),
rtreem=rtree.substr(rtree.begin()+n-y+1,rtree.begin()+n-x),
rtreer=rtree.substr(rtree.begin()+n-x+1,rtree.end());
tree=treel+treem+pt+ps+treer,rtree=rtreel+ps+pt+rtreem+rtreer;
}
}
printf("Final Sequence: ");
for(auto i:tree) write(i),putchar(32);
}
}
signed main()
{
Solve::main();
return 0;
}
1 条评论
-
nr0728 LV 5 @ 2024-12-14 14:31:27
- 1
信息
- ID
- 105
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 8
- 标签
- 递交数
- 17
- 已通过
- 2
- 上传者