Submission #1025177

#TimeUsernameProblemLanguageResultExecution timeMemory
1025177coolboy19521Addk (eJOI21_addk)C++17
92 / 100
41 ms8276 KiB
#include "bits/stdc++.h" #define int long long using namespace std; const int sz = 1e5 + 5; int pf[sz], sf[sz]; int pj[sz], sj[sz]; int a[sz]; int an; void solve() { int t; cin >> t; if (1 == t) { int b; cin >> b; return; } int l, r, m; cin >> l >> r >> m; int n = r - l + 1; int mxv = n - m + 1; int le = l + mxv - 2; int rs = r - mxv + 2; int pjl = pj[le] - pj[l - 1]; int pfl = pf[le] - pf[l - 1]; int fpl = pjl - pfl * (l - 1); int sjr = sj[rs] - sj[r + 1]; int sfr = sf[rs] - sf[r + 1]; int fsr = sjr - sfr * (an - r); int rsms = l + mxv - 1; int rsme = r - mxv + 1; int rsm = pf[rsme] - pf[rsms - 1]; int tsm = fpl + fsr + rsm * mxv; cout << tsm << '\n'; } signed main() { cin.tie(nullptr)->sync_with_stdio(false); int n, k; cin >> n >> k; an = n; for (int i = 1; i <= n; i ++) cin >> a[i]; for (int i = 1; i <= n; i ++) { pf[i] = pf[i - 1] + a[i]; pj[i] = pj[i - 1] + i * a[i]; } for (int i = 1; i <= n; i ++) { int rx = n - i + 1; sf[rx] = sf[rx + 1] + a[rx]; sj[rx] = sj[rx + 1] + i * a[rx]; } int q; cin >> q; while (q --) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...