/** MIT License Copyright (c) 2018 Vasilyev Daniil **/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
#pragma GCC optimize("Ofast")
template<typename T> using v = vector<T>;
template<typename T, typename U> using hmap = __gnu_pbds::gp_hash_table<T, U>;
#define int long long
typedef long double ld;
typedef string str;
typedef vector<int> vint;
#define rep(a, l, r) for(int a = (l); a < (r); a++)
#define pb push_back
#define fs first
#define sc second
#define sz(a) ((int) a.size())
const long long inf = 4611686018427387903; //2^62 - 1
#if 0 //FileIO
const string fileName = "";
ifstream fin ((fileName == "" ? "input.txt" : fileName + ".in" ));
ofstream fout((fileName == "" ? "output.txt" : fileName + ".out"));
#define get fin>>
#define put fout<<
#else
#define get cin>>
#define put cout<<
#endif
#define eol put endl
#define check(a) put #a << ": " << a << endl;
void read() {} template<typename Arg,typename... Args> void read (Arg& arg,Args&... args){get (arg) ;read(args...) ;}
void print(){} template<typename Arg,typename... Args> void print(Arg arg,Args... args){put (arg)<<" ";print(args...);}
void debug(){eol;} template<typename Arg,typename... Args> void debug(Arg arg,Args... args){put (arg)<<" ";debug(args...);}
int getInt(){int a; get a; return a;}
//code goes here
struct node {
int val = 0;
int rem = 0;
int lazy = 0;
node() {}
};
const int N = 131072;
node segTree[N * 2];
int k;
int powsOfK[N];
void processLazy(int cur) {
if (cur < N) {
segTree[cur * 2].lazy += segTree[cur].lazy;
segTree[cur * 2 + 1].lazy += segTree[cur].lazy;
}
if (segTree[cur].lazy) {
segTree[cur].val -= segTree[cur].rem;
segTree[cur].rem = 0;
segTree[cur].val /= powsOfK[segTree[cur].lazy];
segTree[cur].lazy = 0;
}
}
void updatePos(int p, int val, int cur = 1, int ll = 1, int rr = N) {
processLazy(cur);
if (ll == rr){
segTree[cur].val = val;
segTree[cur].rem = val % k;
return;
}
int mid = (ll + rr) / 2;
if (p <= mid) {
updatePos(p, val, cur * 2, ll, mid);
processLazy(cur * 2 + 1);
} else {
processLazy(cur * 2);
updatePos(p, val, cur * 2 + 1, mid + 1, rr);
}
segTree[cur].val = segTree[cur * 2].val + segTree[cur * 2 + 1].val;
segTree[cur].rem = segTree[cur * 2].rem + segTree[cur * 2 + 1].rem;
}
void spray(int l, int r, int cur = 1, int ll = 1, int rr = N) {
//debug(l, r, cur, ll, rr);
if (l == ll && r == rr)
segTree[cur].lazy++;
processLazy(cur);
if (l > r || (l == ll && r == rr))
return;
int mid = (ll + rr) / 2;
spray(l, min(r, mid), cur * 2, ll, mid);
spray(max(l, mid + 1), r, cur * 2 + 1, mid + 1, rr);
segTree[cur].val = segTree[cur * 2].val + segTree[cur * 2 + 1].val;
segTree[cur].rem = segTree[cur * 2].rem + segTree[cur * 2 + 1].rem;
}
int query(int l, int r, int cur = 1, int ll = 1, int rr = N) {
processLazy(cur);
if (l > r)
return 0;
if (l == ll && r == rr)
return segTree[cur].val;
int mid = (ll + rr) / 2;
return query(l, min(r, mid), cur * 2, ll, mid) + query(max(l, mid + 1), r, cur * 2 + 1, mid + 1, rr);
}
void run() {
int n, q;
read(n, q, k);
powsOfK[0] = 1;
rep(i, 1, N)
powsOfK[i] = min(k * powsOfK[i - 1], 1000000001ll);
rep(i, 0, n)
updatePos(i + 1, getInt());
for (; q; q--) {
int s, t, u;
read(s, t, u);
if (s == 1)
updatePos(t, u);
else if (s == 2)
spray(t, u);
else
put query(t, u), eol;
}
}
int32_t main() {srand(time(0)); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); put fixed; put setprecision(15); run(); return 0;}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
7544 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
245 ms |
8620 KB |
Output is correct |
2 |
Correct |
192 ms |
10228 KB |
Output is correct |
3 |
Correct |
195 ms |
11964 KB |
Output is correct |
4 |
Correct |
260 ms |
14108 KB |
Output is correct |
5 |
Correct |
265 ms |
16604 KB |
Output is correct |
6 |
Correct |
268 ms |
19116 KB |
Output is correct |
7 |
Correct |
262 ms |
21584 KB |
Output is correct |
8 |
Correct |
272 ms |
24268 KB |
Output is correct |
9 |
Correct |
225 ms |
26616 KB |
Output is correct |
10 |
Correct |
224 ms |
28652 KB |
Output is correct |
11 |
Correct |
233 ms |
31024 KB |
Output is correct |
12 |
Correct |
243 ms |
33508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
33508 KB |
Output is correct |
2 |
Correct |
53 ms |
33508 KB |
Output is correct |
3 |
Correct |
71 ms |
33508 KB |
Output is correct |
4 |
Correct |
209 ms |
33508 KB |
Output is correct |
5 |
Correct |
261 ms |
33508 KB |
Output is correct |
6 |
Correct |
247 ms |
33508 KB |
Output is correct |
7 |
Correct |
265 ms |
33636 KB |
Output is correct |
8 |
Correct |
254 ms |
35008 KB |
Output is correct |
9 |
Correct |
215 ms |
36320 KB |
Output is correct |
10 |
Correct |
223 ms |
37576 KB |
Output is correct |
11 |
Correct |
220 ms |
38896 KB |
Output is correct |
12 |
Correct |
211 ms |
40012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
163 ms |
40132 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |