比赛 NOIP模拟赛by mzx Day2 评测结果 ATTTTTTTTT
题目名称 学姐的巧克力盒 最终得分 10
用户昵称 njx_07 运行时间 18.006 s
代码语言 C++ 内存使用 3.72 MiB
提交时间 2016-10-20 21:43:25
显示代码纯文本
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#include <cmath>
#include <ctime>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while (ch>'9'||ch<'0')	{if (ch=='-'){f=-1;} ch=getchar();}
	while (ch<='9'&&ch>='0'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
	return x*f;
}
int n,m,k,pa,pb,ty,r,l;
long long ans=0;
int set[1001000]={};
void worka()
{
	ans=set[l];
	for (int i=l+1;i<=r;i++)	{
		ans*=set[i];if (ans>pa)	ans%=pa;
	}
	cout<<ans<<endl;
}
long long get(int st)
{
	long long tmp=1;
	for (int i=1;i<=set[l];i++)	{tmp*=k;if (tmp>pb)tmp%=pb;}
	return tmp;
}
void workb()
{
	ans=get(l);
	long long tmp=0;
	for (int i=l+1;i<=r;i++) {
		tmp=ans;
		for (int j=1;j<set[i];j++)	{
			ans*=tmp;if (ans>pb)	ans%=pb;
		}
	}
	cout<<ans<<endl;
}
int main()
{
	freopen("chocolatebox.in","r",stdin);
	freopen("chocolatebox.out","w",stdout);
	n=read();m=read();k=read();pa=read();pb=read();
	for (int i=1;i<=n;i++)	set[i]=read();
	for (int i=1;i<=m;i++){
		ty=read();l=read();r=read();
		if (ty==1)	worka();
		if (ty==2)	workb();
	}
	
	return 0;
}