Submission #72703213


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull=unsigned long long;
const int INF = 1e9;
const long long INFLL = (long long)1e18;
const double PI = acos(-1);
//cout << fixed << setprecision(15) << ans << '\n';

int main()
{
  int n,q;cin>>n>>q;
  vector<ll>a(n+1,0),prefix(n+1,0);
  for(int i=1;i<=n;i++)cin>>a[i];
  for(int i=1;i<=n;i++)prefix[i]=prefix[i-1]+a[i];
  for(int i=0;i<q;i++)
  {
    int c;cin>>c;
    if(c==1)
    {
      int x;cin>>x;
      prefix[x]=prefix[x-1]+a[x+1];
      swap(a[x],a[x+1]);
    }
    else if(c==2)
    {
      int l,r;cin>>l>>r;
      cout<<prefix[r]-prefix[l-1]<<endl;
    }
  }
  return 0;
}

Submission Info

Submission Time
Task D - Swap and Range Sum
User maou1
Language C++23 (GCC 15.2.0)
Score 400
Code Size 715 Byte
Status AC
Exec Time 472 ms
Memory 9104 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 3592 KiB
00_sample_01.txt AC 1 ms 3584 KiB
01_random_00.txt AC 472 ms 8184 KiB
01_random_01.txt AC 466 ms 8080 KiB
01_random_02.txt AC 431 ms 7160 KiB
01_random_03.txt AC 385 ms 6704 KiB
01_random_04.txt AC 373 ms 6336 KiB
01_random_05.txt AC 338 ms 6392 KiB
01_random_06.txt AC 307 ms 6316 KiB
01_random_07.txt AC 290 ms 6240 KiB
01_random_08.txt AC 251 ms 6232 KiB
01_random_09.txt AC 218 ms 6408 KiB
01_random_10.txt AC 171 ms 6208 KiB
01_random_11.txt AC 457 ms 8852 KiB
01_random_12.txt AC 435 ms 8344 KiB
01_random_13.txt AC 412 ms 7816 KiB
01_random_14.txt AC 382 ms 7052 KiB
01_random_15.txt AC 362 ms 6796 KiB
01_random_16.txt AC 337 ms 6500 KiB
01_random_17.txt AC 306 ms 6464 KiB
01_random_18.txt AC 280 ms 6476 KiB
01_random_19.txt AC 250 ms 6496 KiB
01_random_20.txt AC 217 ms 6496 KiB
01_random_21.txt AC 183 ms 6488 KiB
01_random_22.txt AC 328 ms 6520 KiB
01_random_23.txt AC 332 ms 6476 KiB
02_handmade_00.txt AC 2 ms 3556 KiB
02_handmade_01.txt AC 1 ms 3584 KiB
02_handmade_02.txt AC 435 ms 9104 KiB