Submission #980055

# Submission time Handle Problem Language Result Execution time Memory
980055 2024-05-11T20:38:27 Z TheFuturoma Addk (eJOI21_addk) C++14
0 / 100
29 ms 2012 KB
#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;
        res += prefix_step[left_part] - prefix[left_part] * left;
        res += suffix_step[n - right_part - 1] - suffix[n - right_part - 1] * (n - right - 1);
        res += (prefix[right_part + 1] - prefix[left_part]) * min(m, left_part - left + 1);
        cout << res << endl;
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 2012 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -