結果

問題 No.151 セグメントフィッシング
ユーザー なおなお
提出日時 2015-02-13 02:36:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 31 ms / 5,000 ms
コード長 1,478 bytes
コンパイル時間 1,273 ms
コンパイル使用メモリ 148,476 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-06 00:34:37
合計ジャッジ時間 2,590 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 5 ms
4,376 KB
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 6 ms
4,376 KB
testcase_12 AC 16 ms
4,376 KB
testcase_13 AC 17 ms
4,376 KB
testcase_14 AC 17 ms
4,380 KB
testcase_15 AC 17 ms
4,376 KB
testcase_16 AC 17 ms
4,376 KB
testcase_17 AC 6 ms
4,380 KB
testcase_18 AC 6 ms
4,380 KB
testcase_19 AC 30 ms
4,376 KB
testcase_20 AC 31 ms
4,376 KB
testcase_21 AC 7 ms
4,376 KB
testcase_22 AC 7 ms
4,376 KB
testcase_23 AC 14 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define REP(i, n)           for(int(i)=0;(i)<(n);++(i))
#define FOR(i, f, t)        for(int(i)=(f);(i)<(t);(++i))
#define RREP(i, n)          for(int(i)=(n)-1;(i)>=0;--(i))
const int MOD = int(1e9+7);

// 0-index BIT
template<class _T>struct BIT{
    int N;vector<_T>bit;
    BIT(int n):N(n),bit(n+1){}
    void add(int i,_T v){i++;for(int x=i;x<=N;x+=x&-x)bit[x]+=v;}
    _T sum(int i){i++;_T r=0;for(int x=i;x>0;x-=x&-x)r+=bit[x];return r;}
    _T sum(int l,int r){return l<=r?sum(r)-sum(l-1):sum(r)+sum(l,N-1);}
    _T get(int i){return sum(i)-sum(i-1);}
    void set(int i,_T v){add(i,v-get(i));}
};

int N,Q,N2;
BIT<ll> l(44444), r(44444);

int fix(int n){ return (n % N2 + N2) % N2; }

int main(){
    do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0);

    cin >> N >> Q;
    N2 = N * 2;

    REP(i,Q){
        int t = i+1;
        char x; int y,z; cin >> x >> y >> z;
        if(x == 'L'){
            l.add(fix(y+t), z);
        } else if(x == 'R'){
            r.add(fix(y-t), z);
        } else {
            z--;
            ll res = 0;
            res += l.sum(fix(y+t), fix(z+t));
            res += l.sum(fix(N2-1-z+t), fix(N2-1-y+t));
            res += r.sum(fix(y-t), fix(z-t));
            res += r.sum(fix(N2-1-z-t), fix(N2-1-y-t));
            cout << res << endl;
        }
    }
    return 0;
}
0