結果

問題 No.151 セグメントフィッシング
ユーザー mayoko_mayoko_
提出日時 2015-02-13 18:07:35
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 43 ms / 5,000 ms
コード長 2,333 bytes
コンパイル時間 542 ms
コンパイル使用メモリ 75,384 KB
実行使用メモリ 14,140 KB
最終ジャッジ日時 2023-09-06 00:40:26
合計ジャッジ時間 2,133 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
13,644 KB
testcase_01 AC 4 ms
13,592 KB
testcase_02 AC 2 ms
9,568 KB
testcase_03 AC 3 ms
11,712 KB
testcase_04 AC 3 ms
13,700 KB
testcase_05 AC 3 ms
11,640 KB
testcase_06 AC 3 ms
13,668 KB
testcase_07 AC 4 ms
13,600 KB
testcase_08 AC 8 ms
13,748 KB
testcase_09 AC 8 ms
11,868 KB
testcase_10 AC 8 ms
13,720 KB
testcase_11 AC 8 ms
13,736 KB
testcase_12 AC 26 ms
12,364 KB
testcase_13 AC 28 ms
14,140 KB
testcase_14 AC 27 ms
12,432 KB
testcase_15 AC 27 ms
14,112 KB
testcase_16 AC 26 ms
12,336 KB
testcase_17 AC 16 ms
9,896 KB
testcase_18 AC 17 ms
9,680 KB
testcase_19 AC 43 ms
13,944 KB
testcase_20 AC 41 ms
12,136 KB
testcase_21 AC 17 ms
14,064 KB
testcase_22 AC 16 ms
14,084 KB
testcase_23 AC 22 ms
13,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// kmjpさんのコード参考
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std;
typedef long long ll;

const int MAXN = 40040;

template<class V, int ME> class BIT {
public:
    V bit[1<<ME];
    V total(int e) {
        V s = 0;
        e++;
        while (e) {
            s += bit[e-1];
            e -= e & -e;
        }
        return s;
    }
    void update(int e, V val) {
        e++;
        while (e <= (1<<ME)) {
            bit[e-1] += val;
            e += e&-e;
        }
    }
};

BIT<ll, 20> Lbit;
BIT<ll, 20> Rbit;

int N, N2, Q;
char X[30000];
int Y[30000], Z[30000];

int momo(int a) {return (a%N2+N2)%N2;}

void solve() {
    cin >> N >> Q;
    N2 = 2*N;
    for (int i = 0; i < Q; i++) {
        cin >> X[i] >> Y[i] >> Z[i];
        if (X[i] == 'L') {
            Lbit.update(1+momo(Y[i]+i+1), Z[i]);
        }
        if (X[i] == 'R') {
            Rbit.update(1+momo(Y[i]-(i+1)), Z[i]);
        }
        if (X[i] == 'C') {
            Z[i]--;
            ll ret = 0;
            {
                int x = momo(Y[i]+(i+1));
                int y = momo(Z[i]+(i+1));
                if (x <= y) ret += Lbit.total(y+1)-Lbit.total(x);
                else ret += Lbit.total(N2+2)-Lbit.total(x)+Lbit.total(y+1);
            }
            {
                int x = momo(N2-1-Z[i]+(i+1));
                int y = momo(N2-1-Y[i]+(i+1));
                if (x <= y) ret += Lbit.total(y+1)-Lbit.total(x);
                else ret += Lbit.total(N2+2)-Lbit.total(x)+Lbit.total(y+1);
            }
            {
                int x = momo(Y[i]-(i+1));
                int y = momo(Z[i]-(i+1));
                if (x <= y) ret += Rbit.total(y+1)-Rbit.total(x);
                else ret += Rbit.total(N2+2)-Rbit.total(x)+Rbit.total(y+1);
            }
            {
                int x = momo(N2-1-Z[i]-(i+1));
                int y = momo(N2-1-Y[i]-(i+1));
                if (x <= y) ret += Rbit.total(y+1)-Rbit.total(x);
                else ret += Rbit.total(N2+2)-Rbit.total(x)+Rbit.total(y+1);
            }
            cout << ret << endl;
        }
    }
}

int main() {
    solve();
}
0