This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cmath>
#include <algorithm>
#include <bitset>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <array>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n, k;
cin>>n>>k;
if (k > 1) {
return 0;
}
vector<ll> arr(n);
vector<ll> prefix(1, 0);
vector<ll> prefix_step(1, 0);
vector<ll> prefix_step_retard(1, 0);
for (int i = 0; i < n; i++) {
cin>>arr[i];
prefix.push_back(prefix.back() + arr[i]);
prefix_step.push_back(prefix_step.back() + arr[i] * (i + 1));
prefix_step_retard.push_back(prefix_step_retard.back() + arr[i] * i);
}
reverse(arr.begin(), arr.end());
vector<ll> suffix(1, 0);
vector<ll> suffix_step(1, 0);
vector<ll> suffix_step_retard(1, 0);
for (int i = 0; i < n; i++) {
suffix.push_back(suffix.back() + arr[i]);
suffix_step.push_back(suffix_step.back() + arr[i] * (i + 1));
suffix_step_retard.push_back(suffix_step_retard.back() + arr[i] * i);
}
// reverse(suffix.begin(), suffix.end());
// reverse(suffix_step.begin(), suffix_step.end());
reverse(arr.begin(), arr.end());
int q;
cin>>q;
for (int test = 0; test < q; test++) {
int t;
cin>>t;
if (t == 1) {
int curr;
cin>>curr;
continue;
}
int left, right, m;
cin>>left>>right>>m;
left--;
right--;
if (m == right - left + 1 || m == 1) {
cout << prefix[right + 1] - prefix[left] << endl;
continue;
}
int left_part = min(left + m, right - m + 1);
int right_part = max(right - m, left + m - 1);
ll res = 0;
// cout << left_part << " right_prat" << endl;
res += prefix_step[left_part] - prefix_step[left] - prefix[left_part] * (left) + prefix[left] * (left);
// cout << res << " sres" << endl;
res += suffix_step[n - right_part - 1] - suffix_step[n - right - 1] - suffix[n - right_part - 1] * (n - right - 1) + suffix[n - right - 1] * (n - right - 1);
// cout << res << " srt" << endl;
// cout << suffix_step[n - right_part - 1] << endl;
res += (prefix[right_part + 1] - prefix[left_part]) * min(m, left_part - left + 1);
cout << res << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |