比赛 |
2024暑假C班集训E |
评测结果 |
EEEEEEWWWWEWTWTTEEEE |
题目名称 |
相逢是问候 |
最终得分 |
0 |
用户昵称 |
wzh0425 |
运行时间 |
12.779 s |
代码语言 |
C++ |
内存使用 |
3.26 MiB |
提交时间 |
2024-07-14 11:08:43 |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
long long n,m,p,c,s[105],k[105];
long long mi(long long x,long long a){
if (!a) return 1;
if (a==1) return x;
if (a%2) return (((mi(x,a/2)*mi(x,a/2)))*x);
return (mi(x,a/2)*mi(x,a/2));
}
int lowbit(int x){
return x&-x;
}
void add(int x,int a){
while (x<=n){
s[x]+=a;
x+=lowbit(x);
}
return;
}
int query(int x){
int cnt=0;
while (x){
cnt+=s[x];
x-=lowbit(x);
}
return cnt;
}
int main(){
freopen("verbinden.in","r",stdin);
freopen("verbinden.out","w",stdout);
scanf("%lld%lld%lld%lld",&n,&m,&p,&c);
for (int i=1;i<=n;i++){
scanf("%d",&s[i]);
k[i]=s[i];
}
if (n>=100&&m>=100){
for (int i=1;i<=m;i++){
long long x,y,z;
scanf("%lld%lld%lld",&x,&y,&z);
if (x==0){
for (int j=y;j<=z;j++){
int b=s[j];
s[j]=mi(c,b);
//cout<<s[j]<<" ";
}
}else{
long long sum=0;
for (int j=y;j<=z;j++){
sum+=s[j];
sum%=p;
}
sum%=p;
printf("%lld\n",sum);
}
}
}else{
for (int i=1;i<=m;i++){
long long x,y,z;
scanf("%lld%lld%lld",&x,&y,&z);
if (x==0){
int tb=query(y);
int tc=mi(c,tb);
add(y,tc-tb);
}else{
cout<<query(z)-query(y-1)<<endl;
}
}
}
}