# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
774897 |
2023-07-06T05:10:15 Z |
CDuong |
Addk (eJOI21_addk) |
C++17 |
|
216 ms |
12600 KB |
/*
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,fma,bmi,bmi2,sse4.2,popcnt,lzcnt")
*/
#include <bits/stdc++.h>
#define taskname ""
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define int long long
#define ll long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define isz(x) (int)x.size()
using namespace std;
const int mxN = 1e5 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;
struct node {
int val, lazy;
node() {val = lazy = 0;}
node operator + (const node &o) {
node res;
res.val = val + o.val;
return res;
}
} segtree[4 * mxN];
int n, k, q, a[mxN];
void down(int idx, int l, int r) {
if(segtree[idx].lazy == 0)
return;
int val = segtree[idx].lazy, mid = (l + r) >> 1;
segtree[idx << 1].val += val * (mid - l + 1);
segtree[idx << 1].lazy += val;
segtree[idx << 1 | 1].val += val * (r - mid);
segtree[idx << 1 | 1].lazy += val;
segtree[idx].lazy = 0;
}
void update(int l, int r, int idx, int u, int v, int val) {
if(r < u || v < l) return;
if(u <= l && r <= v) {
segtree[idx].val += (r - l + 1) * val;
segtree[idx].lazy += val;
return;
}
down(idx, l, r);
int mid = (l + r) >> 1;
update(l, mid, idx << 1, u, v, val);
update(mid + 1, r, idx << 1 | 1, u, v, val);
segtree[idx] = segtree[idx << 1] + segtree[idx << 1 | 1];
}
int get(int l, int r, int idx, int u, int v) {
if(r < u || v < l) return 0;
if(u <= l && r <= v)
return segtree[idx].val;
down(idx, l, r);
int mid = (l + r) >> 1;
return get(l, mid, idx << 1, u, v) + get(mid + 1, r, idx << 1 | 1, u, v);
}
void solve() {
cin >> n >> k;
for(int i = 1; i <= n; ++i) {
cin >> a[i];
update(0, n, 1, i, n, a[i]);
}
cin >> q;
while(q--) {
int type; cin >> type;
if(type == 1) {
vi pos(k);
for(int &val : pos) cin >> val;
for(int i = 0; i < k; ++i) {
int diff = a[pos[(i + 1) % k]] - a[pos[i]];
update(0, n, 1, pos[i], n, diff);
}
for(int i = 0; i < k - 1; ++i)
swap(a[pos[i]], a[pos[i + 1]]);
}
else {
int l, r, m; cin >> l >> r >> m;
cout << get(0, n, 1, l + m - 1, r) - get(0, n, 1, l - 1, r - m) << "\n";
}
}
}
signed main() {
#ifndef CDuongg
if(fopen(taskname".inp", "r"))
assert(freopen(taskname".inp", "r", stdin)), assert(freopen(taskname".out", "w", stdout));
#else
freopen("bai3.inp", "r", stdin);
freopen("bai3.out", "w", stdout);
auto start = chrono::high_resolution_clock::now();
#endif
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1; //cin >> t;
while(t--) solve();
#ifdef CDuongg
auto end = chrono::high_resolution_clock::now();
cout << "\n"; for(int i = 1; i <= 100; ++i) cout << '=';
cout << "\nExecution time: " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl;
#endif
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6484 KB |
Output is correct |
2 |
Correct |
3 ms |
6612 KB |
Output is correct |
3 |
Correct |
5 ms |
6624 KB |
Output is correct |
4 |
Correct |
6 ms |
6612 KB |
Output is correct |
5 |
Correct |
6 ms |
6620 KB |
Output is correct |
6 |
Correct |
8 ms |
6612 KB |
Output is correct |
7 |
Correct |
8 ms |
6612 KB |
Output is correct |
8 |
Correct |
9 ms |
6680 KB |
Output is correct |
9 |
Correct |
12 ms |
6740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
6996 KB |
Output is correct |
2 |
Correct |
34 ms |
7116 KB |
Output is correct |
3 |
Correct |
49 ms |
7372 KB |
Output is correct |
4 |
Correct |
78 ms |
8064 KB |
Output is correct |
5 |
Correct |
131 ms |
8780 KB |
Output is correct |
6 |
Correct |
114 ms |
8648 KB |
Output is correct |
7 |
Correct |
116 ms |
8656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
7348 KB |
Output is correct |
2 |
Correct |
119 ms |
10612 KB |
Output is correct |
3 |
Correct |
216 ms |
12600 KB |
Output is correct |
4 |
Correct |
139 ms |
11492 KB |
Output is correct |