Submission #829465

#TimeUsernameProblemLanguageResultExecution timeMemory
829465vuavisaoAddk (eJOI21_addk)C++17
0 / 100
68 ms6176 KiB
#include<bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #define ll long long using namespace std; const ll N = 1e5 + 10; struct SegTree { struct Node { ll val[2] = {0, 0}; Node() {}; Node operator + (const Node& other) const { Node res; res.val[0] = this -> val[0] + other.val[0]; res.val[1] = this -> val[1] + other.val[1]; return res; } }; ll n_node = 0; vector<Node> tree = {}; void resize(ll _n) { n_node = _n; tree.resize((n_node << 2) + 10); }; SegTree() {}; SegTree(ll _n) { this -> resize(_n); }; void update(ll node, ll l, ll r, ll idx, ll val) { if(l == r) { tree[node].val[0] = val; tree[node].val[1] = val * idx; return; } ll mid = (l + r) >> 1; if(idx <= mid) update(node << 1, l, mid, idx, val); else update(node << 1 | 1, mid + 1, r, idx, val); tree[node] = tree[node << 1] + tree[node << 1 | 1]; } void Update(ll idx, ll val) { return update(1, 1, n_node, idx, val); } Node query(ll node, ll l, ll r, ll L, ll R) { if(l > r || L > R || l > R || L > r) return Node(); if(L <= l && r <= R) return tree[node]; ll mid = (l + r) >> 1; return query(node << 1, l, mid, L, R) + query(node << 1 | 1, mid + 1, r, L, R); } Node Query(ll l, ll r) { return query(1, 1, n_node, l, r); } }; ll n, q, k; ll a[N]; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> n >> k; for(ll i = 1; i <= n; ++ i) cin >> a[i]; cin >> q; SegTree st(n); for(ll i = 1; i <= n; ++ i) st.Update(i, a[i]); while(q-- > 0) { ll type; cin >> type; if(type == 1) { ll List[12], val_in_list[12]; for(ll i = 1; i <= k; ++ i) cin >> List[i], val_in_list[i] = a[List[i]]; for(ll i = 1; i <= k; ++ i) { ll j = i + 1; if(j > k) j -= k; a[List[i]] = val_in_list[j]; st.Update(List[i], a[List[i]]); } } else { ll l, r, m; cin >> l >> r >> m; ll le[2], ri[2], have[2] = {l - 1, r + 1}; le[0] = l, ri[0] = min(l + m - 1, r - m + 1); le[1] = max(ri[0] + 1, r - m + 1), ri[1] = r; ll res = 0; for(ll i = 0, sign = 1; i < 2; sign = - sign, ++ i) { if(le[i] > ri[i]) continue; // cout << le[i] << ' ' << ri[i] << '\n'; const auto& tmp = st.Query(le[i], ri[i]); // cout << tmp.val[1] << ' ' << tmp.val[0] << '\n'; // cout << tmp.val[1] * sign - sign * have[i] * tmp.val[0] << '\n'; res += tmp.val[1] * sign - sign * have[i] * tmp.val[0]; } if(ri[0] + 1 <= le[1] - 1) { res += st.Query(ri[0] + 1, le[1] - 1).val[0] * m; } cout << res << '\n'; } } return (0 ^ 0); } /// Code by vuavisao
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...