Submission #69661820


Source Code Expand

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int N, Q; cin >> N >> Q;
  vector<ll> A(N); for(int i=0; i<N; i++) cin >> A[i];

  vector<ll> S(N+1);
  for (int i=0; i<N; i++) S[i+1] = S[i] + A[i];

  int offset=0;
  while(Q--){
    int type; cin >> type;
    if(type==1){
      int c; cin >> c;
       offset = (offset+c)%N;
    }else{
      int l, r; cin >> l >> r;
      int il = (offset+l-1)%N + 1;
      int ir = (offset+r-1)%N + 1;

      ll ans=0;
      if(il<=ir) ans = S[ir]-S[il-1];
      else ans = (S[N]-S[il-1])+S[ir];
      cout << ans << "\n";
    } 
  }
  return 0;
}

Submission Info

Submission Time
Task C - Rotate and Sum Query
User tkar821
Language C++ 23 (gcc 12.2)
Score 350
Code Size 749 Byte
Status AC
Exec Time 53 ms
Memory 6796 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 350 / 350
Status
AC × 2
AC × 22
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
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3468 KiB
00_sample_01.txt AC 1 ms 3548 KiB
01_random_00.txt AC 1 ms 3472 KiB
01_random_01.txt AC 20 ms 3612 KiB
01_random_02.txt AC 28 ms 5024 KiB
01_random_03.txt AC 15 ms 6320 KiB
01_random_04.txt AC 27 ms 3604 KiB
01_random_05.txt AC 40 ms 6384 KiB
01_random_06.txt AC 26 ms 3596 KiB
01_random_07.txt AC 40 ms 6316 KiB
01_random_08.txt AC 35 ms 4884 KiB
01_random_09.txt AC 40 ms 6208 KiB
01_random_10.txt AC 34 ms 5012 KiB
01_random_11.txt AC 40 ms 6244 KiB
01_random_12.txt AC 27 ms 6328 KiB
01_random_13.txt AC 27 ms 6228 KiB
01_random_14.txt AC 53 ms 6524 KiB
01_random_15.txt AC 51 ms 6492 KiB
01_random_16.txt AC 47 ms 6204 KiB
01_random_17.txt AC 33 ms 6276 KiB
01_random_18.txt AC 44 ms 6796 KiB
01_random_19.txt AC 34 ms 6240 KiB