Submission #734379

# Submission time Handle Problem Language Result Execution time Memory
734379 2023-05-02T10:48:48 Z borisAngelov Addk (eJOI21_addk) C++17
92 / 100
52 ms 8140 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 100005;

int n, q, k;

long long a[maxn];

long long preffix_sum[maxn];
long long preffix_cyc[maxn];
long long suffix_sum[maxn];
long long suffix_cyc[maxn];

char current_symbol;
int resulting_number;

int read()
{
    resulting_number = 0;

    current_symbol = getchar();

    while (isdigit(current_symbol) == false)
    {
        current_symbol = getchar();
    }

    while (isdigit(current_symbol) == true)
    {
        resulting_number *= 10;
        resulting_number += (current_symbol - '0');
        current_symbol = getchar();
    }

    return resulting_number;
}

long long calc_preffix(int from, int to, long long coeficient)
{
    if (from > to)
    {
        return 0LL;
    }

    return (preffix_sum[to] - preffix_sum[from - 1]) * coeficient;
}

long long calc_suffix(int from, int to, long long coeficient)
{
    if (from > to)
    {
        return 0LL;
    }

    return (suffix_sum[from] - suffix_sum[to + 1]) * coeficient;
}

void fastIO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main()
{
    fastIO();

    //n = read();
    //k = read();

    cin >> n >> k;

    for (int i = 1; i <= n; ++i)
    {
        //a[i] = read();
        cin >> a[i];

        preffix_sum[i] = preffix_sum[i - 1] + a[i];
        preffix_cyc[i] = preffix_cyc[i - 1] + (1LL * i) * a[i];
    }

    for (int i = n; i >= 1; --i)
    {
        suffix_sum[i] = suffix_sum[i + 1] + a[i];
        suffix_cyc[i] = suffix_cyc[i + 1] + (1LL * (n - i + 1)) * a[i];
    }

    //q = read();
    cin >> q;

    for (int i = 1; i <= q; ++i)
    {
        int type;
        cin >> type;

        if (type == 1)
        {
            int x;
            cin >> x;
        }
        else
        {
            int l, r, m;
            cin >> l >> r >> m;

            if (m == r - l + 1)
            {
                cout << calc_preffix(l, r, 1) << "\n";
                continue;
            }

            int from = l + m - 1;
            int to = r - m + 1;

            long long ans = calc_preffix(from, to, m);

            if (from <= to)
            {
                int last_preffix = from - 1;
                long long add_preffix = preffix_cyc[last_preffix] - preffix_cyc[l - 1] - calc_preffix(l, last_preffix, l - 1);

                int last_suffix = to + 1;
                long long add_suffix = suffix_cyc[last_suffix] - suffix_cyc[r + 1] - calc_suffix(last_suffix, r, n - r);

                ans += add_preffix;
                ans += add_suffix;
            }
            else
            {
                int coeficient = r - l + 2 - m;

                from = l + coeficient - 1;
                to = r - coeficient + 1;

                long long add_middle_sum = calc_preffix(from, to, coeficient);

                //cout << "middle test " << add_middle_sum << " [" << from << ", " << to << "] and " << coeficient << endl;

                ans += add_middle_sum;

                int last_preffix = from - 1;
                long long add_preffix = preffix_cyc[last_preffix] - preffix_cyc[l - 1] - calc_preffix(l, last_preffix, l - 1);

                int last_suffix = to + 1;
                long long add_suffix = suffix_cyc[last_suffix] - suffix_cyc[r + 1] - calc_suffix(last_suffix, r, n - r);

                ans += add_preffix;
                ans += add_suffix;
            }

            cout << ans << "\n";
        }
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 5 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 2 ms 556 KB Output is correct
5 Correct 4 ms 596 KB Output is correct
6 Correct 4 ms 612 KB Output is correct
7 Correct 5 ms 724 KB Output is correct
8 Correct 4 ms 852 KB Output is correct
9 Correct 5 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 1360 KB Output is correct
2 Correct 17 ms 2644 KB Output is correct
3 Correct 21 ms 3400 KB Output is correct
4 Correct 41 ms 5792 KB Output is correct
5 Correct 52 ms 8140 KB Output is correct
6 Correct 50 ms 7896 KB Output is correct
7 Correct 47 ms 7876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 2988 KB Output isn't correct
2 Halted 0 ms 0 KB -