This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
const int MAXN = 1e5+10 ;
using namespace std ;
int N , Q , K ;
struct SimpleSeg
{
long long tree[MAXN*4] ;
int m(int l, int r ) { return (l+r)>>1 ; }
void upd(int pos, int l, int r, int k, long long val )
{
if( l == r ) return (void)(tree[pos] = val) ;
if( k <= m(l,r) ) upd(pos<<1 , l, m(l,r), k , val ) ;
else upd(pos<<1|1 , m(l,r)+1, r, k , val ) ;
tree[pos] = tree[pos<<1] + tree[pos<<1|1] ;
}
void spray(int pos, int l, int r, int beg, int en )
{
if( K == 1 || tree[pos] == 0LL || l > en || r < beg ) return ;
if( l == r ) return (void)(tree[pos] /= K ) ;
spray(pos<<1 , l , m(l,r) , beg, en ) ;
spray(pos<<1|1 , m(l,r)+1, r, beg, en ) ;
tree[pos] = tree[pos<<1] + tree[pos<<1|1] ;
}
long long qry(int pos, int l, int r, int beg, int en )
{
if( l > en || r < beg ) return 0LL ;
if( l >= beg && r <= en ) return tree[pos] ;
long long al = qry(pos<<1 , l , m(l,r) , beg, en ) ;
long long ar = qry(pos<<1|1 , m(l,r)+1 , r , beg, en ) ;
return al + ar ;
}
} seg ;
int main()
{
scanf("%d %d %d", &N, &Q, &K ) ;
for(int i = 1 ; i <= N ; i++ )
{
long long trash ;
scanf("%lld", &trash) ;
seg.upd(1,1,N, i, trash ) ;
}
for(int i = 1 , t , l, r ; i <= Q ; i++ )
{
scanf("%d %d %d", &t, &l, &r ) ;
if( t == 1 ) seg.upd(1,1,N,l , r ) ;
else if(t == 2 ) seg.spray(1,1,N, l, r ) ;
else if(t == 3 ) printf("%lld\n", seg.qry(1,1,N, l, r ) ) ;
}
}
Compilation message (stderr)
sterilizing.cpp: In function 'int main()':
sterilizing.cpp:54:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
54 | scanf("%d %d %d", &N, &Q, &K ) ;
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sterilizing.cpp:59:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
59 | scanf("%lld", &trash) ;
| ~~~~~^~~~~~~~~~~~~~~~
sterilizing.cpp:67:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
67 | scanf("%d %d %d", &t, &l, &r ) ;
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |