#include<bits/stdc++.h>
#define STIZE(x) fprintf(stderr, "STIZE%d\n", x);
#define PRINT(x) fprintf(stderr, "%s = %d\n", #x, x);
#define NL(x) printf("%c", " \n"[(x)]);
#define lld long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mid (l+r)/2
#define endl '\n'
#define all(a) begin(a),end(a)
#define sz(a) int((a).size())
#define LINF 1000000000000000LL
#define INF 1000000000
#define EPS 1e-9
using namespace std;
#define MAXN 100010
set<int> s;
vector<int> izbaciti;
lld bit[MAXN];
lld query(int idx) {
lld rez = 0;
for( ; idx > 0; idx -= idx&-idx) rez += bit[idx];
return rez;
}
lld query1(int idx) { return query(idx) - query(idx-1); }
void update(int idx, lld val) {
val -= query1(idx);
for( ; idx < MAXN; idx += idx&-idx) bit[idx] += val;
}
int main() {
ios::sync_with_stdio(false);cin.tie(0);
lld N, Q, K, a; cin >> N >> Q >> K;
for(int i = 1; i <= N; i++) {
cin >> a; update(i, a);
if(a != 0) s.insert(i);
}
while(Q--) {
int type, u1, u2; cin >> type >> u1 >> u2;
if(type == 1) {
update(u1, u2);
if(u2 != 0) s.insert(u1);
} else if(type == 2) {
for(auto it = s.lower_bound(u1); it != s.end(); it++) {
if(*it > u2) break;
update(*it, query1(*it)/K);
if(query(*it) == 0) izbaciti.pb(*it);
}
for(auto x : izbaciti) s.erase(x);
izbaciti.clear();
} else {
cout << query(u2) - query(u1-1) << endl;
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
376 KB |
Output is correct |
2 |
Correct |
7 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
588 KB |
Output is correct |
4 |
Correct |
23 ms |
716 KB |
Output is correct |
5 |
Correct |
51 ms |
768 KB |
Output is correct |
6 |
Correct |
51 ms |
824 KB |
Output is correct |
7 |
Correct |
53 ms |
824 KB |
Output is correct |
8 |
Correct |
49 ms |
832 KB |
Output is correct |
9 |
Correct |
58 ms |
880 KB |
Output is correct |
10 |
Correct |
54 ms |
880 KB |
Output is correct |
11 |
Correct |
49 ms |
880 KB |
Output is correct |
12 |
Correct |
61 ms |
880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5028 ms |
4384 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1078 ms |
4384 KB |
Output is correct |
2 |
Correct |
2849 ms |
4384 KB |
Output is correct |
3 |
Correct |
4758 ms |
4384 KB |
Output is correct |
4 |
Correct |
2107 ms |
4384 KB |
Output is correct |
5 |
Execution timed out |
5038 ms |
5032 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5039 ms |
5376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |