比赛 |
NOIP模拟赛by mzx Day2 |
评测结果 |
MMMMMMMMMM |
题目名称 |
学姐的巧克力盒 |
最终得分 |
0 |
用户昵称 |
cdcq |
运行时间 |
0.000 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2016-10-20 21:59:46 |
显示代码纯文本
//Xel'Naga神器真的是实心儿的……
//没有第二问的50分是累乘???
//第二问是k^(ai*aj*ak……)???
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int read(){int z=0,mark=1; char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')mark=-1; ch=getchar();}
while(ch>='0'&&ch<='9'){z=(z<<3)+(z<<1)+ch-'0'; ch=getchar();}
return z*mark;
}
int n,m,p1,p2,a[1100000]; long long tk;
int p3;
struct dcd{int sleft,sright,mid;long long svalue,svalue2;}tree[21000000];
void get_SegmentTree(int x,int _left,int _right){
tree[x].sleft=_left,tree[x].sright=_right,tree[x].mid=(_left+_right)>>1;
if(_left==_right) tree[x].svalue=a[_left],tree[x].svalue2=a[_left];
else{
get_SegmentTree(x<<1,_left,tree[x].mid),get_SegmentTree(x<<1|1,tree[x].mid+1,_right);
tree[x].svalue=(tree[x<<1].svalue*tree[x<<1|1].svalue)%p1;
tree[x].svalue2=(tree[x<<1].svalue2*tree[x<<1|1].svalue2)%p2;
}
}
long long search(int x,int _left,int _right){
if(tree[x].sleft==_left && tree[x].sright==_right) return tree[x].svalue;
else if(_left<=tree[x].mid && _right>tree[x].mid) return (search(x<<1,_left,tree[x].mid)*search(x<<1|1,tree[x].mid+1,_right))%p1;
else if(_right<=tree[x].mid) return search(x<<1,_left,_right);
else return search(x<<1|1,_left,_right);
}
long long fast_mi(long long x,long long y){
long long z=1,base=x;
while(y){
if(y&1) z=(z*base)%p3;
base=(base*base)%p3;
y>>=1;
}
return z;
}
int main(){
//freopen("ddd.in","r",stdin);
freopen("chocolatebox.in","r",stdin);
freopen("chocolatebox.out","w",stdout);
cin>>n>>m>>tk>>p1>>p2; p3=p2; p2--;
for(int i=1;i<=n;i++) a[i]=read();
get_SegmentTree(1,1,n);
int _id,_left,_right;
while(m --> 0){//趋向于
_id=read(),_left=read(),_right=read();
if(_id==1) printf("%lld\n",search(1,_left,_right));
else printf("%lld\n",fast_mi(tk,search(1,_left,_right)));
}
return 0;
}