比赛 2025.10.18 评测结果 EEEEEEEEEE
题目名称 Willem, Chtholly and Seniorious 最终得分 0
用户昵称 梦那边的美好BP 运行时间 2.123 s
代码语言 C++ 内存使用 4.54 MiB
提交时间 2025-10-18 11:59:22
显示代码纯文本
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int N = 1e6 + 6;
typedef long long ll;
ll a[N];
int n, m;
ll ksm(ll d, ll z, ll mod) {
    ll ans = 1;
    while (z) {
        if (z & 1) {
            ans *= d;
            ans %= mod;
        }
        ans = ans * ans % mod;
        z /= 2;
    }
    return ans;
}
int main() {
    freopen("kdl.in", "r", stdin);
    freopen("kdl.out", "w", stdout);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    ll op, l, r, x, y;
    while (m--) {
        cin >> op >> l >> r >> x;
        if (op == 1) {
            for (int i = l; i <= r; i++) {
                a[i] += x;
            }
        }
        if (op == 2) {
            for (int i = l; i <= r; i++) {
                a[i] = x;
            }
        }
        if (op == 3) {
            vector<long long> v(r - l + 1);
            for (int i = l; i <= r; i++) {
                v.push_back(a[i]);
            }
            sort(v.begin(), v.end());
            cout << v[x - 1] << endl;
        }
        if (op == 4) {
            cin >> y;
            ll ans = 0;
            for (int i = l; i <= r; i++) {
                ans += ksm(a[i], x, y);
                ans %= y;
            }
            cout << ans << endl;
        }
    }
    return 0;
}