比赛 2024暑假C班集训E 评测结果 WWTWTWTTTTTTWWWWTTTT
题目名称 相逢是问候 最终得分 0
用户昵称 袁书杰 运行时间 37.353 s
代码语言 C++ 内存使用 3.73 MiB
提交时间 2024-07-14 11:30:51
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
unsigned long long n,m,p,c,a[50005],s[50005];
unsigned long long ksm(unsigned long long p,unsigned long long x,unsigned long long p1) {
	unsigned long long ans=1;
	while(p1!=0) {
		if(p1%2) {
			ans*=p;
		}
		p*=p;
		p1/=2;
	}
	return ans;
}
int main() {
    freopen("verbinden.in","r",stdin);
    freopen("verbinden.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>n>>m>>p>>c;
	for(unsigned long long i=1; i<=n; i++) {
		cin>>a[i];
		s[i]=s[i-1]+a[i];
		s[i]%=p;
	}
	while(m--) {
		unsigned  long long op,l,r;
		cin>>op>>l>>r;
		if(op==1) {
			cout<<(s[r]-s[l-1])%p<<'\n';
		} else {
			for(unsigned   long long i=l; i<=r; i++) {
				a[i]=ksm(c,p,a[i]);
			}
			for(unsigned  long long i=l; i<=n; i++) {
				s[i]=s[i-1]+a[i];
				s[i]%=p;
			}
		}
	}
	return 0;
}