TLE求助
查看原帖
TLE求助
377969
george0929楼主2024/8/3 11:57

TLE 50pts

自测极限数据耗时2秒左右,求助到底是哪里出了问题?

#include<bits/stdc++.h>
using namespace std;
#define int long long
int mod=998244353;
int Random(){
	return (rand()<<15)+rand();
}
struct node{
	int ls,rs;
	int val,sz,sum,tag;
	int priority;
}t[2000005];
int tot;
typedef struct _FHQ_TREAP{
	%:define lc t[rt].ls
	%:define rc t[rt].rs
	int root;
	inline void pushup(int rt){
		t[rt].sz=t[lc].sz+t[rc].sz+1;
		t[rt].sum=t[lc].sum+t[rc].sum+t[rt].val;
		t[rt].sum%=mod;
	}
	inline void add(int rt,int v){
		t[rt].tag=t[rt].tag*v%mod;
		t[rt].val=t[rt].val*v%mod;
		t[rt].sum=t[rt].sum*v%mod;
	}
	inline void pushdown(int rt){
		int tmp=t[rt].tag;
		t[rt].tag=1;
		add(lc,tmp);
		add(rc,tmp);
	}
	inline int create(int val){
		++tot;
		t[tot].ls=t[tot].rs=0;
		t[tot].tag=t[tot].sz=1;
		t[tot].val=t[tot].sum=val;
		t[tot].priority=Random();
		return tot;
	}
	void split(int rt,int sz,int &a,int &b){
		if(!rt){
			a=b=0;
			return;
		}
		pushdown(rt);
		if(t[lc].sz>=sz){
			b=rt;
			split(lc,sz,a,lc);
		}else{
			a=rt;
			split(rc,sz-t[lc].sz-1,rc,b);
		}
		pushup(rt);
	}
	int merge(int a,int b){
		if(!a) return b;
		if(!b) return a;
		pushdown(a),pushdown(b);
		if(t[a].priority>t[b].priority){
			t[a].rs=merge(t[a].rs,b);
			pushup(a);
			return a;
		}else{
			t[b].ls=merge(a,t[b].ls);
			pushup(b);
			return b;
		}
	}
	void modify(int l,int r,int v){
		l++,r++;
		int a,b,c;
		split(root,l-1,a,b);
		split(b,r-l+1,b,c);
		add(b,v);
		root=merge(a,merge(b,c));
	}
	int query(int l,int r){
		l++,r++;
		int a,b,c,res;
		split(root,l-1,a,b);
		split(b,r-l+1,b,c);
		res=t[b].sum;
		root=merge(a,merge(b,c));
		return res;
	}
	void rightmove(){
		int a,b;
		split(root,t[root].sz-1,a,b);
		root=merge(create(1),a);
	}
	void push_back(int val){
		root=merge(root,create(val));
	}
	
	%:undef lc
	%:undef rc
}treap;
treap T;
int n,a,b;
int l[200005],r[200005];
signed main(){
	srand(time(0));
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,a,b;
//	cin>>n>>a>>b;
	n=200000,a=200001,b=233333333;
	for(int i=1;i<=n;i++){
		l[i]=Random();
		r[i]=Random();
		if(l[i]>r[i]) swap(l[i],r[i]);
	}
//	for(int i=1;i<=n;i++){
//		cin>>l[i]>>r[i];
//	}
	T.push_back(1);
	for(int i=1;i<a;i++){
		T.push_back(0);
	}
	for(int i=1;i<=n;i++){
		int tmp=0;
		if(l[i]<=b){
			tmp=T.query(0,a-1)*(min(b,r[i])-l[i]+1)%mod;
		}
		T.rightmove();
		if(r[i]>=b+1){
			T.modify(1,a-1,(r[i]-max(l[i],b+1)+1));
		}else{
			T.modify(1,a-1,0);
		}
		T.modify(0,0,tmp);
	}
	cout<<T.query(0,a-1)<<endl;
}
2024/8/3 11:57
加载中...