比赛 |
NOIP模拟赛by mzx Day2 |
评测结果 |
AWAWAWTTEE |
题目名称 |
学姐的巧克力盒 |
最终得分 |
30 |
用户昵称 |
Mealy |
运行时间 |
8.612 s |
代码语言 |
C++ |
内存使用 |
68.99 MiB |
提交时间 |
2016-10-20 22:00:05 |
显示代码纯文本
- #include <iostream>
- #include <cstdio>
- #define u ree[tmpx]
- #define lc ree[tmpx<<1]
- #define rc ree[tmpx<<1^1]
- using namespace std;
- const int nmax=1000086;
- typedef long long ll;
- int n,m,k,FJ1,FJ2;
- int type,tmpl,tmpr;
- ll val[nmax];
- class SegmentTree
- {
- public:
- int l,r;
- ll pro;
- }ree[nmax*4];
-
- ll QuickPow(ll base,ll exp)
- {
- ll ans=1;
- exp%=(FJ2-1);
- while(exp)
- {
- if(exp&1)
- {
- ans=(ans*base)%FJ2;
- }
- base=(base*base)%FJ2;
- exp>>=1;
- }
- return ans%FJ2;
- }
-
-
- void SetTree(int tmpx,int tmpl,int tmpr)
- {
- u.l=tmpl;
- u.r=tmpr;
- if(tmpl==tmpr)
- {
- u.pro=val[tmpl];
- }
- else
- {
- SetTree(tmpx<<1,tmpl,(tmpl+tmpr)>>1);
- SetTree(tmpx<<1^1,((tmpl+tmpr)>>1)+1,tmpr);
- u.pro=lc.pro*rc.pro%FJ1;
- }
- }
- ll QueryPro(int tmpx,int tmpl,int tmpr)
- {
- if(tmpl<=u.l&&tmpr>=u.r)
- {
- return u.pro%FJ1;
- }
- else
- {
- if(u.l!=u.r)
- {
- ll tmpans=1;
- if(tmpl<=lc.r)
- {
- tmpans=tmpans*QueryPro(tmpx<<1,tmpl,tmpr)%FJ1;
- }
- if(tmpr>=rc.l)
- {
- tmpans=tmpans*QueryPro(tmpx<<1^1,tmpl,tmpr)%FJ1;
- }
- return tmpans;
- }
- }
- }
- void PreDo()
- {
- scanf("%d%d%d%d%d",&n,&m,&k,&FJ1,&FJ2);
- for(int i=1;i<=n;i++)
- {
- scanf("%lld",&val[i]);
- }
- }
- int main()
- {
- freopen("chocolatebox.in","r",stdin);
- freopen("chocolatebox.out","w",stdout);
- PreDo();
- SetTree(1,1,n);
- for(int i=1;i<=m;i++)
- {
- scanf("%d%d%d",&type,&tmpl,&tmpr);
- if(type==1)
- {
- ll ans=QueryPro(1,tmpl,tmpr);
- printf("%lld",ans);
- }
- if(type==2)
- {
- int derta=tmpr-tmpl;
-
- ll tmp=QueryPro(1,tmpl,tmpr);
- ll ans=QuickPow(k,tmp);
- printf("%lld",ans);
- }
- }
- return 0;
- }
-
-