# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
632475 |
2022-08-20T07:11:03 Z |
pragmatist |
Addk (eJOI21_addk) |
C++17 |
|
171 ms |
4936 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
#define int long long
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;
}
signed 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(1ll * 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 |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
3 ms |
468 KB |
Output is correct |
6 |
Correct |
3 ms |
468 KB |
Output is correct |
7 |
Correct |
4 ms |
596 KB |
Output is correct |
8 |
Correct |
5 ms |
596 KB |
Output is correct |
9 |
Correct |
8 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
1188 KB |
Output is correct |
2 |
Correct |
32 ms |
1620 KB |
Output is correct |
3 |
Correct |
46 ms |
2160 KB |
Output is correct |
4 |
Correct |
94 ms |
3508 KB |
Output is correct |
5 |
Correct |
132 ms |
4936 KB |
Output is correct |
6 |
Correct |
138 ms |
4812 KB |
Output is correct |
7 |
Correct |
132 ms |
4788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
171 ms |
2360 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |