結果

問題 No.259 セグメントフィッシング+
ユーザー parukiparuki
提出日時 2016-07-25 20:51:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 1,695 bytes
コンパイル時間 1,496 ms
コンパイル使用メモリ 165,108 KB
実行使用メモリ 6,784 KB
最終ジャッジ日時 2024-04-24 09:27:20
合計ジャッジ時間 4,451 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 35 ms
6,528 KB
testcase_09 AC 33 ms
6,656 KB
testcase_10 AC 34 ms
6,656 KB
testcase_11 AC 33 ms
6,784 KB
testcase_12 AC 33 ms
6,656 KB
testcase_13 AC 37 ms
6,656 KB
testcase_14 AC 38 ms
6,656 KB
testcase_15 AC 38 ms
6,656 KB
testcase_16 AC 38 ms
6,528 KB
testcase_17 AC 38 ms
6,656 KB
testcase_18 AC 37 ms
6,528 KB
testcase_19 AC 36 ms
6,528 KB
testcase_20 AC 36 ms
6,656 KB
testcase_21 AC 36 ms
6,656 KB
testcase_22 AC 39 ms
6,528 KB
testcase_23 AC 25 ms
5,376 KB
testcase_24 AC 32 ms
6,656 KB
testcase_25 AC 32 ms
6,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

struct BIT{
    int n;
    vector<long long> t;
    BIT(){}
    BIT(int _n):n(_n+1), t(_n+1){}
    void add(int k, long long val){
        k++;
        while(k < n){
            t[k] += val;
            k += (k&-k);
        }
    }
    long long sum(int k){
        ll r = 0;
        while(k > 0){
            r += t[k];
            k -= (k&-k);
        }
        return r;
    }
    long long sum(int l, int r){
        return sum(r) - sum(l);
    }
};

int f(int a, int b, int md){
    return ((a - b) % md + md) % md;
}

int N, Q;

int main(){
    cin >> N >> Q;
    char x_[2], x;
    int t, y, z;
    const int M = 2 * N;
    BIT bit(M);
    
    while(Q--){
        scanf("%s%d%d%d", x_, &t, &y, &z);
        x = x_[0];
        auto h = [&](int l, int r){
            l = f(l, t, M);
            r = f(r - 1, t, M) + 1;
            if(r <= l)return bit.sum(l, M) + bit.sum(0, r);
            else return bit.sum(l, r);
        };
        if(x == 'C'){
            ll ans = h(y, z) + h(M - z, M - y);
            printf("%lld\n", ans);
        } else{
            if(x == 'L')
                y = M - 1 - y;
            y = f(y, t, M);
            bit.add(y, z);
        }
    }
}
0