結果

問題 No.259 セグメントフィッシング+
ユーザー mamekinmamekin
提出日時 2016-10-09 22:42:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 148 ms / 2,000 ms
コード長 2,035 bytes
コンパイル時間 1,069 ms
コンパイル使用メモリ 102,552 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 18:35:31
合計ジャッジ時間 5,941 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 132 ms
6,940 KB
testcase_09 AC 130 ms
6,940 KB
testcase_10 AC 131 ms
6,944 KB
testcase_11 AC 131 ms
6,940 KB
testcase_12 AC 131 ms
6,944 KB
testcase_13 AC 142 ms
6,940 KB
testcase_14 AC 144 ms
6,944 KB
testcase_15 AC 145 ms
6,944 KB
testcase_16 AC 141 ms
6,940 KB
testcase_17 AC 143 ms
6,944 KB
testcase_18 AC 148 ms
6,944 KB
testcase_19 AC 146 ms
6,940 KB
testcase_20 AC 146 ms
6,940 KB
testcase_21 AC 141 ms
6,944 KB
testcase_22 AC 142 ms
6,940 KB
testcase_23 AC 83 ms
6,944 KB
testcase_24 AC 107 ms
6,944 KB
testcase_25 AC 107 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

// Binary Indexed Tree
template <class T = int>
class BinaryIndexedTree
{
private:
    int n;
    vector<T> data;
public:
    BinaryIndexedTree(int n){ // コンストラクタ
        this->n = n;
        data.assign(n+1, 0);
    }
    void add(int k, T x){ // k番目の要素にxを加算する
        ++ k;
        while(k <= n){
            data[k] += x;
            k += k & -k;
        }
    }
    T sum(int k){ // 区間[0,k]の総和を返す
        ++ k;
        T ret = 0;
        while(k > 0){
            ret += data[k];
            k -= k & -k;
        }
        return ret;
    }
    T sum(int a, int b){ // 区間[a,b]の総和を返す
        return sum(b) - sum(a-1);
    }
};

int main()
{
    int n, q;
    cin >> n >> q;

    BinaryIndexedTree<long long> bit(2*n);
    while(--q >= 0){
        char x;
        int t, y, z;
        cin >> x >> t >> y >> z;

        if(x == 'R'){
            int a = (2 * n - 1 - y + t) % (2 * n);
            bit.add(a, z);
        }
        else if(x == 'L'){
            int a = (y + t) % (2 * n);
            bit.add(a, z);
        }
        else{
            long long ret = 0;
            int a = (y + t) % (2 * n);
            int b = (z - 1 + t) % (2 * n);
            if(a <= b)
                ret += bit.sum(a, b);
            else
                ret += bit.sum(0, b) + bit.sum(a, 2*n-1);

            b = (2 * n - 1 - y + t) % (2 * n);
            a = (2 * n - z + t) % (2 * n);
            if(a <= b)
                ret += bit.sum(a, b);
            else
                ret += bit.sum(0, b) + bit.sum(a, 2*n-1);

            cout << ret << endl;
        }
    }

    return 0;
}
0