結果

問題 No.151 セグメントフィッシング
ユーザー yuustiyuusti
提出日時 2015-02-13 08:03:39
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 2,106 bytes
コンパイル時間 633 ms
コンパイル使用メモリ 77,632 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-06 00:37:05
合計ジャッジ時間 1,813 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 3 ms
4,384 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 4 ms
4,376 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 8 ms
4,380 KB
testcase_13 AC 7 ms
4,376 KB
testcase_14 AC 8 ms
4,376 KB
testcase_15 AC 8 ms
4,384 KB
testcase_16 AC 8 ms
4,380 KB
testcase_17 AC 6 ms
4,380 KB
testcase_18 AC 6 ms
4,380 KB
testcase_19 AC 9 ms
4,380 KB
testcase_20 AC 8 ms
4,376 KB
testcase_21 AC 7 ms
4,376 KB
testcase_22 AC 7 ms
4,376 KB
testcase_23 AC 6 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <array>
#include <climits>
#include <bitset>
#include <cassert>

#ifdef _MSC_VER
#include <agents.h>
#endif

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define UNIQUE(v) (v).erase(unique(ALL(v)), (v).end())
#define MP make_pair
#define MT make_tuple

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;

int n, nn, l;

const int N = 1e5;

template<class T>
struct BIT{
	vector<T> dat;
	int n;

	BIT(int _n){
		n = _n + 10;
		dat.resize(n);
	}

	void add(int x, T val){
		for (int i = ++x; i < n; i += i&-i) dat[i] += val;
	}
	T sum(int a){
		return sum(0, a);
	}
	T sum(int a, int b){
		if (a != 0) return sum(0, b) - sum(0, a);
		T res = 0;
		for (int i = b; i > 0; i -= i&-i) res += dat[i];
		return res;
	}
};

BIT<ll> cnt(N);

void L(int y, int z){
	cnt.add((l + nn - y - 1) % nn, z);
}

void R(int y, int z){
	cnt.add((l + y) % nn, z);
}

ll get(int l, int r){
	if (l >= nn) return get(l - nn, r - nn);
	if (r <= nn) return cnt.sum(l, r);
	return get(l, nn) + get(0, r%nn);
}

// [l+y, l+z)
// (l+nn-z, l+nn-y]
ll count(int y, int z){
	ll a = get(l + y, l + z);
	ll b = get(l + nn - z, l + nn - y);
	return a + b;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout.setf(ios::fixed);
	cout.precision(20);

	int n, q;
	cin >> n >> q;
	nn = n * 2;

	int cnt[N] = {};

	while (q--){
		l = (l - 1 + nn) % nn;
		char x;
		int y, z;
		cin >> x >> y >> z;
		if (x == 'L') L(y, z);
		else if (x == 'R') R(y, z);
		else{
			cout << count(y, z) << '\n';
		}

		//int cnt[N] = {};
		//for (int i = 0; i < n; ++i){
		//	cnt[i] += count(i, i + 1);
		//	cout << cnt[i] << ' ';
		//}
		//cout << endl;
	}
}
0