# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
583747 |
2022-06-26T07:26:59 Z |
Ivkosqn |
Addk (eJOI21_addk) |
C++14 |
|
38 ms |
3020 KB |
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
const int maxn = 1e5 + 1;
unsigned long long n, k, a[maxn], p[maxn], pref[maxn];
long long t[4 * maxn];
void make_tree(int i, int l, int r){
if(l == r){
t[i] = a[r];
return;
}
int mid = (l + r) / 2;
make_tree(2 * i, l, mid);
make_tree(2 * i + 1, mid + 1, r);
t[i] = t[2 * i] + t[2 * i + 1];
}
long long query(int i, int l, int r, int ql, int qr){
if(l == ql && r == qr){
return t[i];
}
int mid = (l + r) / 2;
if(qr <= mid) return query(2 * i, l, mid, ql ,qr);
if(ql > mid) return query(2 * i + 1, mid + 1, r, ql, qr);
return query(2 * i, l, mid, ql, mid) + query(2 * i + 1, mid + 1, r, mid + 1, qr);
}
void solve(){
int q;
cin >> q;
while(q--){
int type;
cin >> type;
if(type == 1){
for(int i = 0;i < k;i++){
int a;
cin >> a;
}
continue;
}
int l, r, m;
cin >> l >> r >> m;
long long ans = 0;
ans = pref[r] - pref[l + m - 2];
ans = ans - (pref[r - m] - pref[l - 1]);
cout << ans << endl;
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
for(int i = 1;i <= n;i++){
cin >> a[i];
p[i] = p[i - 1] + a[i];
}
for(int i = 1;i <= n;i++){
pref[i] = pref[i - 1] + p[i];
}
make_tree(1, 1, n);
solve();
return 0;
}
Compilation message
Main.cpp: In function 'void solve()':
Main.cpp:38:29: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
38 | for(int i = 0;i < k;i++){
| ~~^~~
Main.cpp: In function 'int main()':
Main.cpp:57:21: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
57 | for(int i = 1;i <= n;i++){
| ~~^~~~
Main.cpp:61:21: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
61 | for(int i = 1;i <= n;i++){
| ~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
1620 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
38 ms |
3020 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |