Submission #632473

# Submission time Handle Problem Language Result Execution time Memory
632473 2022-08-20T07:05:31 Z pragmatist Addk (eJOI21_addk) C++17
92 / 100
184 ms 4160 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;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 3 ms 444 KB Output is correct
5 Correct 3 ms 468 KB Output is correct
6 Correct 4 ms 468 KB Output is correct
7 Correct 5 ms 468 KB Output is correct
8 Correct 6 ms 596 KB Output is correct
9 Correct 8 ms 676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 1108 KB Output is correct
2 Correct 39 ms 1456 KB Output is correct
3 Correct 48 ms 1740 KB Output is correct
4 Correct 100 ms 3036 KB Output is correct
5 Correct 148 ms 4160 KB Output is correct
6 Correct 142 ms 4020 KB Output is correct
7 Correct 144 ms 3944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 184 ms 1988 KB Output isn't correct
2 Halted 0 ms 0 KB -