Submission #70973089


Source Code Expand

#include <bits/stdc++.h>
#define int long long
using namespace std;

const int N = 5e5+5;

int ft1[N], ftv[N];

int lsb(int x) {
    return x&(-x);
}

void add(int p, int v, int* ft) {
    ++p;
    while (p < N) {
        ft[p] += v;
        p += lsb(p);
    }
}

int rsq(int p, int* ft) {
    ++p;
    int v = 0;
    while (p) {
        v += ft[p];
        p -= lsb(p);
    }
    return v;
}

int rsq(int l, int r, int* ft) {
    return rsq(r, ft)-rsq(l-1, ft);
}

int a[N];

signed main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ///
    int n, q;
    cin >> n >> q;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        add(a[i], 1, ft1);
        add(a[i], a[i], ftv);
    }
    while (q--) {
        int cc, aa, bb;
        cin >> cc >> aa >> bb;
        if (cc == 1) {
            add(a[aa], -1, ft1);
            add(a[aa], -a[aa], ftv);
            a[aa] = bb;
            add(a[aa], 1, ft1);
            add(a[aa], a[aa], ftv);
        }
        if (cc == 2) {
            int l = aa;
            int r = bb;
            if (l >= r) {
                cout << n*l << '\n';
                continue;
            }
            int s1 = rsq(l-1, ft1)*l;
            int s2 = (n-rsq(r, ft1))*r;
            int s3 = rsq(l, r, ftv);
            cout << s1+s2+s3 << '\n';
        }
    }
}

Submission Info

Submission Time
Task E - Clamp
User PabloNo
Language C++23 (GCC 15.2.0)
Score 450
Code Size 1392 Byte
Status AC
Exec Time 96 ms
Memory 15500 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 450 / 450
Status
AC × 2
AC × 21
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 02_handmade_00.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 2 ms 3660 KiB
00_sample_01.txt AC 1 ms 3752 KiB
01_random_00.txt AC 43 ms 14064 KiB
01_random_01.txt AC 61 ms 15296 KiB
01_random_02.txt AC 58 ms 13692 KiB
01_random_03.txt AC 31 ms 12144 KiB
01_random_04.txt AC 75 ms 15424 KiB
01_random_05.txt AC 64 ms 15200 KiB
01_random_06.txt AC 94 ms 15500 KiB
01_random_07.txt AC 94 ms 15248 KiB
01_random_08.txt AC 86 ms 15244 KiB
01_random_09.txt AC 90 ms 15320 KiB
01_random_10.txt AC 93 ms 15236 KiB
01_random_11.txt AC 94 ms 15320 KiB
01_random_12.txt AC 96 ms 15384 KiB
01_random_13.txt AC 96 ms 15124 KiB
01_random_14.txt AC 91 ms 15300 KiB
01_random_15.txt AC 80 ms 15344 KiB
01_random_16.txt AC 1 ms 3560 KiB
01_random_17.txt AC 36 ms 11436 KiB
02_handmade_00.txt AC 43 ms 7544 KiB