結果

問題 No.151 セグメントフィッシング
ユーザー otsnskotsnsk
提出日時 2015-02-17 22:03:01
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 2,035 bytes
コンパイル時間 585 ms
コンパイル使用メモリ 71,612 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-06 01:12:14
合計ジャッジ時間 1,911 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

#define FORR(i,b,e) for(int i=(b);i<(int)(e);++i)
#define FOR(i,e) FORR(i,0,e)
#define sortuniq(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(),v.end()),v.end())
#define dump(var) cerr << #var ": " << var << "\n"
#define dumpc(con) for(auto& e: con) cerr << e << " "; cerr<<"\n"

typedef long long ll;
typedef unsigned long long ull;

const double EPS = 1e-6;
const int d4[] = {0, -1, 0, 1, 0};

using namespace std;


template<class T>
struct BIT {
    int size;
    vector<T> bit;
    BIT(int size):size(size), bit(size+1) {}
    void add(int p, T v) {
        p++;
        for (; p <= size; p+=(p&-p)) bit[p]+=v;
    }
    // [0, p]
    T sum(int p) {
        p++;
        T r = 0;
        for (; p > 0; p-=(p&-p)) r += bit[p];
        return r;
    }
    // [a, b]
    T sum(int a, int b) {
        return sum(b) - sum(a-1);
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N, Q;
    cin >> N >> Q;
    vector<char> x(Q);
    vector<int> y(Q), z(Q);
    FOR(i, Q) cin >> x[i] >> y[i] >> z[i];

    BIT<ll> bit(1<<16);
    int n2 = N * 2;
    FOR(i, Q) {
        // cout << x[i] << ' ' << y[i] << ' ' << z[i] << endl;
        if (x[i] == 'R') {
            int p = (n2 + y[i] - i%n2) % n2;
            bit.add(p, z[i]);
        }
        else if (x[i] == 'L') {
            int p = (n2 + n2 - y[i] - 1 - i%n2) % n2;
            bit.add(p, z[i]);

        }
        else {
            ll total = 0;
            int pos[2][2] = {{y[i],z[i]}, {n2-z[i],n2-y[i]}};
            for (const auto &p: pos) {
                int l = (n2 + p[0] - i%n2) % n2;
                int r = (n2 + p[1] - i%n2) % n2;
                if (l < r) {
                    total += bit.sum(l, r-1);
                }
                else {
                    if (r > 0) total += bit.sum(r-1);
                    total += bit.sum(l, n2-1);
                }
            }
            cout << total << '\n';
        }
    }
    
    return 0;
}
0