提出 #69654696


ソースコード 拡げる

#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;
            }
        }
    }
}

提出情報

提出日時
問題 C - Rotate and Sum Query
ユーザ tsuyosshi
言語 C++ 20 (gcc 12.2)
得点 350
コード長 1892 Byte
結果 AC
実行時間 346 ms
メモリ 6784 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 350 / 350
結果
AC × 2
AC × 22
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
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