Submission #72714717


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define N (int)2e5 + 10

int tree[N];
inline int lowbit(int x)
{
    return x & (-x);
}
void add(int x, int delta)
{
    for (int i = x; i < N; i += lowbit(i))
    {
        tree[i] += delta;
    }
}
long long query(int x)
{
    long long sum = 0;
    for (int i = x; i > 0; i -= lowbit(i))
    {
        sum += tree[i];
    }
    return sum;
}
int main()
{
    int n, q;
    cin >> n >> q;
    vector<int> num(n + 1, 0);
    for (int i = 1; i <= n; i++)
    {
        int ai;
        cin >> ai;
        num[i] = ai;
        add(i, ai);
    }

    for (int i = 0; i < q; i++)
    {
        int op;
        cin >> op;
        if (op == 1)
        {
            int x;
            cin >> x;
            add(x, num[x + 1] - num[x]);
            add(x + 1, num[x] - num[x + 1]);
            int temp = num[x];
            num[x] = num[x + 1];
            num[x + 1] = temp;
        }
        else
        {
            int l, r;
            cin >> l >> r;
            cout << query(r) - query(l - 1) << '\n';
        }
    }
    return 0;
}

Submission Info

Submission Time
Task D - Swap and Range Sum
User RageLog
Language C++23 (GCC 15.2.0)
Score 400
Code Size 1142 Byte
Status AC
Exec Time 463 ms
Memory 7600 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 3764 KiB
00_sample_01.txt AC 1 ms 3636 KiB
01_random_00.txt AC 463 ms 6564 KiB
01_random_01.txt AC 451 ms 6376 KiB
01_random_02.txt AC 418 ms 5784 KiB
01_random_03.txt AC 367 ms 5272 KiB
01_random_04.txt AC 354 ms 4820 KiB
01_random_05.txt AC 321 ms 4756 KiB
01_random_06.txt AC 287 ms 4900 KiB
01_random_07.txt AC 273 ms 4864 KiB
01_random_08.txt AC 238 ms 4864 KiB
01_random_09.txt AC 207 ms 4824 KiB
01_random_10.txt AC 168 ms 4824 KiB
01_random_11.txt AC 454 ms 7380 KiB
01_random_12.txt AC 429 ms 6860 KiB
01_random_13.txt AC 404 ms 6324 KiB
01_random_14.txt AC 377 ms 5588 KiB
01_random_15.txt AC 352 ms 5312 KiB
01_random_16.txt AC 322 ms 4816 KiB
01_random_17.txt AC 293 ms 4824 KiB
01_random_18.txt AC 266 ms 4808 KiB
01_random_19.txt AC 238 ms 4688 KiB
01_random_20.txt AC 208 ms 4760 KiB
01_random_21.txt AC 180 ms 4820 KiB
01_random_22.txt AC 320 ms 4804 KiB
01_random_23.txt AC 323 ms 4772 KiB
02_handmade_00.txt AC 2 ms 3416 KiB
02_handmade_01.txt AC 1 ms 3696 KiB
02_handmade_02.txt AC 432 ms 7600 KiB