답안 #632472

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
632472 2022-08-20T07:05:13 Z pragmatist Addk (eJOI21_addk) C++17
36 / 100
2000 ms 4248 KB
#include<bits/stdc++.h>
 
#define ll long long
#define nl "\n"
#define sz(v) (int)v.size()
#define pb push_back
#define x first
#define y second
 
using namespace std;
using pii = pair<int, int>; 

const int N = (int)1e5 + 7;
 
int n, k, q, b[N], a[N];

ll p[N], z[N];
vector<pii> c; 

void build() {
	for(int i = 1; i <= n; ++i) {
	    a[i] = b[i];
		p[i] = p[i - 1] + a[i];
		z[i] = z[i - 1] + p[i];
	}
}

ll get(int l) {
	ll ans = z[l];
	for(auto [i, x] : c) {
		if(i > l) continue;
		int ch = l - i + 1;
		ans -= 1ll * ch * a[i];
		ans += 1ll * ch * x;
	}
	return ans;
}

int main() {
	ios_base::sync_with_stdio(NULL);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> k;
	for(int i = 1; i <= n; ++i) {
		cin >> a[i];
		b[i] = a[i];
	}
	build();
	cin >> q;
	while(q--) {
		char tp;
		cin >> tp;
		if(tp == '1') {
			vector<int> v(k);
			for(auto &x : v) cin >> x;
			int o = b[v[0]];
			for(int i = 0; i < k - 1; ++i) {
				b[v[i]] = b[v[i + 1]];
				c.pb({v[i], a[v[i + 1]]});
			}
			c.pb({v.back(), o});
			b[v.back()] = o;
			/*
			if(sz(c) * sz(c) >= n) {
				build();
				c.clear();
			}
			*/
		} else {
			int l, r, m;
			cin >> l >> r >> m;
			ll ans = get(r) - get(l + m - 2);
			ans -= get(r - m) - (l - 2 < 0 ? 0 : get(l - 2));
			cout << ans << nl;
		}
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 3 ms 416 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 5 ms 480 KB Output is correct
6 Correct 8 ms 532 KB Output is correct
7 Correct 12 ms 540 KB Output is correct
8 Correct 15 ms 608 KB Output is correct
9 Correct 27 ms 696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 100 ms 1036 KB Output is correct
2 Correct 248 ms 1404 KB Output is correct
3 Correct 411 ms 1872 KB Output is correct
4 Correct 1341 ms 3032 KB Output is correct
5 Correct 1837 ms 4248 KB Output is correct
6 Execution timed out 2088 ms 3684 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2086 ms 2272 KB Time limit exceeded
2 Halted 0 ms 0 KB -