Submission #69654696
Source Code Expand
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define int long long
#define ALL(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
typedef pair<int, int> PI;
typedef pair<int, pair<int, int>> PII;
static const int INF = 1010000000000000017LL;
static const double eps = 1e-12;
static const double pi = 3.14159265358979323846;
static const int dx[4] = {1, -1, 0, 0};
static const int dy[4] = {0, 0, 1, -1};
static const int ddx[8] = {1, -1, 0, 0, 1, 1, -1, -1};
static const int ddy[8] = {0, 0, 1, -1, 1, -1, 1, -1};
template <class T>
inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T>
inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int N, Q;
signed main() {
cin >> N >> Q;
vector<int> A(N);
for (int i = 0; i < N; ++i) {
cin >> A[i];
}
vector<int> S(N);
for (int i = 0; i < N; ++i) {
if (i == 0) {
S[i] = A[i];
} else {
S[i] = S[i - 1] + A[i];
}
}
int k = 0;
while (Q--) {
int q;
cin >> q;
if (q == 1) {
int x;
cin >> x;
k += x;
} else if (q == 2) {
int l, r;
cin >> l >> r;
l--, r--;
l += k;
r += k;
l %= N;
r %= N;
if (l <= r) {
if (l == 0) {
cout << S[r] << endl;
} else {
cout << S[r] - S[l - 1] << endl;
}
} else {
cout << S[N - 1] - S[l - 1] + S[r] << endl;
}
}
}
}
Submission Info
| Submission Time |
|
| Task |
C - Rotate and Sum Query |
| User |
tsuyosshi |
| Language |
C++ 20 (gcc 12.2) |
| Score |
350 |
| Code Size |
1892 Byte |
| Status |
AC |
| Exec Time |
346 ms |
| Memory |
6784 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
350 / 350 |
| Status |
|
|
| 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 |
3600 KiB |
| 00_sample_01.txt |
AC |
1 ms |
3532 KiB |
| 01_random_00.txt |
AC |
1 ms |
3492 KiB |
| 01_random_01.txt |
AC |
144 ms |
3492 KiB |
| 01_random_02.txt |
AC |
160 ms |
4948 KiB |
| 01_random_03.txt |
AC |
69 ms |
6396 KiB |
| 01_random_04.txt |
AC |
168 ms |
3816 KiB |
| 01_random_05.txt |
AC |
223 ms |
6304 KiB |
| 01_random_06.txt |
AC |
162 ms |
3588 KiB |
| 01_random_07.txt |
AC |
225 ms |
6256 KiB |
| 01_random_08.txt |
AC |
202 ms |
4996 KiB |
| 01_random_09.txt |
AC |
223 ms |
6324 KiB |
| 01_random_10.txt |
AC |
196 ms |
5148 KiB |
| 01_random_11.txt |
AC |
222 ms |
6308 KiB |
| 01_random_12.txt |
AC |
100 ms |
6256 KiB |
| 01_random_13.txt |
AC |
100 ms |
6336 KiB |
| 01_random_14.txt |
AC |
344 ms |
6500 KiB |
| 01_random_15.txt |
AC |
346 ms |
6540 KiB |
| 01_random_16.txt |
AC |
298 ms |
6324 KiB |
| 01_random_17.txt |
AC |
148 ms |
6316 KiB |
| 01_random_18.txt |
AC |
320 ms |
6784 KiB |
| 01_random_19.txt |
AC |
206 ms |
6328 KiB |