#undef _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
void debug_out() {cerr<<endl;}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {cerr<<" "<<to_string(H);debug_out(T...);}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define pb push_back
#define fi first
#define si second
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef tuple<int,int,int> ti;
template<typename T> bool chmin(T &a, T b) {return (b < a) ? a = b, 1 : 0;}
template<typename T> bool chmax(T &a, T b) {return (b > a) ? a = b, 1 : 0;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int N, Q, K;
int C[100010];
struct node {
int s,e,m,val;
node *l, *r;
node(int _s, int _e) {
s = _s, e = _e, m = (s+e)>>1ll;
val = 0;
if (s != e) {
l = new node(s,m);
r = new node(m+1,e);
}
}
void set(int x, int nv) {
if (s == e) {
val = nv;
return;
}
if (x > m) r->set(x, nv);
else l->set(x, nv);
val = l->val + r->val;
}
void spray(int qs, int qe) {
if (val == 0) return;
if (s == e) {
val /= K;
return;
}
if (qs > m) return r->spray(qs, qe);
else if (qe <= m) return l->spray(qs, qe);
else l->spray(qs, m), r->spray(m+1, qe);
val = l->val + r->val;
}
int sum(int qs, int qe) {
if (qs <= s && qe >= e) return val;
if (qs > m) return r->sum(qs, qe);
if (qe <= m) return l->sum(qs, qe);
return l->sum(qs, m) + r->sum(m+1, qe);
}
void printtree() {
debug(s, m, e, val);
if (s != e) {
l->printtree();
r->printtree();
}
}
} *seg;
signed main() {
fast;
cin >> N >> Q >> K;
seg = new node(1, N);
for (int i = 1; i <= N; ++i) {
cin >> C[i];
seg->set(i, C[i]);
}
while (Q--) {
int op, x, y; cin >> op >> x >> y;
if (op == 1) {
seg->set(x, y);
} else if (op == 2) {
seg->spray(x, y);
} else {
// for (int i = 1; i <= N; ++i) cout << seg->sum(i, i) << ' ';
cout << seg->sum(x, y) << '\n';
// break;
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4226 ms |
9076 KB |
Output is correct |
2 |
Correct |
2581 ms |
7060 KB |
Output is correct |
3 |
Correct |
4629 ms |
12772 KB |
Output is correct |
4 |
Execution timed out |
5084 ms |
15576 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
19 ms |
1620 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
92 ms |
8824 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |