比赛 |
NOIP模拟赛by mzx Day2 |
评测结果 |
AWAWAWWWEE |
题目名称 |
学姐的巧克力盒 |
最终得分 |
30 |
用户昵称 |
jmisnal |
运行时间 |
2.052 s |
代码语言 |
C++ |
内存使用 |
118.57 MiB |
提交时间 |
2016-10-20 21:43:28 |
显示代码纯文本
#include <iostream>
#include <cstdio>
#define inf 0x7fffffff
#define ll long long
#define lson(x) (x<<1)
#define rson(x) ((x<<1)^1)
using namespace std;
int read()
{
int x=0;char ch=getchar();
while(ch<'0'||ch>'9')ch=getchar();
while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
return x;
}
struct data{
int l,r;
ll v;
}tr[7500000];
int n,m,k,p1,p2;
int a[1000050];
void build(int bh,int l,int r)
{
// cout<<'*'<<bh<<' '<<l<<' '<<r<<endl;
tr[bh].l=l;tr[bh].r=r;
if(l==r)
{
tr[bh].v=a[l]%p1;
// cout<<bh<<' '<<tr[bh].v<<endl;
return ;
}
int mid=(l+r)>>1;
build(lson(bh),l,mid);
build(rson(bh),mid+1,r);
tr[bh].v=(tr[lson(bh)].v*tr[rson(bh)].v)%p1;
// cout<<bh<<' '<<tr[bh].v<<endl;
}
ll ask(int bh,int l,int r)
{
if(tr[bh].l==l&&tr[bh].r==r)
return tr[bh].v;
int mid=(tr[bh].l+tr[bh].r)>>1;
ll x=0;
if(r<=mid)
{
x=ask(lson(bh),l,r);
return x;
}
else if(l>mid)
{
x=ask(rson(bh),l,r);
return x;
}
else{
x=ask(lson(bh),l,mid);
x*=ask(rson(bh),mid+1,r);
// while(x>=p1)x-=p1;
x%=p1;
return x;
}
}
//vector<>
int main()
{
// freopen("shujv.out","r",stdin);
// freopen("sb.out","w",stdout);
freopen("chocolatebox.in","r",stdin);
freopen("chocolatebox.out","w",stdout);
// cout<<rson(4);return 0;
// cout<<inf;return 0;
n=read(),m=read();k=read();p1=read();p2=read();
if(p1!=1000000007&&p1!=996919243)
{
for(int i=1;i<=n;i++)
a[i]=read();
build(1,1,n);
int ty,l,r;
for(int i=1;i<=m;i++)
{
ty=read();l=read();r=read();
if(ty==1)
{
printf("%lld\n",ask(1,l,r));
}
}
return 0;
}
return 0;
}