比赛 寒假集训4 评测结果 WWEEEEEEEE
题目名称 数据结构题 最终得分 0
用户昵称 ChenBp 运行时间 1.897 s
代码语言 C++ 内存使用 3.47 MiB
提交时间 2026-02-28 12:28:42
显示代码纯文本
#include <iostream>
using namespace std;
typedef long long ll;
ll a[5003], b[5003];
ll n, m;
void s() {
    for (int i = 1; i <= n; i++) {
        a[i] = a[i - 1] + b[i];
        // b[i] = a[i] - a[i - 1];
    }
}
ll ksm(ll x, ll y, ll p) {
    ll res = 1;
    while (y) {
        if (y & 1) res = (res * x) % p;
        x = (x * x) % p;
        y >>= 1;
    }
    return res;
}
int main() {
    freopen("sjjgt.in", "r", stdin);
    freopen("sjjgt.out", "w", stdout);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        b[i] = a[i] - a[i - 1];
    }
    while (m--) {
        ll op, l, r, x;
        cin >> op >> l >> r >> x;
        if (op == 1) {
            b[l] += x;
            b[r + 1] -= x;
        } else {
            s();
            //            cout<<"@";for(int i=1;i<=n;i++) cout<<a[i]<<" \n"[i==n];
            ll now = a[r];
            for (int i = r - 1; i >= l; i--) {
                //                cout<<"!"<<a[i]<<" "<<now<<endl;
                now = ksm(a[i], now, x);
            }
            cout << now << endl;
        }
    }
    return 0;
}