結果

問題 No.259 セグメントフィッシング+
ユーザー machymachy
提出日時 2015-08-01 00:32:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 154 ms / 2,000 ms
コード長 2,552 bytes
コンパイル時間 467 ms
コンパイル使用メモリ 62,936 KB
実行使用メモリ 12,556 KB
最終ジャッジ日時 2023-09-24 23:57:40
合計ジャッジ時間 4,573 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 143 ms
12,300 KB
testcase_09 AC 141 ms
12,288 KB
testcase_10 AC 141 ms
12,404 KB
testcase_11 AC 141 ms
12,424 KB
testcase_12 AC 140 ms
12,416 KB
testcase_13 AC 153 ms
12,344 KB
testcase_14 AC 152 ms
12,352 KB
testcase_15 AC 154 ms
12,340 KB
testcase_16 AC 153 ms
12,460 KB
testcase_17 AC 152 ms
12,492 KB
testcase_18 AC 154 ms
12,468 KB
testcase_19 AC 152 ms
12,556 KB
testcase_20 AC 154 ms
12,396 KB
testcase_21 AC 153 ms
12,340 KB
testcase_22 AC 152 ms
12,284 KB
testcase_23 AC 79 ms
4,376 KB
testcase_24 AC 114 ms
12,464 KB
testcase_25 AC 113 ms
12,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;

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

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

            cout << ans << endl;
        }
    }
    return 0;
}
0