比赛 2025.10.18 评测结果 RRRRRRRRRR
题目名称 Willem, Chtholly and Seniorious 最终得分 0
用户昵称 彭欣越 运行时间 0.028 s
代码语言 C++ 内存使用 4.01 MiB
提交时间 2025-10-18 11:55:29
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100010;
ll n,m,a[N],b[N];
ll ksm (int x,int k,int p) {
	ll res=1;
	while (k) {
		if (k&1) {
		    res*=x;
		    res%=p;
		}
		x*=x;
		x%=p;
		k>>=1;
	}
	return res;
}
int main() {
	freopen("Willem, Chtholly and Seniorious.in","r",stdin);
	freopen("Willem, Chtholly and Seniorious.out","w",stdout); 
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin >> n >> m;
    for (int i=1;i<=n;i++) {
    	cin >> a[i];
	}
	while (m--) {
		int op,l,r,x,y;
		cin >> op >> l >> r >> x;
		if (op==1) {
			for (int i=l;i<=r;i++) a[i]+=x;
		}else if (op==2) {
			for (int i=l;i<=r;i++) a[i]=x;
		}else if (op==3) {
			for (int i=l;i<=r;i++) b[i]=a[i];
			sort(b+l+1,b+r+1);
			cout << b[l+x-1] <<endl;
		}else{
			ll sum=0,ans=0;
			cin >> y;
			for (int i=l;i<=r;i++) {
				sum=ksm(a[i],x,y);
				ans+=sum;
				ans%=y;
			}
			cout << ans <<endl;
		}
	}
    return 0;
}