# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
850490 |
2023-09-16T17:30:54 Z |
TahirAliyev |
Addk (eJOI21_addk) |
C++17 |
|
153 ms |
6952 KB |
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define oo 1e9
#define pii pair<ll, int>
struct DATA{
ll sum = 0, leftSum = 0, rightSum = 0, s = 0;
};
const int MAX = 1e5 + 5;
int n, k, q;
int arr[MAX];
DATA tree[4 * MAX];
DATA combine(DATA a, DATA b){
DATA c;
c.sum = a.sum + b.sum;
c.leftSum = a.leftSum + b.leftSum + a.s * b.sum;
c.rightSum = b.rightSum + a.rightSum + b.s * a.sum;
c.s = a.s + b.s;
return c;
}
void build(int node, int l, int r){
if(l == r){
tree[node].sum = arr[l];
tree[node].leftSum = arr[l];
tree[node].rightSum = arr[l];
tree[node].s = 1;
return;
}
int mid = (l + r) / 2;
build(2 * node, l, mid);
build(2 * node + 1, mid + 1, r);
tree[node] = combine(tree[2 * node], tree[2 * node + 1]);
}
DATA ask(int node, int l, int r, int ql, int qr){
if(r < ql || qr < l) return DATA();
if(ql <= l && r <= qr){
return tree[node];
}
int mid = (l + r) / 2;
return combine(ask(2 * node, l, mid, ql, qr), ask(2 * node + 1, mid + 1, r, ql ,qr));
}
int findAns(int l, int r){
if(l > r) return 0;
int mid = (l + r) / 2;
return ask(1, 1, n, l, mid).leftSum + ask(1, 1, n, mid + 1, r).rightSum;
}
int main(){
cin >> n >> k;
for(int i = 1; i <= n; i++){
cin >> arr[i];
}
build(1, 1, n);
cin >> q;
while(q--){
int t; cin >> t;
if(t == 2){
int l, r, m; cin >> l >> r >> m;
int s = r - l + 1;
m = min(m, (s + 1) - m);
cout << findAns(l, r) - findAns(l + m, r - m) << '\n';
}
else{
for(int i = 1; i <= k; i++){
int a; cin >> a;
}
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
348 KB |
Output is correct |
3 |
Incorrect |
6 ms |
604 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
65 ms |
3412 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
153 ms |
6952 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |