#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
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);
~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
9 ms |
384 KB |
Output is correct |
5 |
Correct |
13 ms |
512 KB |
Output is correct |
6 |
Correct |
13 ms |
512 KB |
Output is correct |
7 |
Correct |
7 ms |
768 KB |
Output is correct |
8 |
Correct |
12 ms |
512 KB |
Output is correct |
9 |
Correct |
14 ms |
512 KB |
Output is correct |
10 |
Correct |
14 ms |
512 KB |
Output is correct |
11 |
Correct |
13 ms |
512 KB |
Output is correct |
12 |
Correct |
14 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4943 ms |
4120 KB |
Output is correct |
2 |
Correct |
3005 ms |
3448 KB |
Output is correct |
3 |
Correct |
4979 ms |
4860 KB |
Output is correct |
4 |
Execution timed out |
5059 ms |
4788 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
214 ms |
888 KB |
Output is correct |
2 |
Correct |
497 ms |
1760 KB |
Output is correct |
3 |
Correct |
750 ms |
2040 KB |
Output is correct |
4 |
Correct |
1575 ms |
2296 KB |
Output is correct |
5 |
Execution timed out |
5071 ms |
4480 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2341 ms |
3256 KB |
Output is correct |
2 |
Correct |
2812 ms |
3516 KB |
Output is correct |
3 |
Correct |
1548 ms |
2868 KB |
Output is correct |
4 |
Correct |
2292 ms |
2880 KB |
Output is correct |
5 |
Execution timed out |
5072 ms |
5076 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |