結果

問題 No.151 セグメントフィッシング
ユーザー 👑 kmjpkmjp
提出日時 2015-02-13 00:09:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 43 ms / 5,000 ms
コード長 2,212 bytes
コンパイル時間 1,276 ms
コンパイル使用メモリ 148,332 KB
実行使用メモリ 15,264 KB
最終ジャッジ日時 2023-09-06 00:20:40
合計ジャッジ時間 2,783 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
14,760 KB
testcase_01 AC 5 ms
14,832 KB
testcase_02 AC 4 ms
10,708 KB
testcase_03 AC 4 ms
12,644 KB
testcase_04 AC 5 ms
14,552 KB
testcase_05 AC 4 ms
12,592 KB
testcase_06 AC 4 ms
14,612 KB
testcase_07 AC 5 ms
14,616 KB
testcase_08 AC 9 ms
14,668 KB
testcase_09 AC 9 ms
12,824 KB
testcase_10 AC 9 ms
14,788 KB
testcase_11 AC 8 ms
14,720 KB
testcase_12 AC 24 ms
13,292 KB
testcase_13 AC 23 ms
15,072 KB
testcase_14 AC 23 ms
13,348 KB
testcase_15 AC 23 ms
15,076 KB
testcase_16 AC 23 ms
13,400 KB
testcase_17 AC 10 ms
10,816 KB
testcase_18 AC 11 ms
10,684 KB
testcase_19 AC 42 ms
14,896 KB
testcase_20 AC 43 ms
13,092 KB
testcase_21 AC 12 ms
15,264 KB
testcase_22 AC 14 ms
15,124 KB
testcase_23 AC 20 ms
14,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<to;x++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

template<class V, int ME> class BIT {
public:
	V bit[1<<ME];
	int lower_bound(V val) {
		V tv=0; int i,ent=0;
		for(i=ME-1;i>=0;i--) if(tv+bit[ent+(1<<i)-1]<val) tv+=bit[ent+(1<<i)-1],ent+=(1<<i);
		return ent;
	}
	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> Lbt;
BIT<ll,20> Rbt;


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

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

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>Q;
	N2=2*N;
	FOR(i,Q) {
		cin>>X[i]>>Y[i]>>Z[i];
		if(X[i][0]=='L') {
			Lbt.update(1+momo(Y[i]+i+1),Z[i]);
		}
		if(X[i][0]=='R') {
			Rbt.update(1+momo(Y[i]-(i+1)),Z[i]);
		}
		if(X[i][0]=='C') {
			Z[i]--;
			ll ret=0;
			x=momo(Y[i]+(i+1));
			y=momo(Z[i]+(i+1));
			//_P("L %d %d\n",x,y);
			if(x<=y) ret +=Lbt.total(y+1)-Lbt.total(x);
			else ret +=Lbt.total(N2+2)-Lbt.total(x) + Lbt.total(y+1);
			//cout<<ret<<endl;
			x=momo(N2-1-Z[i]+(i+1));
			y=momo(N2-1-Y[i]+(i+1));
			//_P("L %d %d\n",x,y);
			if(x<=y) ret +=Lbt.total(y+1)-Lbt.total(x);
			else ret +=Lbt.total(N2+2)-Lbt.total(x) + Lbt.total(y+1);
			//cout<<ret<<endl;
			x=momo(Y[i]-(i+1));
			y=momo(Z[i]-(i+1));
			//_P("R %d %d\n",x,y);
			if(x<=y) ret +=Rbt.total(y+1)-Rbt.total(x);
			else ret +=Rbt.total(N2+2)-Rbt.total(x) + Rbt.total(y+1);
			//cout<<ret<<endl;
			x=momo(N2-1-Z[i]-(i+1));
			y=momo(N2-1-Y[i]-(i+1));
			//_P("R %d %d\n",x,y);
			if(x<=y) ret +=Rbt.total(y+1)-Rbt.total(x);
			else ret +=Rbt.total(N2+2)-Rbt.total(x) + Rbt.total(y+1);
			
			cout<<ret<<endl;
		}
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}
0