比赛 2024国庆练习2 评测结果 AAAAAAAAAA
题目名称 学姐的巧克力盒 最终得分 100
用户昵称 darkMoon 运行时间 7.434 s
代码语言 C++ 内存使用 13.64 MiB
提交时间 2024-10-05 16:37:14
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
auto IN = freopen("chocolatebox.in", "r", stdin);
auto OUT = freopen("chocolatebox.out", "w", stdout);
auto mread = [](){int x;scanf("%d", &x);return x;};
const int N = 1e6 + 5;
int n = mread(), m = mread(), k = mread(), p1 = mread(), p2 = mread(), p3, a[N];
int ksm(int x, int k, int MOD){
    int ans = 1, now = x;
    while(k){
        if(k & 1){
            ans = 1ll * ans * now % MOD;
        }
        now = 1ll * now * now % MOD;
        k >>= 1;
    }
    return ans;
}
struct tree{
    int s[N << 2], MOD;
    void pushup(int x){
        s[x] = 1ll * s[x << 1] * s[x << 1 | 1] % MOD;
        return;
    }
    void build(int x, int nl, int nr){
        if(nl == nr){
            s[x] = a[nl] % MOD;
            return;
        }
        int mid = nl + nr >> 1;
        build(x << 1, nl, mid);
        build(x << 1 | 1, mid + 1, nr);
        pushup(x);
        return;
    }
    int query(int x, int nl, int nr, int l, int r){
        if(nl >= l && nr <= r){
            return s[x];
        }
        int mid = nl + nr >> 1, sum = 1;
        if(mid >= l){
            sum = query(x << 1, nl, mid, l, r);
        }
        if(mid + 1 <= r){
            sum = 1ll * sum * query(x << 1 | 1, mid + 1, nr, l, r) % MOD;
        }
        return sum;
    }
}t1, t2;
signed main(){
    int P2 = p2;
    if(p1 == 0){
        p1 = 1;
    }
    if(p2 == 0){
        p3 = 1;
        P2 = 1;
    }
    else{
        p3 = p2;
        for(int i = 2; i * i <= p2; i ++){
            if(p2 % i == 0){
                p3 = p3 / i * (i - 1);
                while(p2 % i == 0){
                    p2 /= i;
                }
            }
        }
        if(p2 > 1){
            p3 = p3 / p2 * (p2 - 1);
        }
    }
    for(int i = 1; i <= n; i ++){
        cin >> a[i];
    }
    t1.MOD = p1, t2.MOD = p3;
    t1.build(1, 1, n), t2.build(1, 1, n);
    int tmp = ksm(k, p3, P2);
    while(m --){
        int op = mread(), l = mread(), r = mread();
        if(op == 1){
            printf("%d\n", t1.query(1, 1, n, l, r));
        }
        else{
            printf("%d\n", 1ll * ksm(k, t2.query(1, 1, n, l, r), P2) * tmp % P2);
        }
    }
    return 0;
}