Submission #72717529


Source Code Expand

#include<iostream>
#include<cstring>
#define int long long
constexpr int N=200005;
int rd(){
    int x=0,f=1;char c=getchar();
    for(;!isdigit(c);c=getchar())f=x==45?-1:f;
    for(;isdigit(c);c=getchar())x=x*10+c-48;
    return x*f;
}
using namespace std;
int n,q;
int a[N],sum[N];
signed main(){
    n=rd(),q=rd();
    for(int i=1;i<=n;i++)a[i]=rd(),sum[i]=sum[i-1]+a[i];
    while(q--){
        int op=rd(),x,l,r;
        if(op==1){
            x=rd();
            swap(a[x],a[x+1]);
            sum[x]=sum[x-1]+a[x];
            sum[x+1]=sum[x]+a[x+1];
        }
        if(op==2){
            l=rd(),r=rd();
            cout<<sum[r]-sum[l-1]<<'\n';
        }
    }
    return 0;
}

Submission Info

Submission Time
Task D - Swap and Range Sum
User Sayhere
Language C++23 (GCC 15.2.0)
Score 400
Code Size 716 Byte
Status AC
Exec Time 58 ms
Memory 9224 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 3444 KiB
00_sample_01.txt AC 1 ms 3444 KiB
01_random_00.txt AC 54 ms 8140 KiB
01_random_01.txt AC 58 ms 7948 KiB
01_random_02.txt AC 54 ms 7360 KiB
01_random_03.txt AC 49 ms 6672 KiB
01_random_04.txt AC 46 ms 6644 KiB
01_random_05.txt AC 45 ms 6452 KiB
01_random_06.txt AC 40 ms 6452 KiB
01_random_07.txt AC 37 ms 6572 KiB
01_random_08.txt AC 32 ms 6576 KiB
01_random_09.txt AC 29 ms 6596 KiB
01_random_10.txt AC 24 ms 6468 KiB
01_random_11.txt AC 52 ms 8908 KiB
01_random_12.txt AC 54 ms 8344 KiB
01_random_13.txt AC 50 ms 7912 KiB
01_random_14.txt AC 46 ms 7120 KiB
01_random_15.txt AC 45 ms 6632 KiB
01_random_16.txt AC 41 ms 6596 KiB
01_random_17.txt AC 38 ms 6856 KiB
01_random_18.txt AC 34 ms 6620 KiB
01_random_19.txt AC 32 ms 6828 KiB
01_random_20.txt AC 28 ms 6648 KiB
01_random_21.txt AC 25 ms 6580 KiB
01_random_22.txt AC 39 ms 6704 KiB
01_random_23.txt AC 40 ms 6704 KiB
02_handmade_00.txt AC 2 ms 3524 KiB
02_handmade_01.txt AC 1 ms 3568 KiB
02_handmade_02.txt AC 45 ms 9224 KiB