Submission #825577

#TimeUsernameProblemLanguageResultExecution timeMemory
825577andecaandeciAddk (eJOI21_addk)C++17
0 / 100
2079 ms2780 KiB
#include<bits/stdc++.h> using namespace std; #define ioss ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define int long long #define tup tuple<int, int, int> #define pii pair<int, int> #define fi first #define se second #define pub push_back #define pob pop_back int n, k, q; int arr[100004]; vector<int> segtr; void build(int i, int l, int r) { if(l == r) { segtr[i] = arr[l]; return; } int mid = (l+r)/2; build(i*2, l, mid); build(i*2+1, mid+1, r); segtr[i] = segtr[i*2] + segtr[i*2+1]; } void update(int i, int l, int r, int idx, int val) { if(l == r) { segtr[i] = val; return; } int mid = (l+r)/2; if(idx <= mid) update(i*2, l, mid, idx, val); else update(i*2+1, mid+1, r, idx, val); segtr[i] = segtr[i*2] + segtr[i*2+1]; } int query(int i, int l, int r, int ql, int qr) { if(ql <= l && qr >= r) return segtr[i]; if(ql > r || qr < l) return 0; int mid = (l+r)/2; return query(i*2, l, mid, ql, qr) + query(i*2+1, mid+1, r, ql, qr); } signed main() { ioss; cin >> n >> k; segtr.assign(4*n, 0); for(int i = 1; i <= n; i++) cin >> arr[i]; build(1, 1, n); cin >> q; for(int i = 0; i < q; i++) { int x; cin >> x; if(x == 1) { vector<int> tmp(k+2); for(int j = 1; j <= k; j++) cin >> tmp[j]; if(k == 1) continue; for(int j = 2; j <= k; j++) swap(arr[tmp[j-1]], arr[tmp[j]]); for(int j = 1; j <= k; j++) update(1, 1, n, tmp[j], arr[tmp[j]]); } else { int l, r, m; cin >> l >> r >> m; int ans = 0; for(int j = l; j <= r-m+1; j++) ans += query(1, 1, n, j, j+m-1); cout << ans << endl; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...