답안 #958792

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
958792 2024-04-06T16:36:25 Z Acanikolic Addk (eJOI21_addk) C++14
36 / 100
2000 ms 2380 KB
#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];
	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;
			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 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 5 ms 480 KB Output is correct
3 Correct 21 ms 528 KB Output is correct
4 Correct 45 ms 348 KB Output is correct
5 Correct 79 ms 560 KB Output is correct
6 Correct 124 ms 1360 KB Output is correct
7 Correct 176 ms 600 KB Output is correct
8 Correct 239 ms 620 KB Output is correct
9 Correct 628 ms 1448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2039 ms 1236 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2025 ms 2380 KB Time limit exceeded
2 Halted 0 ms 0 KB -