Submission #72693355


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n, q;
    cin >> n >> q;
    vector<int> a(n), sum(n+1);
    sum[0] = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        sum[i+1] = sum[i] + a[i];
    }
    
    for(int i = 0; i < q; i++){
        int t;
        cin >> t;
        
        if(t == 1){
            int x;
            cin >> x;
            x--;
            
            sum[x+1] += a[x+1] - a[x];
            swap(a[x], a[x+1]);
        }
        else if(t == 2){
            int l, r;
            cin >> l >> r;
            
            cout << sum[r] - sum[l-1] << endl;
        }
    }
}

Submission Info

Submission Time
Task D - Swap and Range Sum
User mrkm1627
Language C++23 (GCC 15.2.0)
Score 400
Code Size 671 Byte
Status AC
Exec Time 387 ms
Memory 7540 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 3552 KiB
00_sample_01.txt AC 1 ms 3584 KiB
01_random_00.txt AC 387 ms 6708 KiB
01_random_01.txt AC 378 ms 6504 KiB
01_random_02.txt AC 344 ms 5660 KiB
01_random_03.txt AC 305 ms 5180 KiB
01_random_04.txt AC 292 ms 4936 KiB
01_random_05.txt AC 263 ms 4792 KiB
01_random_06.txt AC 234 ms 4784 KiB
01_random_07.txt AC 221 ms 4668 KiB
01_random_08.txt AC 192 ms 4732 KiB
01_random_09.txt AC 166 ms 4732 KiB
01_random_10.txt AC 133 ms 4852 KiB
01_random_11.txt AC 383 ms 7296 KiB
01_random_12.txt AC 362 ms 6776 KiB
01_random_13.txt AC 339 ms 6260 KiB
01_random_14.txt AC 311 ms 5500 KiB
01_random_15.txt AC 292 ms 5244 KiB
01_random_16.txt AC 268 ms 4904 KiB
01_random_17.txt AC 240 ms 4792 KiB
01_random_18.txt AC 217 ms 4904 KiB
01_random_19.txt AC 192 ms 4928 KiB
01_random_20.txt AC 167 ms 4916 KiB
01_random_21.txt AC 142 ms 4804 KiB
01_random_22.txt AC 263 ms 4796 KiB
01_random_23.txt AC 267 ms 4936 KiB
02_handmade_00.txt AC 1 ms 3404 KiB
02_handmade_01.txt AC 1 ms 3552 KiB
02_handmade_02.txt AC 371 ms 7540 KiB