#include<bits/stdc++.h>
#include<fstream>
using namespace std;
ifstream fin("VNOICUP.INP");
ofstream fout("VNOICUP.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ld PI = 3.14159265359;
using u128 = __uint128_t;
const int mxn = 1e5 + 5;
int n, k;
struct BIT{
ll bit[mxn + 1];
void upd(int p, ll v){
while(p <= n){
bit[p] += v; p += p & (-p);
}
}
ll get(int p){
ll ans = 0;
while(p){
ans += bit[p]; p -= p & (-p);
}
return(ans);
}
ll query(int l, int r){
if(l > r)return(0);
return(get(r) - get(l - 1));
}
};
BIT bit, bit2;
ll a[mxn + 1];
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> k;
for(int i = 1; i <= n; i++){
cin >> a[i]; bit.upd(i, a[i]); bit2.upd(i, a[i] * i);
}
int q; cin >> q;
for(int i = 1; i <= q; i++){
int idq; cin >> idq;
if(idq == 1){
for(int j = 0; j < k; j++){
int x; cin >> x;
}
}else{
int l, r, m; cin >> l >> r >> m;
ll ans = 0;
/*
for(int j = l; j <= r; j++){
int low = max(j - m + 1, l), high = min(r - m + 1, j);
ans += 1LL * (high - low + 1) * a[j];
}
cout << ans << "\n";
*/
ll low = bit.query(l, l + m - 1) * l + bit2.query(l + m, r) - bit.query(l + m, r) * m + bit.query(l + m, r);
ll high = bit.query(r - m + 1, r) * (r - m + 1) + bit2.query(l, r - m);
//cout << high << " " << low << " " << "\n";
cout << high - low + bit.query(l, r) << "\n";
}
}
return(0);
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:59:16: warning: unused variable 'ans' [-Wunused-variable]
59 | ll ans = 0;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
4 ms |
468 KB |
Output is correct |
6 |
Correct |
3 ms |
468 KB |
Output is correct |
7 |
Correct |
5 ms |
524 KB |
Output is correct |
8 |
Correct |
5 ms |
596 KB |
Output is correct |
9 |
Correct |
5 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
980 KB |
Output is correct |
2 |
Correct |
15 ms |
1376 KB |
Output is correct |
3 |
Correct |
26 ms |
1784 KB |
Output is correct |
4 |
Correct |
36 ms |
3404 KB |
Output is correct |
5 |
Correct |
64 ms |
6596 KB |
Output is correct |
6 |
Correct |
47 ms |
6352 KB |
Output is correct |
7 |
Correct |
47 ms |
6340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
32 ms |
1988 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |