結果
| 問題 | 
                            No.259 セグメントフィッシング+
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2016-10-09 22:42:07 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 137 ms / 2,000 ms | 
| コード長 | 2,035 bytes | 
| コンパイル時間 | 954 ms | 
| コンパイル使用メモリ | 103,724 KB | 
| 実行使用メモリ | 6,528 KB | 
| 最終ジャッジ日時 | 2024-11-22 00:26:07 | 
| 合計ジャッジ時間 | 6,523 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 23 | 
ソースコード
#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;
}