結果

問題 No.151 セグメントフィッシング
ユーザー assy1028assy1028
提出日時 2017-01-02 00:11:58
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 11 ms / 5,000 ms
コード長 2,967 bytes
コンパイル時間 840 ms
コンパイル使用メモリ 98,720 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-22 10:10:19
合計ジャッジ時間 2,504 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n, q;
char x[20010];
int y[20010];
ll z[20010];

// 1 base
template<typename T, int max_n>
class BIT {
private:
    T bit[max_n + 1];
    int n;
public:
    BIT(int _n = max_n) {
        n = _n;
        memset(bit, 0, sizeof(bit));
    }
    // [1, i]
    T sum(int i) {
        T s = 0;
        while (i > 0) {
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }
    // [a, b]
    T sum(int a, int b) {
        return sum(b) - sum(a-1);
    }

    void add(int i, T x) {
        while (i <= n) {
            bit[i] += x;
            i += i & -i;
        }
    }

    int lower_bound(T x) {
        int lb = 0, ub = n;
        while (ub - lb > 1) {
            int mid = (ub + lb) / 2;
            T v = sum(mid);
            if (v < x) {
                lb = mid;
            } else {
                ub = mid;
            }
        }
        return ub;
    }

    int upper_bound(T x) {
        int lb = 1, ub = n+1;
        while (ub - lb > 1) {
            int mid = (ub + lb) / 2;
            T v = sum(mid);
            if (v <= x) {
                lb = mid;
            } else {
                ub = mid;
            }
        }
        return ub;
    }
};

BIT<ll, 40010> l;
BIT<ll, 40010> r;

void solve() {
    int idxl = 1, idxr = 20005;
    for (int i = 0; i < q; i++) {
        if (x[i] == 'L') {
            l.add(idxl+y[i], z[i]);
        } else if (x[i] == 'R') {
            r.add(idxr+y[i], z[i]);
        } else {
            cout << l.sum(idxl+y[i], idxl+z[i]-1) + r.sum(idxr+y[i], idxr+z[i]-1) << endl;
        }
        r.add(idxr-1, l.sum(idxl, idxl));
        l.add(idxl+n, r.sum(idxr+n-1, idxr+n-1));
        idxl++;
        idxr--;
    }
}

void input() {
    cin >> n >> q;
    for (int i = 0; i < q; i++) cin >> x[i] >> y[i] >> z[i];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    solve();
}
0