Submission #72725753


Source Code Expand

#include <iostream>
#define int long long
#define lowbit(x) ((x) & -x)
using namespace std;
int n, q;
int tr[200005];
void add(int p, int val)
{
    for (; p <= n; p += lowbit(p))
        tr[p] += val;
}
int query(int p)
{
    int res = 0;
    for (; p; p -= lowbit(p))
        res += tr[p];
    return res;
}
void solve()
{
    int opt;
    cin >> opt;
    if (opt == 1)
    {
        int x;
        cin >> x;
        int t1 = query(x) - query(x - 1), t2 = query(x + 1) - query(x);
        add(x, t2 - t1);
        add(x + 1, t1 - t2);
    }
    else
    {
        int l, r;
        cin >> l >> r;
        cout << query(r) - query(l - 1) << '\n';
    }
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n >> q;
    for (int i = 1; i <= n; i++)
    {
        int x;
        cin >> x;
        add(i, x);
    }
    while (q--)
        solve();
}

Submission Info

Submission Time
Task D - Swap and Range Sum
User Hygrox
Language C++23 (GCC 15.2.0)
Score 400
Code Size 934 Byte
Status AC
Exec Time 85 ms
Memory 7580 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 29
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, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 02_handmade_00.txt, 02_handmade_01.txt, 02_handmade_02.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3448 KiB
00_sample_01.txt AC 1 ms 3620 KiB
01_random_00.txt AC 83 ms 6656 KiB
01_random_01.txt AC 85 ms 6468 KiB
01_random_02.txt AC 81 ms 5688 KiB
01_random_03.txt AC 75 ms 5188 KiB
01_random_04.txt AC 77 ms 5084 KiB
01_random_05.txt AC 72 ms 5096 KiB
01_random_06.txt AC 69 ms 4988 KiB
01_random_07.txt AC 70 ms 4996 KiB
01_random_08.txt AC 65 ms 5128 KiB
01_random_09.txt AC 63 ms 4996 KiB
01_random_10.txt AC 56 ms 4984 KiB
01_random_11.txt AC 81 ms 7484 KiB
01_random_12.txt AC 80 ms 6940 KiB
01_random_13.txt AC 78 ms 6344 KiB
01_random_14.txt AC 77 ms 5528 KiB
01_random_15.txt AC 75 ms 5256 KiB
01_random_16.txt AC 73 ms 5112 KiB
01_random_17.txt AC 70 ms 5184 KiB
01_random_18.txt AC 69 ms 5224 KiB
01_random_19.txt AC 66 ms 5224 KiB
01_random_20.txt AC 63 ms 5124 KiB
01_random_21.txt AC 59 ms 5024 KiB
01_random_22.txt AC 70 ms 5220 KiB
01_random_23.txt AC 71 ms 5184 KiB
02_handmade_00.txt AC 2 ms 3592 KiB
02_handmade_01.txt AC 1 ms 3460 KiB
02_handmade_02.txt AC 67 ms 7580 KiB