比赛 NOIP模拟赛by mzx Day2 评测结果 AWAWAWTTEE
题目名称 学姐的巧克力盒 最终得分 30
用户昵称 Marvolo 运行时间 6.691 s
代码语言 C++ 内存使用 68.96 MiB
提交时间 2016-10-20 21:43:14
显示代码纯文本
#include<cstdio>
#include<cstring>
#define N 1000010
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;

int i,n,m,k,p1,p2,tk,l,r;
long long a[N];
struct Marvolo{
	int l,r;
	long long d;
}t[4000010];

inline int read(){
	int p=0,c=getchar();
	while (c<'0'||c>'9')	c=getchar();
	while (c>='0'&&c<='9')	p=p*10+c-48,c=getchar();
	return p;
}

inline void Maketree(int x,int low,int high){
	int mid=(low+high)>>1;
	t[x].l=low;	t[x].r=high;
	if (low==high)	{t[x].d=a[low]%p1;	return;}
	Maketree(x*2,low,mid);	Maketree(x*2+1,mid+1,high);
	t[x].d=(t[x*2].d*t[x*2+1].d)%p1;
}

inline long long Query(int x,int low,int high){
	int mid=(t[x].l+t[x].r)>>1;
	if (t[x].l==low&&t[x].r==high){return t[x].d;}
	if (high<=mid)	return Query(x*2,low,high)%p1;	else
	if (low>mid)	return Query(x*2+1,low,high)%p1;	else
		return (Query(x*2,low,mid)*Query(x*2+1,mid+1,high))%p1;
}

inline void Work(){
	printf("%lld\n",Query(1,l,r));
}

inline void Solve(){
	return;
}

int main(){
	freopen("chocolatebox.in","r",stdin);
	freopen("chocolatebox.out","w",stdout);
	n=read();	m=read();	k=read();	p1=read();	p2=read();
	for (i=1;i<=n;i++)	a[i]=read();
	Maketree(1,1,n);
	for (i=1;i<=m;i++){
		tk=read();	l=read();	r=read();
		if (tk==1)	Work();	else Solve();
	}
	return 0;
}