社区讨论
站外fhq-treap板子题求条
学术版参与者 1已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @mity9vtz
- 此快照首次捕获于
- 2025/12/06 15:06 2 个月前
- 此快照最后确认于
- 2025/12/08 16:15 2 个月前
不用理我那个快读,题目:超级备忘录
CPP#include<bits/stdc++.h>
#define int long long
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
bool st;
using namespace std;
/*Ctrl+Alt+G F*/
namespace AC{
namespace Fread{const int SIZE=1<<16;char buf[SIZE],*S,*T;inline char getchar(){if(S==T){T=(S=buf)+fread(buf,1,SIZE,stdin);if(S==T)return'\n';}return *S++;}}namespace Fwrite{const int SIZE=1<<16;char buf[SIZE],*S=buf,*T=buf+SIZE;inline void flush(){fwrite(buf,1,S-buf,stdout);S=buf;}inline void putchar(char c){*S++=c;if(S==T)flush();}struct NTR{~NTR(){flush();}}ztr;}
#define getchar Fread::getchar
#define putchar Fwrite::putchar
#define Setprecision 15
#define between ' '
template<typename T>struct is_char{static constexpr bool value=(std::is_same<T,char>::value||std::is_same<T,signed char>::value||std::is_same<T,unsigned char>::value);};template<typename T>struct is_integral_ex{static constexpr bool value=(std::is_integral<T>::value||std::is_same<T,__int128>::value)&&!is_char<T>::value;};template<typename T>struct is_floating_point_ex{static constexpr bool value=std::is_floating_point<T>::value||std::is_same<T,__float128>::value;};namespace Fastio{struct Reader{template<typename T>typename std::enable_if_t<std::is_class<T>::value,Reader&>operator>>(T&x){for(auto &y:x)*this>>y;return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1;while(c<'0'||c>'9'){if(c=='-')f*=-1;c=getchar();}x=0;while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();}x*=f;return *this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1,s=0;x=0;T t=0;while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else return x*=f,*this;while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Reader&>operator>>(T&c){c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();return *this;}Reader&operator>>(char*str){int len=0;char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str[len++]=c,c=getchar();str[len]='\0';return*this;}Reader&operator>>(std::string&str){str.clear();char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str.push_back(c),c=getchar();return*this;}Reader(){}}cin;const char endl='\n';struct Writer{typedef __int128 mxdouble;template<typename T>typename std::enable_if_t<std::is_class<T>::value,Writer&>operator<<(T x){for(auto &y:x)*this<<y<<between;*this<<'\n';return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Writer&>operator<<(T x){if(x==0)return putchar('0'),*this;if(x<0)putchar('-'),x=-x;static int sta[45];int top=0;while(x)sta[++top]=x%10,x/=10;while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Writer&>operator<<(T x){if(x<0)putchar('-'),x=-x;x+=pow(10,-Setprecision)/2;mxdouble _=x;x-=(T)_;static int sta[45];int top=0;while(_)sta[++top]=_%10,_/=10;if(!top)putchar('0');while(top)putchar(sta[top]+'0'),--top;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Writer&>operator<<(T c){putchar(c);return*this;}Writer&operator<<(char*str){int cur=0;while(str[cur])putchar(str[cur++]);return *this;}Writer&operator<<(const char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}Writer&operator<<(std::string str){int st=0,ed=str.size();while(st<ed)putchar(str[st++]);return*this;}Writer(){}void flush(){Fwrite::flush();}}cout;}
#undef Setprecision
using Fastio::cin;
using Fastio::cout;
using Fastio::endl;
mt19937 rnd(time(0));
struct FHQ{
private:
struct node{
int rev,add,num,siz,min,rk,ls,rs;
}tr[20010];
int tot=0,root=0;
int newnode(int x){
tot++;
tr[tot].num=x;
tr[tot].siz=1;
tr[tot].min=x;
tr[tot].add=tr[tot].rev=0;
tr[tot].rk=rnd();
return tot;
}
void pushdown(int x){
if(tr[x].rev){
swap(tr[x].ls,tr[x].rs);
if(tr[x].ls)tr[tr[x].ls].rev^=1;
if(tr[x].rs)tr[tr[x].rs].rev^=1;
tr[x].rev=0;
}
if(tr[x].add){
tr[x].num+=tr[x].add;
tr[x].min+=tr[x].add;
if(tr[x].ls)tr[tr[x].ls].add+=tr[x].add;
if(tr[x].rs)tr[tr[x].rs].add+=tr[x].add;
tr[x].add=0;
}
}
void pushup(int x){
if(tr[x].ls)pushdown(tr[x].ls);
if(tr[x].rs)pushdown(tr[x].rs);
tr[x].siz=tr[tr[x].ls].siz+tr[tr[x].rs].siz+1;
tr[x].min=tr[x].num;
if(tr[x].ls)tr[x].min=min(tr[x].min,tr[tr[x].ls].min);
if(tr[x].rs)tr[x].min=min(tr[x].min,tr[tr[x].rs].min);
}
array<int,2>split(int x,int k){
array<int,2>ans={0,0};
if(!x)return ans;
pushdown(x);
if(tr[tr[x].ls].siz+1<=k){
ans=split(tr[x].rs,k-tr[tr[x].ls].siz-1);
tr[x].rs=ans[0];
ans[0]=x;
}
else{
ans=split(tr[x].ls,k);
tr[x].ls=ans[1];
ans[1]=x;
}
pushup(x);
return ans;
}
int merge(int x,int y){
if(!x||!y)return x^y;
pushdown(x);
pushdown(y);
if(tr[x].rk>tr[y].rk){
tr[x].rs=merge(tr[x].rs,y);
pushup(x);
return x;
}
else{
tr[y].ls=merge(x,tr[y].ls);
pushup(y);
return y;
}
}
public:
void add(int x,int y,int d){
auto[tr0,tr3]=split(root,y);//分裂(-∞,y]与(y,+∞)
auto[tr1,tr2]=split(tr0,x-1);//分裂(-∞,x)、[x,y]与(y,+∞)
tr[tr2].add+=d;
root=merge(tr1,merge(tr2,tr3));
}
void reverse(int x,int y){
auto[tr0,tr3]=split(root,y);//分裂(-∞,y]与(y,+∞)
auto[tr1,tr2]=split(tr0,x-1);//分裂(-∞,x)、[x,y]与(y,+∞)
tr[tr2].rev^=1;
root=merge(tr1,merge(tr2,tr3));
}
void revolve(int x,int y,int k){//轮换k次
auto[tr0,tr3]=split(root,y);//分裂(-∞,y]与(y,+∞)
auto[tr1,tr2]=split(tr0,x-1);//分裂(-∞,x)、[x,y]与(y,+∞)
int len=y-x+1;
k%=len;
auto[tr2_1,tr2_2]=split(tr2,len-k);//分裂[x,y-k]、[y-k+1,y]
tr2=merge(tr2_2,tr2_1);
root=merge(tr1,merge(tr2,tr3));
}
void insert(int x,int y){
auto[tr0,tr1]=split(root,x);//分裂(-∞,x]与(x,+∞)
root=merge(tr0,merge(newnode(y),tr1));
}
void erase(int x){
auto[tr0,tr3]=split(root,x);//分裂(-∞,x]与(x,+∞)
auto[tr1,tr2]=split(tr0,x-1);//分裂(-∞,x)、x与(x,+∞)
root=merge(tr1,tr3);
}
int min(int x,int y){
auto[tr0,tr3]=split(root,y);//分裂(-∞,y]与(y,+∞)
auto[tr1,tr2]=split(tr0,x-1);//分裂(-∞,x)、[x,y]与(y,+∞)
int ans=tr[tr2].min;
root=merge(tr1,merge(tr2,tr3));
return ans;
}
};
void solve(){
FHQ treap;
int n,m;
cin>>n;
for(int i=0;i<n;i++){
int x;
cin>>x;
treap.insert(i,x);
}
cin>>m;
while(m--){
string op;
cin>>op;
if(op=="ADD"){
int x,y,k;
cin>>x>>y>>k;
treap.add(x,y,k);
}
if(op=="REVERSE"){
int x,y;
cin>>x>>y;
treap.reverse(x,y);
}
if(op=="REVOLVE"){
int x,y,k;
cin>>x>>y>>k;
treap.revolve(x,y,k);
}
if(op=="INSERT"){
int x,y;
cin>>x>>y;
treap.insert(x,y);
}
if(op=="DELETE"){
int x;
cin>>x;
treap.erase(x);
}
if(op=="MIN"){
int x,y;
cin>>x>>y;
cout<<treap.min(x,y)<<endl;
}
}
}
}
bool ed;
signed main(){
#ifdef debug
cerr<<"----------------------------------- START -----------------------------------\n";
#endif
int t=1;
//cin>>t;
while(t--)AC::solve();
#ifdef debug
cerr<<"\n--------------------------------- INPUT END ---------------------------------\n";
AC::cout.flush();
cerr<<"\n------------------------------------ END ------------------------------------\n";
cerr<<setprecision(3)<<fixed<<"Total Memory : "<<left<<setw(10)<<(&ed-&st)/1048576.0<<" \tMB\n"<<" "<<left<<setw(10)<<(&ed-&st)/1024.0<<" \tKB\n"<<" "<<left<<setw(10)<<(&ed-&st)<<" \tByte\n";
#endif
}
回复
共 1 条回复,欢迎继续交流。
正在加载回复...