This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,fma,bmi,bmi2,sse4.2,popcnt,lzcnt")
*/
#include <bits/stdc++.h>
#define taskname ""
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define int long long
#define ll long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define isz(x) (int)x.size()
using namespace std;
const int mxN = 1e5 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;
struct node {
int val, lazy;
node() {val = lazy = 0;}
node operator + (const node &o) {
node res;
res.val = val + o.val;
return res;
}
} segtree[4 * mxN];
int n, k, q, a[mxN];
void down(int idx, int l, int r) {
if(segtree[idx].lazy == 0)
return;
int val = segtree[idx].lazy, mid = (l + r) >> 1;
segtree[idx << 1].val += val * (mid - l + 1);
segtree[idx << 1].lazy += val;
segtree[idx << 1 | 1].val += val * (r - mid);
segtree[idx << 1 | 1].lazy += val;
segtree[idx].lazy = 0;
}
void update(int l, int r, int idx, int u, int v, int val) {
if(r < u || v < l) return;
if(u <= l && r <= v) {
segtree[idx].val += (r - l + 1) * val;
segtree[idx].lazy += val;
return;
}
down(idx, l, r);
int mid = (l + r) >> 1;
update(l, mid, idx << 1, u, v, val);
update(mid + 1, r, idx << 1 | 1, u, v, val);
segtree[idx] = segtree[idx << 1] + segtree[idx << 1 | 1];
}
int get(int l, int r, int idx, int u, int v) {
if(r < u || v < l) return 0;
if(u <= l && r <= v)
return segtree[idx].val;
down(idx, l, r);
int mid = (l + r) >> 1;
return get(l, mid, idx << 1, u, v) + get(mid + 1, r, idx << 1 | 1, u, v);
}
void solve() {
cin >> n >> k;
for(int i = 1; i <= n; ++i) {
cin >> a[i];
update(0, n, 1, i, n, a[i]);
}
cin >> q;
while(q--) {
int type; cin >> type;
if(type == 1) {
vi pos(k);
for(int &val : pos) cin >> val;
for(int i = 0; i < k; ++i) {
int diff = a[pos[(i + 1) % k]] - a[pos[i]];
update(0, n, 1, pos[i], n, diff);
}
}
else {
int l, r, m; cin >> l >> r >> m;
cout << get(0, n, 1, l + m - 1, r) - get(0, n, 1, l - 1, r - m) << "\n";
}
}
}
signed main() {
#ifndef CDuongg
if(fopen(taskname".inp", "r"))
assert(freopen(taskname".inp", "r", stdin)), assert(freopen(taskname".out", "w", stdout));
#else
freopen("bai3.inp", "r", stdin);
freopen("bai3.out", "w", stdout);
auto start = chrono::high_resolution_clock::now();
#endif
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1; //cin >> t;
while(t--) solve();
#ifdef CDuongg
auto end = chrono::high_resolution_clock::now();
cout << "\n"; for(int i = 1; i <= 100; ++i) cout << '=';
cout << "\nExecution time: " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl;
#endif
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |