提出 #72726531


ソースコード 拡げる

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

提出情報

提出日時
問題 D - Swap and Range Sum
ユーザ gushiro
言語 C++23 (GCC 15.2.0)
得点 400
コード長 749 Byte
結果 AC
実行時間 398 ms
メモリ 9096 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 2
AC × 29
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3556 KiB
00_sample_01.txt AC 1 ms 3556 KiB
01_random_00.txt AC 398 ms 8188 KiB
01_random_01.txt AC 387 ms 8076 KiB
01_random_02.txt AC 355 ms 7156 KiB
01_random_03.txt AC 312 ms 6700 KiB
01_random_04.txt AC 300 ms 6468 KiB
01_random_05.txt AC 269 ms 6312 KiB
01_random_06.txt AC 242 ms 6160 KiB
01_random_07.txt AC 230 ms 6180 KiB
01_random_08.txt AC 199 ms 6252 KiB
01_random_09.txt AC 172 ms 6328 KiB
01_random_10.txt AC 138 ms 6252 KiB
01_random_11.txt AC 394 ms 8856 KiB
01_random_12.txt AC 372 ms 8340 KiB
01_random_13.txt AC 346 ms 7820 KiB
01_random_14.txt AC 319 ms 7068 KiB
01_random_15.txt AC 297 ms 6812 KiB
01_random_16.txt AC 274 ms 6440 KiB
01_random_17.txt AC 247 ms 6352 KiB
01_random_18.txt AC 224 ms 6456 KiB
01_random_19.txt AC 198 ms 6380 KiB
01_random_20.txt AC 173 ms 6456 KiB
01_random_21.txt AC 148 ms 6436 KiB
01_random_22.txt AC 269 ms 6380 KiB
01_random_23.txt AC 273 ms 6452 KiB
02_handmade_00.txt AC 1 ms 3392 KiB
02_handmade_01.txt AC 1 ms 3572 KiB
02_handmade_02.txt AC 377 ms 9096 KiB