結果

問題 No.151 セグメントフィッシング
ユーザー parukiparuki
提出日時 2016-07-25 20:58:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 5,000 ms
コード長 1,694 bytes
コンパイル時間 1,633 ms
コンパイル使用メモリ 164,988 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 09:27:33
合計ジャッジ時間 3,037 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 4 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 9 ms
5,376 KB
testcase_13 AC 10 ms
5,376 KB
testcase_14 AC 10 ms
5,376 KB
testcase_15 AC 9 ms
5,376 KB
testcase_16 AC 9 ms
5,376 KB
testcase_17 AC 7 ms
5,376 KB
testcase_18 AC 7 ms
5,376 KB
testcase_19 AC 11 ms
5,376 KB
testcase_20 AC 11 ms
5,376 KB
testcase_21 AC 8 ms
5,376 KB
testcase_22 AC 8 ms
5,376 KB
testcase_23 AC 8 ms
5,376 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 y, z;
    const int M = 2 * N;
    BIT bit(M);
    
    FOR(t, 1, Q + 1){
        scanf("%s%d%d%d", x_, &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