#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
struct node
{
ll sum;
int Max, pos;
node(ll sum = 0, int Max = 0, int pos = 0):
sum(sum), Max(Max), pos(pos) {}
node operator + (const node & other) const
{
node res; res.sum = sum + other.sum;
res.Max = max(Max, other.Max);
res.pos = (Max < other.Max) ? other.pos : pos;
return res;
}
}ST[4 * maxn];
int N, Q, K;
#define lc id << 1
#define rc id << 1 | 1
void build(int id, int l, int r)
{
if (l == r){
ST[id].pos = l;
return;
}
int mid = (l + r) / 2;
build(lc, l, mid); build(rc, mid + 1, r);
}
void update(int id, int l, int r, int i, int val)
{
if (r < i || l > i) return;
if (l == r){
ST[id].Max = ST[id].sum = val;
return;
}
int mid = (l + r) / 2;
update(lc, l, mid, i, val); update(rc, mid + 1, r, i, val);
ST[id] = ST[lc] + ST[rc];
}
void rupd(int id, int l, int r ,int L, int R)
{
if (l > R || L > r || ST[id].Max == 0){
return;
}
if (l == r){
ST[id].Max = ST[id].sum = ST[id].Max / K;
return;
}
int mid = (l + r) / 2;
rupd(lc, l, mid, L, R); rupd(rc, mid + 1, r, L, R);
ST[id] = ST[lc] + ST[rc];
}
node query(int id, int l, int r, int L, int R)
{
if (L <= l && r <= R){
return ST[id];
}
if (L > r || l > R) return node(0, -1e9);
int mid = (l + r) / 2;
return query(lc, l, mid, L, R) + query(rc, mid + 1, r, L, R);
}
#undef lc
#undef rc
signed main(void)
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if (fopen("A.INP", "r")){
freopen("A.INP", "r", stdin);
freopen("A.OUT", "w", stdout);
}
cin >> N >> Q >> K;
build(1, 1, N);
for (int i = 1; i <= N; ++i){
int x; cin >> x;
update(1, 1, N, i, x);
}
for (int i = 1; i <= Q; ++i){
int type; cin >> type;
if (type == 1){
int pos, val; cin >> pos >> val;
update(1 ,1, N, pos, val);
}
else if (type == 2){
int l, r; cin >> l >> r;
rupd(1, 1, N, l, r);
}
else{
int l, r; cin >> l >> r;
cout << query(1, 1, N, l, r).sum << '\n';
}
}
}
Compilation message
sterilizing.cpp: In function 'int main()':
sterilizing.cpp:84:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen("A.INP", "r", stdin);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~
sterilizing.cpp:85:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen("A.OUT", "w", stdout);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
6648 KB |
Output is correct |
2 |
Correct |
11 ms |
6648 KB |
Output is correct |
3 |
Correct |
10 ms |
6648 KB |
Output is correct |
4 |
Correct |
12 ms |
6648 KB |
Output is correct |
5 |
Correct |
13 ms |
6648 KB |
Output is correct |
6 |
Correct |
13 ms |
6648 KB |
Output is correct |
7 |
Correct |
13 ms |
6648 KB |
Output is correct |
8 |
Correct |
13 ms |
6648 KB |
Output is correct |
9 |
Correct |
15 ms |
6776 KB |
Output is correct |
10 |
Correct |
14 ms |
6752 KB |
Output is correct |
11 |
Correct |
12 ms |
6648 KB |
Output is correct |
12 |
Correct |
14 ms |
6648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5090 ms |
8560 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
7032 KB |
Output is correct |
2 |
Correct |
29 ms |
6904 KB |
Output is correct |
3 |
Correct |
39 ms |
7032 KB |
Output is correct |
4 |
Correct |
76 ms |
7928 KB |
Output is correct |
5 |
Correct |
103 ms |
8184 KB |
Output is correct |
6 |
Correct |
103 ms |
8060 KB |
Output is correct |
7 |
Execution timed out |
5043 ms |
7916 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
120 ms |
8312 KB |
Output is correct |
2 |
Correct |
135 ms |
8544 KB |
Output is correct |
3 |
Correct |
152 ms |
7928 KB |
Output is correct |
4 |
Correct |
165 ms |
8544 KB |
Output is correct |
5 |
Correct |
192 ms |
9336 KB |
Output is correct |
6 |
Correct |
215 ms |
9336 KB |
Output is correct |
7 |
Correct |
210 ms |
9492 KB |
Output is correct |
8 |
Correct |
255 ms |
9336 KB |
Output is correct |
9 |
Correct |
247 ms |
9208 KB |
Output is correct |
10 |
Correct |
253 ms |
9208 KB |
Output is correct |
11 |
Correct |
207 ms |
9376 KB |
Output is correct |
12 |
Correct |
343 ms |
9208 KB |
Output is correct |