結果

問題 No.259 セグメントフィッシング+
ユーザー machymachy
提出日時 2015-07-31 23:57:11
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,390 bytes
コンパイル時間 536 ms
コンパイル使用メモリ 63,624 KB
実行使用メモリ 8,100 KB
最終ジャッジ日時 2023-09-24 23:47:48
合計ジャッジ時間 4,526 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;

struct SegTree{
    vector<int> data_;
    static int operation(int op1, int op2){
        return op1 + op2;
    }
    SegTree(const vector<int>& src){
        data_.resize(src.size() * 2);
        for(size_t i = 0; i < src.size(); i++) update(i, src[i]);
    }
    int query(size_t begin, size_t end, int init) const{
        begin += data_.size()/2; end += data_.size()/2;
        for(; begin < end; begin /= 2, end /= 2){
            if(begin & 1) init = operation(init, data_[begin++]);
            if(end & 1) init = operation(init, data_[end-1]);
        }
        return init;
    }
    void update(size_t pos, int val){
        pos += data_.size()/2;
        data_[pos] = val;
        while((pos /= 2) > 0){
            data_[pos] = operation(data_[pos*2], data_[pos*2+1]);
        }
    }
};

int main(){
    int n, q;
    cin >> n >> q;
    int n2 = (n)*2;
    vector<int> src(n2);
    SegTree seg(src);
    for(int i = 0; i < q; i++){
        char x;
        int t, y, z;
        cin >> x >> t >> y >> z;
        if(x == 'R'){
            int y2 = (y - t % (n2) + n2) % n2;
            int cur = seg.query(y2, y2+1, 0);
            seg.update(y2, cur + z);
            //cerr << "update y2=" << y2 << ", v=" << cur + z << endl;
        }else if(x == 'L'){
            int y3 = (n2-1 - y - t % (n2) + n2) % n2;
            int cur = seg.query(y3, y3+1, 0);
            seg.update(y3, cur + z);
            //cerr << "update y3=" << y3 << ", v=" << cur + z << endl;
        }else{
            int ans = 0;
            int width = z - y;
            int y2 = (y - t % (n2) + n2) % n2;
            int z2 = (z - t % (n2) + n2) % n2;
            //cerr << "y2=" << y2 << ", z2=" << z2 << endl;
            if(y2 + width > n2){
                ans += seg.query(y2, n2, 0);
                ans += seg.query(0, z2, 0);
            }else{
                ans += seg.query(y2, z2, 0);
            }
            int y3 = (n2 - z - t % (n2) + n2) % n2;
            int z3 = (n2 - y - t % (n2) + n2) % n2;
            //cerr << "y3=" << y3 << ", z3=" << z3 << endl;
            if(y3 + width > n2){
                ans += seg.query(y3, n2, 0);
                ans += seg.query(0, z3, 0);
            }else{
                ans += seg.query(y3, z3, 0);
            }
            cout << ans << endl;
        }
    }
    return 0;
}
0