結果

問題 No.151 セグメントフィッシング
ユーザー 👑 kmjpkmjp
提出日時 2015-02-13 00:08:03
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,152 bytes
コンパイル時間 1,603 ms
コンパイル使用メモリ 148,548 KB
実行使用メモリ 15,284 KB
最終ジャッジ日時 2023-09-06 00:20:28
合計ジャッジ時間 2,875 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 5 ms
14,576 KB
testcase_02 AC 4 ms
10,544 KB
testcase_03 AC 4 ms
12,660 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 5 ms
14,660 KB
testcase_07 AC 5 ms
14,624 KB
testcase_08 AC 9 ms
14,688 KB
testcase_09 WA -
testcase_10 AC 9 ms
14,880 KB
testcase_11 AC 9 ms
14,680 KB
testcase_12 AC 24 ms
13,388 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 10 ms
10,820 KB
testcase_18 AC 11 ms
10,672 KB
testcase_19 WA -
testcase_20 AC 41 ms
13,080 KB
testcase_21 AC 14 ms
15,072 KB
testcase_22 AC 13 ms
15,100 KB
testcase_23 WA -
権限があれば一括ダウンロードができます

ソースコード

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);
			
			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);
			
			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);
			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