灵异事件?
  • 板块灌水区
  • 楼主引领天下魔酸
  • 当前回复10
  • 已保存回复10
  • 发布时间2020/11/2 22:07
  • 上次更新2023/11/5 09:10:00
查看原帖
灵异事件?
39863
引领天下魔酸楼主2020/11/2 22:07

RT

这份代码

#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
int n,m,p,k,flag,x,y,k1,k2,k3,k4;
const int mod=998244353;
inline long long ksm(long long a,int b){
	long long res=1;
	while(b){
		if(b&1)res=(res*a)%mod;
		a=(a*a)%mod,b>>=1;
	}
	return res;
}
struct Lycoris{
	int x,id;
	inline bool operator<(const Lycoris&p)const{return x^p.x?x<p.x:id<p.id;}
	inline bool operator>(const Lycoris&p)const{return x^p.x?x>p.x:id>p.id;}
}a[100005];
tree<Lycoris,null_type,less<Lycoris>,rb_tree_tag,tree_order_statistics_node_update>s;
class FastIO{
    private:
        struct control{
            int ct,val;
            control(int Ct,int Val=-1):ct(Ct),val(Val){}
            inline control operator()(int Val){
                return control(ct,Val);
            }
        }_endl,_prs,_setprecision;
        #define IOSIZE 1000000
        char in[IOSIZE],*p,*pp,out[IOSIZE],*q,*qq,ch[20],*t,b,K,prs;
        inline char getch(){
            return p==pp&&(pp=(p=in)+fread(in,1,IOSIZE,stdin),p==pp)?b=0,EOF:*p++;
        }
        inline void putch(char x){
            q==qq&&(fwrite(out,1,q-out,stdout),q=out),*q++=x;
        }
        inline void puts(const char str[]){fwrite(out,1,q-out,stdout),fwrite(str,1,strlen(str),stdout),q=out;}
        inline void getline(string& s){
            s="";
            for(register char ch;(ch=getch())!='\n'&&b;)s+=ch;
        }
    public:
        FastIO():_endl(0),_prs(1),_setprecision(2),p(in),pp(in),q(out),qq(out+IOSIZE),t(ch),b(1),K(6){}
        ~FastIO(){fwrite(out,1,q-out,stdout);}
        #define endl "\n"
        #define indef(T) inline FastIO& operator>>(T& x){\
            x=0;register char f=0,ch;\
            while(!isdigit(ch=getch())&&b)f|=ch=='-';\
            while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48),ch=getch();\
            return x=f?-x:x,*this;\
        }
        indef(int)
        indef(long long)
        inline FastIO& operator>>(char& ch){return ch=getch(),*this;}
        inline FastIO& operator>>(string& s){
            s="";register char ch;
            while(isspace(ch=getch())&&b);
            while(!isspace(ch)&&b)s+=ch,ch=getch();
            return *this;
        }
        inline FastIO& operator>>(double& x){
            x=0;register char f=0,ch;
            double d=0.1;
            while(!isdigit(ch=getch())&&b)f|=(ch=='-');
            while(isdigit(ch))x=x*10+(ch^48),ch=getch();
            if(ch=='.')while(isdigit(ch=getch()))x+=d*(ch^48),d*=0.1;
            return x=f?-x:x,*this;
        }
        #define outdef(_T) inline FastIO& operator<<(_T x){\
            !x&&(putch('0'),0),x<0&&(putch('-'),x=-x);\
            while(x)*t++=x%10+48,x/=10;\
            while(t!=ch)*q++=*--t;\
            return *this;\
        }
        outdef(int)
        outdef(long long)
        inline FastIO& operator<<(char ch){return putch(ch),*this;}
        inline FastIO& operator<<(const char str[]){return puts(str),*this;}
        inline FastIO& operator<<(const string& s){return puts(s.c_str()),*this;}
        inline FastIO& operator<<(double x){
            register int k=0;
            this->operator<<(int(x));
            putch('.');
            x-=int(x);
            prs&&(x+=5*pow(10,-K-1));
            while(k<K)putch(int(x*=10)^48),x-=int(x),++k;
            return *this;
        }
        inline FastIO& operator<<(const control& cl){
            switch(cl.ct){
                case 0:putch('\n');break;
                case 1:prs=cl.val;break;
                case 2:K=cl.val;break;
            }
            return *this;
        }
        inline operator bool(){return b;}
}io;
int main(){
    #ifndef ONLINE_JUDGE
	freopen("lycoris.in","r",stdin);
	freopen("lycoris.out","w",stdout);
    #endif
	io>>n>>m>>p>>k;
	for(int i=1;i<=n;i++)io>>a[i].x,a[i].id=i,s.insert(a[i]);
	while(m--){
		io>>flag;
		if(flag==1){
			io>>x>>y;
			s.erase(s.lower_bound(a[x]));a[x].x=y;s.insert(a[x]);
		}else{
			io>>x;
            if(k==1){io<<"1\n";continue;}
			k1=s.order_of_key(*(s.lower_bound((Lycoris){(a[x].x+k-1)/k,0})))+1;//[k1,n]的石蒜突变后都能爆踩x
			k2=s.order_of_key(*(s.lower_bound((Lycoris){a[x].x,0})))+1;//[k2,n]的石蒜是否突变都爆踩x,但得把x扣掉
            //故[k1,k2)的石蒜都不能突变,再加上讨论了x不突变,概率为(1-Pr)^(k2-k1+1)
			k3=s.order_of_key(*(s.lower_bound((Lycoris){a[x].x,0})))+1;//[k3,n]的石蒜都得突变才能不被x爆踩
			k4=s.order_of_key(*(s.lower_bound((Lycoris){a[x].x*k,0})))+1;//[k4,n]的石蒜是否突变都不会被x爆踩,但得扣掉x本身
            //故[k3,k4)的石蒜都得突变,再加上讨论的x本身突变,概率为Pr^(k4-k3)
            // printf("%d %d %d %d\n",k1,k2,k3,k4);
            // io<<k1<<' '<<k2<<' '<<k3<<' '<<k4<<endl;
			io<<(ksm(1+mod-p,k2-k1+1)+ksm(p,k4-k3))%mod<<"\n";
		}
	}
}
/*
1 1 1 1
104209796
1 1 1 1
104209796
3 3 3 3
104209796
9 9 9 9
104209796
1 1 1 1
104209796
9 9 9 9
104209796
3 3 3 3
104209796
5 5 5 5
104209796
5 5 5 5
104209796
*/

跑这份数据:

10 10 1 23
3 2 6 5 7 1 1 4 2 7 
2 4
2 3
2 6
2 7
2 4
2 7
2 3
2 6
2 5
1 5 1

在本地跑快得很,一点问题都没有

但是交到学校的OJ上就T,交到你谷IDE上也T

我™直接一脸问号

求大佬解释

2020/11/2 22:07
加载中...