Submission #958793

#TimeUsernameProblemLanguageResultExecution timeMemory
958793AcanikolicAddk (eJOI21_addk)C++14
92 / 100
640 ms7424 KiB
#include <bits/stdc++.h>
			 				 
#define pb push_back 
			
#define F first
		 
#define S second
			 
#define int long long 			 
			 
using namespace std;
			 
const int N = 1e5 + 10;
			 
const int mod = 998244353;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

	int n,k;
	cin >> n >> k;
	vector<int>a(n + 1);
	for(int i = 1; i <= n; i++) cin >> a[i];
	vector<int>pref(n + 1),Pref(n + 1);
	for(int i = 1; i <= n; i++) pref[i] = pref[i - 1] + a[i];
	for(int i = 1; i <= n; i++) Pref[i] = Pref[i - 1] + pref[i];
	int q;
	cin >> q;
	while(q--) {
		int type;
		cin >> type;
		if(type == 1) {
			vector<int>b(k + 1),c(k + 1);
			for(int i = 1; i <= k; i++) cin >> b[i];
			for(int i = 1; i <= k - 1; i++) c[i] = b[i + 1];
			c[k] = b[1];
			vector<int>cpy = a;
			for(int i = 1; i <= k; i++) cpy[b[i]] = a[c[i]];
			a = cpy;
		}else {
			int l,r,m,res = 0;
			cin >> l >> r >> m;
			int L = l + m - 1;
			if(L <= r) res += Pref[r] - Pref[L - 1];
			int R = r - m + 1;
			if(R >= l) res -= Pref[R - 1];
			if(R >= l && l >= 2) res += Pref[l - 2];
			cout << res << "\n"; 
		}
	}
   	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...