#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_set>
#include <bitset>
#include <time.h>
#include <limits.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define Fi first
#define Se second
#define pb push_back
#define szz(x) (int)x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
typedef tuple<int, int, int> t3;
int N, K, Q;
int A[100010];
ll T[1<<18];
int H[1<<18];
void init(int rt, int l, int r) {
if(l == r) T[rt] = A[l];
else {
int m = (l + r) >> 1;
init(rt*2, l, m);
init(rt*2+1, m+1, r);
T[rt] = T[rt*2] + T[rt*2+1];
H[rt] = H[rt*2] & H[rt*2+1];
}
}
void update_v(int rt, int l, int r, int x, int v) {
if(l == r) {
T[rt] = v;
H[rt] = (v == 0);
return;
}
int m = (l + r) >> 1;
if(x <= m) update_v(rt*2, l, m, x, v);
else update_v(rt*2+1, m+1, r, x, v);
T[rt] = T[rt*2] + T[rt*2+1];
H[rt] = H[rt*2] & H[rt*2+1];
}
void update_s(int rt, int l, int r, int s, int e) {
if(H[rt]) return;
if(l == r) {
T[rt] /= K;
H[rt] = (T[rt] == 0);
return;
}
int m = (l + r) >> 1;
if(s <= m) update_s(rt*2, l, m, s, e);
if(m < e) update_s(rt*2+1, m+1, r, s, e);
T[rt] = T[rt*2] + T[rt*2+1];
H[rt] = H[rt*2] & H[rt*2+1];
}
ll get_sum(int rt, int l, int r, int s, int e) {
if(s <= l && r <= e) return T[rt];
int m = (l + r) >> 1;
ll res = 0;
if(s <= m) res += get_sum(rt*2, l, m, s, e);
if(m < e) res += get_sum(rt*2+1, m+1, r, s, e);
return res;
}
int main() {
scanf("%d%d%d", &N, &Q, &K);
for(int i=1;i<=N;i++) scanf("%d", A + i);
init(1, 1, N);
for(int i=1;i<=Q;i++) {
int cmd; scanf("%d", &cmd);
if(cmd == 1) {
int x, y; scanf("%d%d", &x, &y);
update_v(1, 1, N, x, y);
}
else if(cmd == 2) {
int l, r; scanf("%d%d", &l, &r);
update_s(1, 1, N, l, r);
}
else {
int l, r; scanf("%d%d", &l, &r);
printf("%lld\n", get_sum(1, 1, N, l, r));
}
}
return 0;
}
Compilation message
sterilizing.cpp: In function 'int main()':
sterilizing.cpp:86:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &N, &Q, &K);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
sterilizing.cpp:87:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i=1;i<=N;i++) scanf("%d", A + i);
~~~~~^~~~~~~~~~~~~
sterilizing.cpp:90:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int cmd; scanf("%d", &cmd);
~~~~~^~~~~~~~~~~~
sterilizing.cpp:92:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int x, y; scanf("%d%d", &x, &y);
~~~~~^~~~~~~~~~~~~~~~
sterilizing.cpp:96:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int l, r; scanf("%d%d", &l, &r);
~~~~~^~~~~~~~~~~~~~~~
sterilizing.cpp:100:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int l, r; scanf("%d%d", &l, &r);
~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
7 ms |
512 KB |
Output is correct |
5 |
Correct |
8 ms |
512 KB |
Output is correct |
6 |
Correct |
7 ms |
640 KB |
Output is correct |
7 |
Correct |
7 ms |
512 KB |
Output is correct |
8 |
Correct |
8 ms |
512 KB |
Output is correct |
9 |
Correct |
7 ms |
512 KB |
Output is correct |
10 |
Correct |
5 ms |
512 KB |
Output is correct |
11 |
Correct |
6 ms |
512 KB |
Output is correct |
12 |
Correct |
6 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5063 ms |
4096 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
1024 KB |
Output is correct |
2 |
Correct |
18 ms |
2304 KB |
Output is correct |
3 |
Correct |
28 ms |
2436 KB |
Output is correct |
4 |
Correct |
55 ms |
2504 KB |
Output is correct |
5 |
Correct |
116 ms |
5280 KB |
Output is correct |
6 |
Correct |
80 ms |
5240 KB |
Output is correct |
7 |
Execution timed out |
5088 ms |
4852 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
3768 KB |
Output is correct |
2 |
Correct |
139 ms |
3972 KB |
Output is correct |
3 |
Correct |
159 ms |
3348 KB |
Output is correct |
4 |
Correct |
136 ms |
3196 KB |
Output is correct |
5 |
Correct |
176 ms |
6648 KB |
Output is correct |
6 |
Correct |
192 ms |
6624 KB |
Output is correct |
7 |
Correct |
167 ms |
6520 KB |
Output is correct |
8 |
Correct |
253 ms |
6568 KB |
Output is correct |
9 |
Correct |
242 ms |
6380 KB |
Output is correct |
10 |
Correct |
257 ms |
6496 KB |
Output is correct |
11 |
Correct |
172 ms |
6452 KB |
Output is correct |
12 |
Correct |
301 ms |
6580 KB |
Output is correct |