#include <bits/stdc++.h>
using namespace std;
array<long long, 31> operator +(array<long long, 31> A, array<long long, 31> B){
for (int i = 0; i < 31; i++){
A[i] += B[i];
}
return A;
}
array<long long, 31> apply(array<long long, 31> A, int x){
x = min(x, 31);
for (int i = 0; i <= 30 - x; i++){
A[i] = A[i + x];
}
for (int i = 31 - x; i < 31; i++){
A[i] = 0;
}
return A;
}
array<long long, 31> get(int x, int K){
array<long long, 31> ans;
ans[0] = x;
for (int i = 0; i < 30; i++){
ans[i + 1] = ans[i] / K;
}
return ans;
}
struct lazy_segment_tree{
int N;
vector<array<long long, 31>> ST;
vector<int> lazy;
lazy_segment_tree(vector<int> A, int K){
int N2 = A.size();
N = 1;
while (N < N2){
N *= 2;
}
ST = vector<array<long long, 31>>(N * 2 - 1);
for (int i = 0; i < N2; i++){
ST[N - 1 + i] = get(A[i], K);
}
for (int i = N2; i < N; i++){
ST[N - 1 + i] = get(0, K);
}
for (int i = N - 2; i >= 0; i--){
ST[i] = ST[i * 2 + 1] + ST[i * 2 + 2];
}
lazy = vector<int>(N * 2 - 1, 0);
}
void eval(int i){
if (i < N - 1){
lazy[i * 2 + 1] += lazy[i];
lazy[i * 2 + 2] += lazy[i];
}
ST[i] = apply(ST[i], lazy[i]);
lazy[i] = 0;
}
void update(int i, int x, int K){
i += N - 1;
vector<int> X;
X.push_back(i);
while (X.back() > 0){
int t = (X.back() - 1) / 2;
X.push_back(t);
}
reverse(X.begin(), X.end());
for (int t : X){
eval(t);
}
ST[i] = get(x, K);
while (i > 0){
i = (i - 1) / 2;
ST[i] = ST[i * 2 + 1] + ST[i * 2 + 2];
}
}
void range_apply(int L, int R, int i, int l, int r){
eval(i);
if (r <= L || R <= l){
return;
} else if (L <= l && r <= R){
lazy[i] = 1;
eval(i);
} else {
int m = (l + r) / 2;
range_apply(L, R, i * 2 + 1, l, m);
range_apply(L, R, i * 2 + 2, m, r);
ST[i] = ST[i * 2 + 1] + ST[i * 2 + 2];
}
}
void range_apply(int L, int R){
range_apply(L, R, 0, 0, N);
}
long long range_sum(int L, int R, int i, int l, int r){
eval(i);
if (r <= L || R <= l){
return 0;
} else if (L <= l && r <= R){
return ST[i][0];
} else {
int m = (l + r) / 2;
return range_sum(L, R, i * 2 + 1, l, m) + range_sum(L, R, i * 2 + 2, m, r);
}
}
long long range_sum(int L, int R){
return range_sum(L, R, 0, 0, N);
}
};
int main(){
int N, Q, K;
cin >> N >> Q >> K;
vector<int> C(N);
for (int i = 0; i < N; i++){
cin >> C[i];
}
lazy_segment_tree ST(C, K);
for (int i = 0; i < Q; i++){
int S, T, U;
cin >> S >> T >> U;
if (S == 1){
T--;
ST.update(T, U, K);
}
if (S == 2){
T--;
ST.range_apply(T, U);
}
if (S == 3){
T--;
cout << ST.range_sum(T, U) << endl;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
621 ms |
35012 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
209 ms |
4904 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
442 ms |
34528 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |