# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
989964 |
2024-05-29T08:59:44 Z |
LOLOLO |
Addk (eJOI21_addk) |
C++14 |
|
209 ms |
18392 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f first
#define s second
#define pb push_back
#define ep emplace
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define mem(f,x) memset(f , x , sizeof(f))
#define sz(x) (ll)(x).size()
#define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b))
#define mxx *max_element
#define mnn *min_element
#define cntbit(x) __builtin_popcountll(x)
#define len(x) (int)(x.length())
const int N = 5e5;
ll sz[N], seg[N], laz[N];
void push(int id) {
ll t = laz[id];
laz[id * 2] += t;
laz[id * 2 + 1] += t;
seg[id * 2] += sz[id * 2] * t;
seg[id * 2 + 1] += sz[id * 2 + 1] * t;
laz[id] = 0;
}
void build(int id, int l, int r) {
sz[id] = r - l + 1;
if (l == r)
return;
int m = (l + r) / 2;
build(id * 2, l, m);
build(id * 2 + 1, m + 1, r);
}
void upd(int id, int l, int r, int u, int v, ll c) {
if (l > v || r < u)
return;
if (l >= u && r <= v) {
seg[id] += sz[id] * c;
laz[id] += c;
return;
}
push(id);
int m = (l + r) / 2;
upd(id * 2, l, m, u, v, c);
upd(id * 2 + 1, m + 1, r, u, v, c);
seg[id] = seg[id * 2] + seg[id * 2 + 1];
}
ll range(int id, int l, int r, int u, int v) {
if (l > v || r < u || u > v)
return 0;
if (l >= u && r <= v) {
return seg[id];
}
push(id);
int m = (l + r) / 2;
return range(id * 2, l, m, u, v) + range(id * 2 + 1, m + 1, r, u, v);
}
ll a[N];
void solve() {
int n, k;
cin >> n >> k;
build(1, 0, n);
for (int i = 1; i <= n; i++) {
cin >> a[i];
upd(1, 0, n, i, n, a[i]);
}
int q;
cin >> q;
for (int i = 1; i <= q; i++) {
int t;
cin >> t;
if (t == 1) {
vector <int> val, pos;
int fs = -1;
for (int j = 0; j < k; j++) {
int x;
cin >> x;
if (fs == -1) {
fs = a[x];
} else {
val.pb(a[x]);
}
pos.pb(x);
}
val.pb(fs);
for (int j = 0; j < k; j++) {
upd(1, 0, n, pos[j], n, val[j] - a[pos[j]]);
a[pos[j]] = val[j];
}
} else {
int l, r, m;
cin >> l >> r >> m;
cout << range(1, 0, n, l + m - 1, r) - range(1, 0, n, l - 1, r - m) << '\n';
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
//cin >> t;
while (t--) {
solve();
}
return 0;
}
/*
8 3
7 2 5 1 9 3 4 6
3
2 2 7 5
1 2 5 8
2 2 7 3
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
3 ms |
4444 KB |
Output is correct |
4 |
Correct |
5 ms |
4696 KB |
Output is correct |
5 |
Correct |
4 ms |
4696 KB |
Output is correct |
6 |
Correct |
5 ms |
4696 KB |
Output is correct |
7 |
Correct |
6 ms |
4696 KB |
Output is correct |
8 |
Correct |
6 ms |
4700 KB |
Output is correct |
9 |
Correct |
9 ms |
5040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
7256 KB |
Output is correct |
2 |
Correct |
31 ms |
9564 KB |
Output is correct |
3 |
Correct |
43 ms |
13888 KB |
Output is correct |
4 |
Correct |
73 ms |
14336 KB |
Output is correct |
5 |
Correct |
108 ms |
14672 KB |
Output is correct |
6 |
Correct |
102 ms |
14672 KB |
Output is correct |
7 |
Correct |
110 ms |
14416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
79 ms |
13648 KB |
Output is correct |
2 |
Correct |
108 ms |
16724 KB |
Output is correct |
3 |
Correct |
209 ms |
18392 KB |
Output is correct |
4 |
Correct |
125 ms |
17492 KB |
Output is correct |