提出 #69668415


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

struct BIT {
    int n;
    vector<long long> bit; // 1-indexed

    BIT(int n): n(n), bit(n+1, 0) {}

    void add(int i, long long x) {
        for(; i <= n; i += i & -i) bit[i] += x;
    }

    long long sum(int i) {
        long long s = 0;
        for(; i > 0; i -= i & -i) s += bit[i];
        return s;
    }

    long long sum(int l, int r) {
        if(l > r) return 0;
        return sum(r) - sum(l-1);
    }
};

int main() {
    int n,q;
    cin >> n >> q;
    int count=0;
    BIT f(n);

    for (int i=1;i<=n;i++) {
        int a; cin >> a;
        f.add(i,a);
    }

    while (q--) {
        int O; cin >> O;
        if (O==1) {
            int c; cin >> c;
            count = (count - c + n) % n; // 回転オフセット更新
        }
        else {
            int l,r; cin >> l >> r;

            // 入力は1-index → 0-indexに直して回転調整 → 1-indexに戻す
            l = ((l - 1 - count) % n + n) % n + 1;
            r = ((r - 1 - count) % n + n) % n + 1;

            if (l <= r) {
                cout << f.sum(l,r) << "\n";
            } else {
                cout << f.sum(l,n) + f.sum(1,r) << "\n";
            }
        }
    }
}

提出情報

提出日時
問題 C - Rotate and Sum Query
ユーザ Rsetu45
言語 C++ 23 (gcc 12.2)
得点 350
コード長 1304 Byte
結果 AC
実行時間 359 ms
メモリ 5224 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 3572 KiB
00_sample_01.txt AC 1 ms 3444 KiB
01_random_00.txt AC 1 ms 3572 KiB
01_random_01.txt AC 147 ms 3456 KiB
01_random_02.txt AC 167 ms 4228 KiB
01_random_03.txt AC 72 ms 4632 KiB
01_random_04.txt AC 174 ms 3576 KiB
01_random_05.txt AC 232 ms 4696 KiB
01_random_06.txt AC 168 ms 3536 KiB
01_random_07.txt AC 232 ms 4688 KiB
01_random_08.txt AC 207 ms 4160 KiB
01_random_09.txt AC 231 ms 4644 KiB
01_random_10.txt AC 203 ms 3844 KiB
01_random_11.txt AC 236 ms 4756 KiB
01_random_12.txt AC 101 ms 4656 KiB
01_random_13.txt AC 102 ms 4636 KiB
01_random_14.txt AC 359 ms 4920 KiB
01_random_15.txt AC 358 ms 4964 KiB
01_random_16.txt AC 307 ms 4700 KiB
01_random_17.txt AC 155 ms 4644 KiB
01_random_18.txt AC 330 ms 5224 KiB
01_random_19.txt AC 212 ms 4700 KiB