比赛 |
NOIP模拟赛by mzx Day2 |
评测结果 |
AWAWAWEEWW |
题目名称 |
学姐的巧克力盒 |
最终得分 |
30 |
用户昵称 |
chad |
运行时间 |
2.508 s |
代码语言 |
C++ |
内存使用 |
23.43 MiB |
提交时间 |
2016-10-20 21:57:10 |
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<ctime>
#include<cmath>
#include<queue>
using namespace std;
#define FILE "chocolatebox"
#define pii pair<long long,long long>
#define LL long long
#define up(i,j,n) for(int i=j;i<=n;i++)
#define down(i,n,j) for(int i=n;i>=j;i--)
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define abs(x) ((x)<0?(-(x)):(x))
template<typename T>inline bool chkmax(T &a,T b){return a<b?a=b,true : false;}
template<typename T>inline bool chkmin(T &a,T b){return a>b?a=b,true : false;}
int read(){
int x=0;char ch=getchar();bool flag=0;
while(ch<'0'||ch>'9'){if(ch=='-')flag=1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return flag?-x:x;
}
const int maxn=1010000;
LL n,m,k,p1,p2;
LL a[maxn];
namespace OI{
LL c[maxn];
int x,y;
void updata(int root){c[root]=c[root<<1]*c[root<<1|1]%p1;}
void Set(int left,int right,int root){
if(left==right){
c[root]=a[left];
return;
}
int mid=(left+right)>>1;
Set(left,mid,root<<1);
Set(mid+1,right,root<<1|1);
updata(root);
}
LL query(int left,int right,int root){
if(left>y||right<x)return 1;
if(left>=x&&right<=y)return c[root];
int mid=(left+right)>>1;
return query(left,mid,root<<1)*query(mid+1,right,root<<1|1)%p1;
}
void slove(){
Set(1,n,1);int ty;
while(m--){
ty=read(),x=read(),y=read();
if(ty==1){
printf("%lld\n",query(1,n,1));
continue;
}
}
}
}
namespace OI2{
LL c[maxn];
void gcd(LL a,LL b,LL &d,LL &x,LL &y){
if(b==0){x=1;y=0;d=a;}
gcd(b,a%b,d,x,y);
LL t=x;
x=y;
y=t-a/b*y;
}
LL inv(LL a){
LL d,x,y;
gcd(a,p1,d,x,y);
return (d==1)?((x%p1+p1)%p1):-1;
}
void slove(){
c[1]=a[1];c[0]=1;
for(int i=2;i<=n;i++)c[i]=c[i-1]*a[i]%p1;
LL ty,l,r;
while(m--){
ty=read(),l=read(),r=read();
if(ty==1)printf("%lld\n",c[r]%p1*inv(c[l-1])%p1);
}
}
}
int main(){
freopen(FILE".in","r",stdin);
freopen(FILE".out","w",stdout);
n=read(),m=read(),k=read(),p1=read(),p2=read();
up(i,1,n)a[i]=read();
if(p2==0){
if(n<=500000)OI::slove();
else OI2::slove();
}
return 0;
}