This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// author : anhtun_hi , nqg
#include <bits/stdc++.h>
#define ll long long
#define ii pair<ll, ll>
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define reset(h, v) memset(h, v, sizeof h)
#define Forv(i, a) for(auto& i : a)
#define For(i, a, b) for(int i = a; i <= b; ++i)
#define Ford(i, a, b) for(int i = a; i >= b; --i)
#define c_bit(i) __builtin_popcountll(i)
#define Bit(mask, i) ((mask >> i) & 1LL)
#define onbit(mask, i) ((mask) bitor (1LL << i))
#define offbit(mask, i) ((mask) &~ (1LL << i))
using namespace std;
namespace std {
template <typename T, int D>
struct _vector : public vector <_vector <T, D - 1>> {
static_assert(D >= 1, "Dimension must be positive!");
template <typename... Args>
_vector(int n = 0, Args... args) : vector <_vector <T, D - 1>> (n, _vector <T, D - 1> (args...)) {}
};
template <typename T> struct _vector <T, 1> : public vector <T> {
_vector(int n = 0, const T& val = T()) : vector <T> (n, val) {}
};
template <class A, class B> bool minimize(A &a, B b){return a > b ? a = b, true : false;}
template <class A, class B> bool maximize(A &a, B b){return a < b ? a = b, true : false;}
}
const int dx[] = {0, 0, +1, -1}, dy[] = {-1, +1, 0, 0}, LOG = 20, base = 311, inf = 1e9 + 5;
const int MAXN = 1e6 + 5;
const ll mod = 1e9 + 7;
const ll oo = 1e18;
//#define int long long
int n, q, k; ll a[MAXN], f[MAXN], st[MAXN << 2], lazy[MAXN << 2];
void down(int id, int l, int r)
{
if (!lazy[id] || l == r) return;
int mid = l + r >> 1; auto &val = lazy[id];
st[id << 1] += (mid - l + 1) * val, lazy[id << 1] += val;
st[id << 1 | 1] += (r - mid) * val, lazy[id << 1 | 1] += val;
val = 0;
}
void update(int id, int l, int r, int u, int v, ll val)
{
if (v < l || r < u) return;
down(id, l, r);
if (u <= l && r <= v){
down(id, l, r);
st[id] += val * (r - l + 1);
lazy[id] += val;
return;
}
int mid = l + r >> 1;
update(id << 1, l, mid, u, v, val);
update(id << 1 | 1, mid + 1, r, u, v, val);
st[id] = st[id << 1] + st[id << 1 | 1];
}
ll get(int id, int l, int r, int u, int v)
{
if (v < l || r < u) return 0LL;
down(id, l, r);
if (u <= l && r <= v) return st[id];
int mid = l + r >> 1;
return get(id << 1, l, mid, u, v) + get(id << 1 | 1, mid + 1, r, u, v);
}
void Solve() {
cin >> n >> k;
For(i, 1, n) cin >> a[i], f[i] = f[i - 1] + a[i], update(1, 1, n, i, i, f[i]);
cin >> q;
while (q--){
int op; cin >> op;
if(op & 1){
vector<ii> List(k);
Forv(x, List) {cin >> x.fi; x.se = a[x.fi];}
int pre = List[0].fi;
For(i, 0, List.size() - 1){
int nxt = i + 1;
if (nxt >= List.size()) nxt = 0;
update(1, 1, n, List[i].fi, n, -a[List[i].fi] + a[List[nxt].fi]);
}
For(i, 0, List.size() - 1){
int nxt = i + 1;
if (nxt >= List.size()) nxt = 0;
a[List[i].fi] = List[nxt].se;
}
} else {
int l, r, m; cin >> l >> r >> m;
cout << get(1, 1, n, l + m - 1, r) - get(1, 1, n, l - 1, r - m) << '\n';
}
}
}
int32_t main() {
cin.tie(0) -> sync_with_stdio(0);
if(fopen("eJOI21_addk.inp", "r")) {
freopen("eJOI21_addk.inp", "r", stdin);
freopen("eJOI21_addk.out", "w", stdout);
}
int t = 1;
// cin >> t;
for (int test = 1; test <= t; test++) {
Solve();
}
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'void down(int, int, int)':
Main.cpp:42:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
42 | int mid = l + r >> 1; auto &val = lazy[id];
| ~~^~~
Main.cpp: In function 'void update(int, int, int, int, int, long long int)':
Main.cpp:58:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
58 | int mid = l + r >> 1;
| ~~^~~
Main.cpp: In function 'long long int get(int, int, int, int, int)':
Main.cpp:69:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
69 | int mid = l + r >> 1;
| ~~^~~
Main.cpp: In function 'void Solve()':
Main.cpp:10:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
10 | #define For(i, a, b) for(int i = a; i <= b; ++i)
......
83 | For(i, 0, List.size() - 1){
| ~~~~~~~~~~~~~~~~~~~~~
Main.cpp:83:13: note: in expansion of macro 'For'
83 | For(i, 0, List.size() - 1){
| ^~~
Main.cpp:85:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | if (nxt >= List.size()) nxt = 0;
| ~~~~^~~~~~~~~~~~~~
Main.cpp:10:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
10 | #define For(i, a, b) for(int i = a; i <= b; ++i)
......
88 | For(i, 0, List.size() - 1){
| ~~~~~~~~~~~~~~~~~~~~~
Main.cpp:88:13: note: in expansion of macro 'For'
88 | For(i, 0, List.size() - 1){
| ^~~
Main.cpp:90:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
90 | if (nxt >= List.size()) nxt = 0;
| ~~~~^~~~~~~~~~~~~~
Main.cpp:82:17: warning: unused variable 'pre' [-Wunused-variable]
82 | int pre = List[0].fi;
| ^~~
Main.cpp: In function 'int32_t main()':
Main.cpp:103:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
103 | freopen("eJOI21_addk.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:104:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
104 | freopen("eJOI21_addk.out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |