#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lld double
#define int ll
#define usaco(fname) freopen(#fname ".in","r",stdin);freopen(#fname ".out","w",stdout);
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
// const ll INF = 1e18;
const int INF = 1e9;
const int mod = 1e9+7;
const lld PI = acos(-1.0);
int di[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dj[] = {0, 0, 1, -1, 1, -1, 1, -1};
#define debug(x) cout << #x << ": " << x << endl;
#define add(a, b) a += b, a %= mod
#define mul(a, b) ((a % mod) * (b % mod)) % mod
#define all(x) x.begin(),x.end()
void solve() {
int n,k;cin>>n>>k;
vector<int> a(n), pref1(n), pref2(n), suff2(n);
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) {
pref1[i] = a[i];
pref2[i] = (i+1)*a[i];
if (i > 0) pref1[i] += pref1[i-1], pref2[i] += pref2[i-1];
}
for (int i = n-1; i >= 0; i--) {
suff2[i] = (n-1-i+1)*a[i];
if (i+1 < n)suff2[i] += suff2[i+1];
}
function<int(int, int)> sum = [&](int l, int r) {
return pref1[r] - (l-1 >= 0 ? pref1[l-1] : 0);
};
function<int(int,int)> sum_mul = [&](int l, int r) {
return pref2[r] - (l-1 >= 0 ? pref2[l-1] : 0);
};
function<int(int, int)> suff_mul = [&](int l, int r) {
return suff2[l] - (r+1 < n ? suff2[r+1] : 0);
};
function<int(int, int)> rnge = [&](int l, int r) {
return sum_mul(l, r) - l * sum(l, r);
};
function<int(int, int)> rngesuff = [&](int l, int r) {
return suff_mul(l, r) - (n-1-r) * sum(l, r);
};
int q;cin>>q;
while (q--) {
int t;cin>>t;
if (t == 1) {
int x,y,z;cin>>x>>y>>z;
continue;
} else {
int l,r,m;cin>>l>>r>>m;l--;r--;
int len = (r-l+1);
int x = min(len-m+1, m);
cout << rnge(l, l+x-1) + (r-(l+x) >= (l+x) ? x*sum(l+x, r - x + 1) : 0ll) + rngesuff(r-x+1, r) << endl;
}
}
}
int32_t main() {
ios_base::sync_with_stdio(0);cin.tie(0);
int t=1;
while(t--) solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
25 ms |
2140 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
58 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |