# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1096556 |
2024-10-04T18:14:30 Z |
andrewp |
Addk (eJOI21_addk) |
C++14 |
|
0 ms |
0 KB |
//Dedicated to my love, ivaziva
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define int long long
using pii = pair<int, int>;
using ll = int64_t;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define dbg(x) cerr<<#x<<": "<<x<<'\n';
#define dbga(A,l_,r_){for(int i_=l_;i_<=r_;i_++)cerr<<A[i_]<<' ';cerr<<'\n';}
#define dbgv(a_){for(auto x_:a_) cerr<<x_<<' ';cerr<<'\n';}
const int maxn = 1e5 + 20;
int n, k, a[maxn], ps[maxn][20], psum[maxn];
void precalc() {
for (int i = 1; i <= n; i++) {
ps[i][0] = a[i];
}
for (int j = 1; j < 20; j++) {
for (int i = 1; i <= n - (1ll << j) + 1; i++) {
ps[i][j] = ps[i][j - 1] + ps[i + (1ll << (j - 1))][j - 1] + (psum[i + (1ll << j) - 1] - psum[i + (1ll << (j - 1)) - 1]) * (1ll << (j - 1));
}
}
}
int32_t main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cout.tie(nullptr); cerr.tie(nullptr);
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
psum[i] = psum[i - 1] + a[i];
}
precalc();
int q;
cin >> q;
while (q--) {
int tp;
cin >> tp;
if (tp == 1) {
int x;
cin >> x;
continue;
}
int l, r, m;
cin >> l >> r >> m;
int sum = 0, c = min(r - l + 1 - m + 1, m);
sum += qry(l, l + c - 2);
// for (int i = l; i <= (l + c - 2); i++) {
// sum += a[i] * (i - l + 1);
// }
// for (int i = r; i >= (r - c + 2); i--) {
// sum += a[i] * (r - i + 1);
// }
sum += (psum[r - c + 1] - psum[l + c - 2]) * c;
// for (int i = l + c - 1; i <= r - c + 1; i++) {
// sum += a[i] * c;
// }
cout << sum << '\n';
}
return 0;
}
Compilation message
Main.cpp: In function 'int32_t main()':
Main.cpp:57:16: error: 'qry' was not declared in this scope
57 | sum += qry(l, l + c - 2);
| ^~~