比赛 NOIP模拟赛by mzx Day2 评测结果 AWAWAWTTEE
题目名称 学姐的巧克力盒 最终得分 30
用户昵称 可以的. 运行时间 7.310 s
代码语言 C++ 内存使用 38.46 MiB
提交时间 2016-10-20 21:50:10
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <deque>
#define Mem(a,v) memset(a,v,sizeof(a))
using namespace std;
/*
freopen(".in","r",stdin);
	freopen(".out","w",stdout);
getchar(); getchar();
	return 0;
*/
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
#define lch rt<<1
#define rch rt<<1|1
#define maxn 1000010
typedef long long LL;
int Phi;
int phi(int x){
	int Max = x , sum = x;
	for(int i=2;i*i<=Max;i++){
		int cnt = 0;
		while(x%i==0){
			x /= i;	cnt ++ ;
		}	
		if(cnt){
			sum = sum - sum / i;	
		}
	}
	if(x && x!=1) sum -= sum / x;
	return sum;
}
LL quickpow(LL a,LL b){
	LL res = 1;
	while(b){
		if(b&1) res *= a;
		a *= a; b >>= 1;
		res %= Phi; a %= Phi;
	}return res;
}
int N,M,K;
LL p1,p2,a[maxn],mul[maxn<<2];
void Insert(int i,LL x,int rt,int l,int r){
	if(l == r){
		mul[rt] = x%p1; return;	
	}	
	int mid = (l + r) >> 1;
	if(i <= mid) Insert(i,x,lson);
	else Insert(i,x,rson);
	mul[rt] = (mul[lch]*mul[rch])%p1;
}

void Read_build(){
	scanf("%d%d%d%lld%lld",&N,&M,&K,&p1,&p2);
	for(int i = 1;i <= N;++ i){
		scanf("%lld",&a[i]);
		Insert(i,a[i],1,1,N);
	}
}
LL Query_mul(int s,int t,int rt,int l,int r){
	if(s <= l && t >= r) return mul[rt]%p1;
	int mid = (l + r) >> 1;
	if(t <=mid) return Query_mul(s,t,lson)%p1;
	if(s > mid) return Query_mul(s,t,rson)%p1;
	return (Query_mul(s,t,lson)*Query_mul(s,t,rson))%p1;	
}
void Reply(){
	if(p2) Phi = phi(p2);
	int l , r , o ; LL res;
	while( M -- ){
		scanf("%d%d%d",&o,&l,&r);
		if(o == 1){
			res = Query_mul(l,r,1,1,N);
			printf("%lld\n",res);
		} else {
		//	LL x = Query_mul2(l,r,1,1,N)%p2;
		//	res = quickpow(K,((x%Phi)+Phi));
		//	printf("%lld\n",res%p2);
			printf("0\n");
			
		}
	}
}
int main(){
	freopen("chocolatebox.in","r",stdin);
	freopen("chocolatebox.out","w",stdout);
	Read_build();
	Reply();
	getchar(); getchar();
	return 0;
}