#include<stdio.h>
#include<assert.h>
#include<vector>
#include<string.h>
#include<algorithm>
#include<memory.h>
#include<cmath>
#include<string>
#include<iostream>
#include<set>
#include<unordered_set>
#include<map>
#include<queue>
#include<functional>
#include<list>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double, double> pdd;
typedef tuple<int,int,int> t3;
const int MX = 1<<17;
const int MM = 1000000007;
struct Tree{
pii t[MX*2];
ll tot[MX*2];
ll sum(int s, int e){
s += MX, e += MX;
ll r = 0;
while( s <= e){
if( s&1 ) r += tot[s++];
if(~e&1 ) r += tot[e--];
s /= 2, e /= 2;
}
return r;
}
pii read(int s, int e){
s += MX, e += MX;
pii mx = pii(0, -1);
while( s <= e){
if( s&1 ) mx = max(mx, t[s++]);
if(~e&1 ) mx = max(mx, t[e--]);
s /= 2, e /= 2;
}
return mx;
}
void update(int x, int v){
x += MX; t[x] = pii(v, x-MX); tot[x] = v;
while(x > 1){
x /= 2; t[x] = max(t[x*2], t[x*2+1]);
tot[x] = tot[x*2] + tot[x*2+1];
}
}
} tree;
int a, b, c, d;
int main()
{
int N, Q, K;
scanf("%d%d%d", &N, &Q, &K);
for(int i = 1; i <= N; i++){
scanf("%d", &a);
tree.update(i, a);
}
for(int i = 1; i <= Q; i++){
scanf("%d%d%d", &a, &b, &c);
if( a == 1 ){
tree.update(b, c);
}
else if( a == 2 ){
if( K != 1 ){
vector<pii> L;
while(1){
pii mx = tree.read(b, c);
if( mx.first == 0 ) break;
tree.update(mx.second, 0);
L.emplace_back(mx.second, mx.first / K);
}
for(pii c : L) tree.update(c.first, c.second);
}
}
else{
printf("%lld\n", tree.sum(b, c));
}
}
}
Compilation message
sterilizing.cpp: In function 'int main()':
sterilizing.cpp:64:29: 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:66:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &a);
^
sterilizing.cpp:70:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &a, &b, &c);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
6116 KB |
Output is correct |
2 |
Correct |
0 ms |
6116 KB |
Output is correct |
3 |
Correct |
6 ms |
6116 KB |
Output is correct |
4 |
Correct |
16 ms |
6116 KB |
Output is correct |
5 |
Correct |
29 ms |
6260 KB |
Output is correct |
6 |
Correct |
16 ms |
6116 KB |
Output is correct |
7 |
Correct |
16 ms |
6260 KB |
Output is correct |
8 |
Correct |
19 ms |
6260 KB |
Output is correct |
9 |
Correct |
23 ms |
6260 KB |
Output is correct |
10 |
Correct |
16 ms |
6256 KB |
Output is correct |
11 |
Correct |
19 ms |
6260 KB |
Output is correct |
12 |
Correct |
23 ms |
6260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
6116 KB |
Output is correct |
2 |
Correct |
76 ms |
6116 KB |
Output is correct |
3 |
Correct |
69 ms |
6116 KB |
Output is correct |
4 |
Correct |
66 ms |
6116 KB |
Output is correct |
5 |
Correct |
86 ms |
6116 KB |
Output is correct |
6 |
Correct |
103 ms |
6116 KB |
Output is correct |
7 |
Correct |
83 ms |
6116 KB |
Output is correct |
8 |
Correct |
93 ms |
6116 KB |
Output is correct |
9 |
Correct |
96 ms |
6116 KB |
Output is correct |
10 |
Correct |
126 ms |
6116 KB |
Output is correct |
11 |
Correct |
93 ms |
6116 KB |
Output is correct |
12 |
Correct |
89 ms |
6116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
6116 KB |
Output is correct |
2 |
Correct |
33 ms |
6324 KB |
Output is correct |
3 |
Correct |
33 ms |
6256 KB |
Output is correct |
4 |
Correct |
69 ms |
6260 KB |
Output is correct |
5 |
Correct |
123 ms |
6388 KB |
Output is correct |
6 |
Correct |
113 ms |
6452 KB |
Output is correct |
7 |
Correct |
79 ms |
6116 KB |
Output is correct |
8 |
Correct |
113 ms |
6584 KB |
Output is correct |
9 |
Correct |
129 ms |
6968 KB |
Output is correct |
10 |
Correct |
116 ms |
6972 KB |
Output is correct |
11 |
Correct |
116 ms |
6968 KB |
Output is correct |
12 |
Correct |
136 ms |
6968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
376 ms |
6972 KB |
Output is correct |
2 |
Correct |
373 ms |
6708 KB |
Output is correct |
3 |
Correct |
773 ms |
7224 KB |
Output is correct |
4 |
Correct |
506 ms |
6708 KB |
Output is correct |
5 |
Correct |
696 ms |
7224 KB |
Output is correct |
6 |
Correct |
869 ms |
7220 KB |
Output is correct |
7 |
Correct |
683 ms |
8244 KB |
Output is correct |
8 |
Correct |
1303 ms |
8244 KB |
Output is correct |
9 |
Correct |
1193 ms |
8244 KB |
Output is correct |
10 |
Correct |
1489 ms |
8244 KB |
Output is correct |
11 |
Correct |
889 ms |
8244 KB |
Output is correct |
12 |
Correct |
2073 ms |
8244 KB |
Output is correct |