結果

問題 No.259 セグメントフィッシング+
ユーザー 👑 kmjpkmjp
提出日時 2021-04-30 01:38:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 2,022 bytes
コンパイル時間 1,989 ms
コンパイル使用メモリ 202,352 KB
実行使用メモリ 23,996 KB
最終ジャッジ日時 2023-09-25 01:22:14
合計ジャッジ時間 5,735 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
17,796 KB
testcase_01 AC 5 ms
17,892 KB
testcase_02 AC 4 ms
15,668 KB
testcase_03 AC 4 ms
15,792 KB
testcase_04 AC 5 ms
17,736 KB
testcase_05 AC 4 ms
15,680 KB
testcase_06 AC 4 ms
15,680 KB
testcase_07 AC 3 ms
11,496 KB
testcase_08 AC 102 ms
22,212 KB
testcase_09 AC 104 ms
23,380 KB
testcase_10 AC 104 ms
20,008 KB
testcase_11 AC 102 ms
23,496 KB
testcase_12 AC 103 ms
21,596 KB
testcase_13 AC 108 ms
22,844 KB
testcase_14 AC 107 ms
23,788 KB
testcase_15 AC 113 ms
21,892 KB
testcase_16 AC 113 ms
21,960 KB
testcase_17 AC 112 ms
22,832 KB
testcase_18 AC 113 ms
22,948 KB
testcase_19 AC 113 ms
21,920 KB
testcase_20 AC 112 ms
22,948 KB
testcase_21 AC 109 ms
22,868 KB
testcase_22 AC 109 ms
22,960 KB
testcase_23 AC 38 ms
9,816 KB
testcase_24 AC 58 ms
23,820 KB
testcase_25 AC 59 ms
23,996 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 FORR(x,arr) for(auto& x:arr)
#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],val[1<<ME];
	V total(int e) {V s=0;e++;while(e) s+=bit[e-1],e-=e&-e; return s;}
	void add(int e,V v) { val[e++]+=v; while(e<=1<<ME) bit[e-1]+=v,e+=e&-e;}
};

BIT<ll,20> lbt,rbt;

int N,Q;
int X,T,Y,Z;

void solve() {
	int i,j,k,l,r,x,y,z,t; string s;
	
	cin>>N>>Q;
	while(Q--) {
		cin>>s>>t>>y>>z;
		if(s=="L") {
			y += t;
			y = ((y%(2*N))+2*N)%(2*N);
			lbt.add(y+1,z);
		}
		if(s=="R") {
			y -= t;
			y = ((y%(2*N))+2*N)%(2*N);
			rbt.add(y+1,z);
		}
		if(s=="C") {
			ll sum=0;
			
			ll L=y+t,R=z-1+t;
			L = ((L%(2*N))+2*N)%(2*N);
			R = ((R%(2*N))+2*N)%(2*N);
			if(R<L) sum += lbt.total(R+1) + lbt.total(2*N)-lbt.total(L);
			else sum += lbt.total(R+1) - lbt.total(L);
			
			L=2*N-1-(z-1)+t,R=2*N-1-y+t;
			L = ((L%(2*N))+2*N)%(2*N);
			R = ((R%(2*N))+2*N)%(2*N);
			if(R<L) sum += lbt.total(R+1) + lbt.total(2*N)-lbt.total(L);
			else sum += lbt.total(R+1) - lbt.total(L);
			
			L=y-t,R=z-1-t;
			L = ((L%(2*N))+2*N)%(2*N);
			R = ((R%(2*N))+2*N)%(2*N);
			if(R<L) sum += rbt.total(R+1) + rbt.total(2*N)-rbt.total(L);
			else sum += rbt.total(R+1) - rbt.total(L);
			
			L=2*N-1-(z-1)-t,R=2*N-1-y-t;
			L = ((L%(2*N))+2*N)%(2*N);
			R = ((R%(2*N))+2*N)%(2*N);
			if(R<L) sum += rbt.total(R+1) + rbt.total(2*N)-rbt.total(L);
			else sum += rbt.total(R+1) - rbt.total(L);
			
			cout<<sum<<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