#include<bits/stdc++.h>
#include<fstream>
#pragma GCC optimize("Ofast,O3,unroll-loops")
#pragma GCC target("avx2")
using namespace std;
//ifstream fin("FEEDING.INP");
//ofstream fout("FEEDING.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const int mxn = 1e5 + 5, base = 74;
const ll p = 31, mod = 1e9 + 7;
int n, q, k;
ll sm[4 * mxn + 1], mx[4 * mxn + 1], bad[4 * mxn + 1], c[mxn + 1];
void push(int nd){
if(bad[nd]){
bad[nd << 1] = bad[nd << 1 | 1] = 1;
sm[nd << 1] = sm[nd << 1 | 1] = mx[nd << 1] = mx[nd << 1 | 1] = 0;
}
}
void upd(int nd, int l, int r, int id, int v){
if(id < l || id > r)return;
if(l == r){
sm[nd] = mx[nd] = v;
bad[nd] = !v;
return;
}
int mid = (l + r) >> 1;
push(nd);
upd(nd << 1, l, mid, id, v); upd(nd << 1 | 1, mid + 1, r, id, v);
sm[nd] = sm[nd << 1] + sm[nd << 1 | 1];
mx[nd] = max(mx[nd << 1], mx[nd << 1 | 1]);
bad[nd] = (mx[nd] == 0);
}
void upd2(int nd, int l, int r, int ql, int qr){
if(ql > r || qr < l)return;
if(ql <= l && qr >= r){
if(mx[nd] < k){
bad[nd] = 1; sm[nd] = 0; mx[nd] = 0;
return;
}else if(l == r){
mx[nd] /= k; sm[nd] /= k;
return;
}
}
int mid = (l + r) >> 1;
push(nd);
upd2(nd << 1, l, mid, ql, qr); upd2(nd << 1 | 1, mid + 1, r, ql, qr);
sm[nd] = sm[nd << 1] + sm[nd << 1 | 1];
mx[nd] = max(mx[nd << 1], mx[nd << 1 | 1]);
bad[nd] = (mx[nd] == 0);
}
ll get(int nd, int l, int r, int ql, int qr){
if(ql > r || qr < l)return(0);
if(ql <= l && qr >= r)return(sm[nd]);
push(nd);
int mid = (l + r) >> 1;
return(get(nd << 1, l, mid, ql, qr) + get(nd << 1 | 1, mid + 1, r, ql, qr));
}
void solve2(){
for(int i = 1; i <= n; i++){
cin >> c[i];
upd(1, 1, n, i, c[i]);
}
while(q--){
int idq; cin >> idq;
if(idq == 1){
int id, v; cin >> id >> v;
upd(1, 1, n, id, v);
}else if(idq == 2){
int l, r; cin >> l >> r;
upd2(1, 1, n, l, r);
}else{
int l, r; cin >> l >> r;
cout << get(1, 1, n, l, r) << "\n";
}
}
}
ll bit[mxn + 1];
void upd(int p, ll v){
while(p <= n){
bit[p] += v; p += p & (-p);
}
}
ll get(int p){
ll ans =0 ;
while(p){
ans += bit[p]; p -= p & (-p);
}
return(0);
}
void solve1(){
for(int i = 1; i <= n; i++){
cin >> c[i]; upd(i, c[i]);
}
while(q--){
int idq; cin >> idq;
if(idq == 1){
int id, v; cin >> id >> v;
upd(id, -c[id]); upd(id, v); c[id] = v;
}else if(idq == 2){
int l, r; cin >> l >> r;
}else{
int l, r; cin >> l >> r;
cout << get(r) - get(l - 1) << "\n";
}
}
}
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> q >> k;
if(k == 1){
solve1();
}else{
solve2();
}
return(0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
24 ms |
3020 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
1244 KB |
Output is correct |
2 |
Correct |
15 ms |
3992 KB |
Output is correct |
3 |
Correct |
21 ms |
4164 KB |
Output is correct |
4 |
Correct |
46 ms |
3240 KB |
Output is correct |
5 |
Correct |
67 ms |
8656 KB |
Output is correct |
6 |
Correct |
67 ms |
8680 KB |
Output is correct |
7 |
Incorrect |
24 ms |
3320 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
5528 KB |
Output is correct |
2 |
Correct |
85 ms |
5684 KB |
Output is correct |
3 |
Correct |
96 ms |
5080 KB |
Output is correct |
4 |
Correct |
109 ms |
4044 KB |
Output is correct |
5 |
Correct |
131 ms |
9960 KB |
Output is correct |
6 |
Correct |
141 ms |
9948 KB |
Output is correct |
7 |
Correct |
124 ms |
9932 KB |
Output is correct |
8 |
Correct |
173 ms |
9940 KB |
Output is correct |
9 |
Correct |
152 ms |
9848 KB |
Output is correct |
10 |
Correct |
180 ms |
9860 KB |
Output is correct |
11 |
Correct |
131 ms |
9804 KB |
Output is correct |
12 |
Correct |
230 ms |
9892 KB |
Output is correct |