#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000007
#define PI 3.14159265359
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005ll
#define CODE_START ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,q,a[100005],tree[400005],k;
void build(ll node,ll l,ll r){
if(l==r){
tree[node]=a[l];
return;
}
ll mid=(l+r)/2;
build(2*node,l,mid);
build(2*node+1,mid+1,r);
tree[node]=tree[node*2]+tree[node*2+1];
}
void update(ll node,ll l,ll r,ll pos,ll val){
if(l==r){
tree[node]=val;
return;
}
ll mid=(l+r)/2;
if(pos<=mid){
update(2*node,l,mid,pos,val);
}else update(2*node+1,mid+1,r,pos,val);
tree[node]=tree[node*2]+tree[node*2+1];
}
void spray(ll node,ll l,ll r,ll st,ll dr){
if(st>r){
return;
}
if(dr<l){
return;
}
if(l==r){
tree[node]/=k;
return;
}
ll mid=(l+r)/2;
if(st<=mid){
spray(2*node,l,mid,st,dr);
}
if(mid<dr){
spray(2*node+1,mid+1,r,st,dr);
}
tree[node]=tree[node*2]+tree[node*2+1];
}
ll query(ll node,ll l,ll r,ll st,ll dr){
if(st<=l&&r<=dr){
return tree[node];
}
if(st>r){
return 0;
}
if(dr<l){
return 0;
}
ll mid=(l+r)/2;
ll res=0;
if(st<=mid){
res+=query(2*node,l,mid,st,dr);
}
if(mid<dr){
res+=query(2*node+1,mid+1,r,st,dr);
}
return res;
}
int32_t main(){
CODE_START;
cin>>n>>q>>k;
for(ll i=1;i<=n;i++)
{
scanf("%ld",&a[i]);
}
build(1,1,n);
while(q--){
ll type,l,r;
scanf("%ld %ld %ld",&type,&l,&r);
if(type==1){
update(1,1,n,l,r);
}else if(type==2){
if(k>=2)
spray(1,1,n,l,r);
}else if(type==3)
cout<<query(1,1,n,l,r)<<endl;
}
}
Compilation message
sterilizing.cpp: In function 'int32_t main()':
sterilizing.cpp:88:14: warning: format '%ld' expects argument of type 'long int*', but argument 2 has type 'long long int*' [-Wformat=]
88 | scanf("%ld",&a[i]);
| ~~^ ~~~~~
| | |
| | long long int*
| long int*
| %lld
sterilizing.cpp:93:14: warning: format '%ld' expects argument of type 'long int*', but argument 2 has type 'long long int*' [-Wformat=]
93 | scanf("%ld %ld %ld",&type,&l,&r);
| ~~^ ~~~~~
| | |
| long int* long long int*
| %lld
sterilizing.cpp:93:18: warning: format '%ld' expects argument of type 'long int*', but argument 3 has type 'long long int*' [-Wformat=]
93 | scanf("%ld %ld %ld",&type,&l,&r);
| ~~^ ~~
| | |
| long int* long long int*
| %lld
sterilizing.cpp:93:22: warning: format '%ld' expects argument of type 'long int*', but argument 4 has type 'long long int*' [-Wformat=]
93 | scanf("%ld %ld %ld",&type,&l,&r);
| ~~^ ~~
| | |
| long int* long long int*
| %lld
sterilizing.cpp:88:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
88 | scanf("%ld",&a[i]);
| ~~~~~^~~~~~~~~~~~~
sterilizing.cpp:93:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
93 | scanf("%ld %ld %ld",&type,&l,&r);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
60 ms |
2284 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
285 ms |
748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3743 ms |
2104 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |