結果

問題 No.151 セグメントフィッシング
ユーザー tkzw_21tkzw_21
提出日時 2015-03-17 17:51:24
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 45 ms / 5,000 ms
コード長 1,302 bytes
コンパイル時間 4,024 ms
コンパイル使用メモリ 147,844 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-11 08:30:28
合計ジャッジ時間 3,636 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

//ドワンゴ フィッシング 8020
//SYAKYO
//http://yukicoder.me/submissions/12291
#include <bits/stdc++.h>

using namespace std;

typedef pair<int,int> P;
typedef pair<int,pair<int,int>> PP;
typedef long long ll;

const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9+7;

int dy[] = {0,1,0,-1};
int dx[] = {1,0,-1,0};

//fenwick_tree
template <class T>
struct BIT{
	int N;vector<T>bit;
	BIT(int n):N(n),bit(n+1){}
	void add(T k,int i){i++;for(int x=i;x<=N;x+=x&-x)bit[x]+=k;}
	T sum(int i){i++;T r=0;for(int x=i;x>0;x-=x&-x)r+=bit[x];return r;}
	T sum(int l,int r){return l<=r ? sum(r)-sum(l-1):sum(r)+sum(l,N-1);}
	T get(int i){return sum(i) - sum(i-1);}
	void set(T k,int i){add(k-get(i),i);}
};

int fix(int a,int N2){
	return (a%N2+N2)%N2;
}
int main(void) {	
	int N,Q;
	cin >> N >> Q;
	BIT<ll> lfw(2*N+1),rfw(2*N+1);
	char x;
	int y,z;
	int N2 = N+N;
	for(int t=1;t<=Q;t++){
		cin >> x >> y >> z;
		if(x == 'L'){
			lfw.add(z,fix(y+t,N2));
		}
		if(x == 'R'){
			rfw.add(z,fix(y-t,N2));
		}
		if(x == 'C'){
			z--;
			ll ret = 0;
			ret += lfw.sum(fix(y+t,N2),fix(z+t,N2));
			ret += lfw.sum(fix(N2-1-z +t,N2),fix(N2-1-y +t,N2));
			ret += rfw.sum(fix(y-t,N2),fix(z-t,N2));
			ret += rfw.sum(fix(N2-1-z -t,N2),fix(N2-1-y -t,N2));
			cout << ret << endl;
		}
	}
	return 0;
}

0