比赛 NOIP模拟赛by mzx Day2 评测结果 ETETETEEEE
题目名称 学姐的巧克力盒 最终得分 0
用户昵称 Sky_miner 运行时间 7.050 s
代码语言 C++ 内存使用 30.83 MiB
提交时间 2016-10-20 21:13:42
显示代码纯文本
  1. #include <queue>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <iostream>
  5. #include <algorithm>
  6. using namespace std;
  7. typedef long long ll;
  8. inline void read(int &x){
  9. x=0;char ch;bool flag = false;
  10. while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
  11. while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
  12. }
  13. inline int cat_max(const int &a,const int &b){return a>b ? a:b;}
  14. inline int cat_min(const int &a,const int &b){return a<b ? a:b;}
  15. const int maxn = 1000010;
  16. int phi(int x){
  17. int ret = x;
  18. for(int i=2;i*i<=x; ++i){
  19. if(x % i == 0){
  20. ret /= i;ret *= (i-1);
  21. while(x % i == 0) x /= i;
  22. }
  23. }
  24. if(x^1) ret /= x,ret *= (x-1);
  25. return ret;
  26. }
  27. int p1,p2,T[maxn<<2],h[maxn<<2],M;
  28. int n,m,k,P;
  29. inline void update(int x){
  30. T[x] = T[x<<1]*T[x<<1|1]%p1;
  31. h[x] = h[x<<1]*h[x<<1|1]%p2;
  32. }
  33. void build(int n){
  34. for(M=1;M<(n+1);M<<=1);
  35. for(int i=M+1;i<=M+n;++i) read(T[i]),h[i]=T[i],h[i]%=p2,T[i]%=p1;
  36. for(int i=M-1;i;--i) update(i);
  37. }
  38. int query1(int s,int t){
  39. int ret = 1;
  40. for(s += M-1,t += M+1;s^t^1;s>>=1,t>>=1){
  41. if(~s&1) ret = ret*T[s^1]%p1;
  42. if( t&1) ret = ret*T[t^1]%p1;
  43. }return ret;
  44. }
  45. int query2(int s,int t){
  46. int ret = 1;
  47. for(s += M-1,t += M+1;s^t^1;s>>=1,t>>=1){
  48. if(~s&1) ret = ret*h[s^1]%p2;
  49. if( t&1) ret = ret*h[t^1]%p2;
  50. }return ret;
  51. }
  52. inline int qpow(int x,int p){
  53. int ret = 1;
  54. for(;p;p>>=1,x=x*x%P) if(p&1) ret = ret*x%P;
  55. return ret;
  56. }
  57. int main(){
  58. freopen("chocolatebox.in","r",stdin);
  59. freopen("chocolatebox.out","w",stdout);
  60. read(n);read(m);read(k);read(p1);read(P);
  61. p2 = phi(P);
  62. build(n);
  63. int cmd,u,v;
  64. while(m--){
  65. read(cmd);read(u);read(v);
  66. if(cmd == 1) printf("%d\n",query1(u,v));
  67. else printf("%d\n",qpow(k,query2(u,v)) );
  68. }
  69. //getchar();getchar();
  70. fclose(stdin);fclose(stdout);
  71. return 0;
  72. }