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>
using namespace std;
const int N = 1e5 + 10;
int n, q;
long long seg[N<<2], k;
void update( int pos, long long val, int l = 1, int r = n, int idx = 1 ) {
if( l > pos || r < pos ) return ;
if( l == r ) return void( seg[idx] = val );
int m = l + r >> 1;
if( pos <= m ) update( pos, val, l, m, idx<<1 );
else update( pos, val, m+1, r, idx<<1|1 );
seg[idx] = seg[idx<<1] + seg[idx<<1|1];
}
void spray( int ll, int rr, int l = 1, int r = n, int idx = 1 ) {
if( l > rr || r < ll ) return ;
if( l == r ) return void( seg[idx] /= k );
int m = l + r >> 1;
spray( ll, rr, l, m, idx<<1 ), spray( ll, rr, m+1, r, idx<<1|1 );
seg[idx] = seg[idx<<1] + seg[idx<<1|1];
}
long long query( int ll, int rr, int l = 1, int r = n, int idx = 1 ) {
if( l > rr || r < ll ) return 0;
if( l >= ll && r <= rr ) return seg[idx];
int m = l + r >> 1;
return query( ll, rr, l, m, idx<<1 ) + query( ll, rr, m+1, r, idx<<1|1 );
}
int main()
{
scanf("%d %d %lld",&n,&q,&k);
for( int i = 1 ; i <= n ; i++ ) {
long long a;
scanf("%lld",&a);
update( i, a );
}
while( q-- ) {
int t, a, b;
scanf("%d %d %d",&t,&a,&b);
if( t == 1 ) update( a, ( long long )b );
else if( t == 2 ) spray( a, b );
else printf("%lld\n",query( a, b ));
}
return 0;
}
Compilation message (stderr)
sterilizing.cpp: In function 'void update(int, long long int, int, int, int)':
sterilizing.cpp:12:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int m = l + r >> 1;
~~^~~
sterilizing.cpp: In function 'void spray(int, int, int, int, int)':
sterilizing.cpp:21:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int m = l + r >> 1;
~~^~~
sterilizing.cpp: In function 'long long int query(int, int, int, int, int)':
sterilizing.cpp:29:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int m = l + r >> 1;
~~^~~
sterilizing.cpp: In function 'int main()':
sterilizing.cpp:35:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %lld",&n,&q,&k);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~
sterilizing.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld",&a);
~~~~~^~~~~~~~~~~
sterilizing.cpp:43:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d",&t,&a,&b);
~~~~~^~~~~~~~~~~~~~~~~~~~~
# | 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... |