离线 两个堆 后两组RE 前无组AC why RE
查看原帖
离线 两个堆 后两组RE 前无组AC why RE
141335
qwq2519楼主2020/10/12 20:21
#include<bits/stdc++.h>
#define rep(i,j,k) for(register int i(j);i!=(k+1);++i)
using namespace std;
typedef long long ll;
const int N=1007079;
const int mod=317847191;
inline void read(int &x) {
	x=0;
	register char ch=getchar();
	int w=0;
	while(ch>'9'||ch<'0') {
		w|=ch=='-';
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') {
		x=x*10+ch-48;
		ch=getchar();
	}
	w?x=~(x-1):x;
}
inline ll quickpow(int a,int b) {
	ll ans(1);
	ll res=a;
	while(b) {
		b&1 ?ans=(ans*res)%mod:1;
		res=(res*res)%mod;
		b>>=1;
	}
	return ans%mod;
}

int n,m;
int a;
ll mul,chu=1;
bitset<100000000> b;

priority_queue<int,vector<int>,greater<int> >xiao;
priority_queue<int> da;
int ans[1000001],tot;
int main() {
// freopen("sequence.in","r",stdin);
// freopen("sequence.out","w",stdout);
	read(n);
	read(m);
	n>0 ? mul=1:mul=0;
	rep(i,1,n) read(a),a%=mod,da.push(a),xiao.push(a),mul=(mul*a)%mod;
//	while(da.size()){
//		cout<<da.top()<<' ';da.pop();
//	}
//	cout<<endl;
//	while(xiao.size()){
//		cout<<xiao.top()<<' ';
//		xiao.pop();
//	}
	char op;
	int x;
//	while(m--) 
	rep(i,1,m)
	{
		cin>>op;
		if(op=='B') {
			int x=da.top();
			while(b[x])
			{
				b[x]=0;
				da.pop();x=da.top();
			}
//			printf("%d\n",x);
			ans[i]=x;
		} else if(op=='S') {
			int y=xiao.top();
			while(b[y])
			{
				b[y]=0;
				xiao.pop();y=xiao.top();
			}
			ans[i]=y;
//			printf("%d\n",y);
		} else if(op=='M') {
			int x=da.top();
			while(b[x]&&da.size())
			{
				b[x]=0;
				da.pop();x=da.top();
			}
			int y=xiao.top();
			while(b[y]&&xiao.size())
			{
				b[y]=0;
				xiao.pop();y=xiao.top();
			}
			ans[i]=quickpow(x,y);
//			printf("%d\n",quickpow(x,y));
		} else if(op=='D') {
			read(x);
			x%=mod;
			chu=(chu*x)%mod;
			b[x]=1;
			ans[i]=2222222;
		} else if(op=='T') {
//			printf("%d\n",mul);
			ans[i]=mul/chu;
		}
	}
   rep(i,1,m) if(ans[i]!=2222222)printf("%d\n",ans[i]);
	return 0;
}

问同标题

2020/10/12 20:21
加载中...