• 【LOJ#3110】【SDOI2019】—快速查询(模拟)


    传送门

    发现都是全局的修改
    于是就变成了喜闻乐见的模拟题了

    注意特判整体乘0的情况

    #include<bits/stdc++.h>
    using namespace std;
    const int RLEN=1<<20|1;
    inline char gc(){
        static char ibuf[RLEN],*ib,*ob;
        (ob==ib)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
        return (ob==ib)?EOF:*ib++;
    }
    inline int read(){
        char ch=gc();
        int res=0,f=1;
        while(!isdigit(ch))f^=ch=='-',ch=gc();
        while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
        return f?res:-res;
    }
    #define ll long long
    #define re register
    #define pii pair<int,int>
    #define fi first
    #define se second
    #define pb push_back
    #define cs const
    #define bg begin
    #define poly vector<int>
    struct Map{
    	static cs int Mod=13718533;
    	int key[Mod],stk[Mod],top;
    	int val[Mod];
    	Map(){memset(key,-1,sizeof(key));}
    	inline int pos(int k){
    		int p=k%Mod;
    		while(key[p]!=-1&&key[p]!=k)p=p+1==Mod?0:p+1;
    		return p;
    	}
    	inline int &operator[](int k){
    		int p=pos(k);
    		if(key[p]==-1){
    			key[p]=k,val[p]=0,stk[++top]=p;
    		}
    		return val[p];
    	}
    	inline void clear(){
    		while(top)key[stk[top--]]=-1;
    	}
    	inline bool count(int k){
    		return key[pos(k)]==k;
    	}
    };
    Map mp;
    cs int mod=1e7+19;
    inline int add(int a,int b){return (a+=b)>=mod?a-mod:a;}
    inline int dec(int a,int b){return (a-=b)<0?a+mod:a;}
    inline int mul(int a,int b){return 1ll*a*b%mod;}
    inline void Add(int &a,int b){(a+=b)>=mod?a-=mod:0;}
    inline void Dec(int &a,int b){(a-=b)<0?a+=mod:0;}
    inline void Mul(int &a,int b){a=1ll*a*b%mod;}
    inline int ksm(int a,int b,int res=1){for(;b;b>>=1,Mul(a,a))(b&1)&&(Mul(res,a),1);return res;}
    inline void chemx(int &a,int b){a<b?a=b:0;}
    inline void chemn(int &a,int b){a>b?a=b:0;}
    cs int N=100005;
    int last,atag,mtag,sum;
    int n,t,q,ans;
    int a[N],b[N],inv[mod];
    struct opt{
    	int op,x,y;	
    }p[N];
    inline void calc(int pos){
    	int op=p[pos].op,x=p[pos].x,y=p[pos].y;
    	if(op==1){
    		int k=mul(dec(y,atag),inv[mtag]);
    		if(mp.count(x))Dec(sum,mp[x]),mp[x]=k,Add(sum,k);
    		else Dec(sum,last),mp[x]=k,Add(sum,k);
    	}
    	else if(op==2){
    		Add(atag,x);
    	}
    	else if(op==3){
    		if(x==0)mp.clear(),last=0,sum=0,atag=0,mtag=1;
    		else Mul(atag,x),Mul(mtag,x);
    	}
    	else if(op==4){
    		mp.clear(),sum=mul(x,n),last=x,atag=0,mtag=1;
    	}
    	else if(op==5){
    		int res=last;
    		if(mp.count(x))res=mp[x];
    		Mul(res,mtag),Add(res,atag);
    		Add(ans,res);
    	}
    	else{
    		Add(ans,add(mul(sum,mtag),mul(n,atag)));
    	}
    }
    int main(){
    	inv[0]=inv[1]=1;
    	for(int i=2;i<mod;i++)inv[i]=mul(mod-mod/i,inv[mod%i]);
    	n=read(),q=read(),mtag=1;
    	for(int i=1;i<=q;i++){
    		p[i].op=read();
    		if(p[i].op<=5)p[i].x=read();
    		if(p[i].op<=4&&p[i].op>=2)p[i].x=(p[i].x%mod+mod)%mod;
    		if(p[i].op==1)p[i].y=(read()%mod+mod)%mod;
    	}
    	t=read();
    	for(int i=1;i<=t;i++)a[i]=read(),b[i]=read();
    	for(int i=1;i<=t;i++)
    	for(int j=1;j<=q;j++){
    		int now=(1ll*a[i]+1ll*b[i]*j)%q+1;
    		calc(now);
    	}
    	cout<<ans;
    }
    
  • 相关阅读:
    面向对象静态语言的模型
    语言的静态分析技术
    面向对象的核心元素与机制
    Lua 笔记
    Linux配置系统
    Linux文件类型
    Wijmo 日历插件
    窗外大雨,心里小雨
    一次胆战心惊的服务器经历
    一次胆战心惊的服务器经历
  • 原文地址:https://www.cnblogs.com/stargazer-cyk/p/12328525.html
Copyright © 2020-2023  润新知