結果

問題 No.259 セグメントフィッシング+
ユーザー hirokazu1020hirokazu1020
提出日時 2015-07-31 23:47:32
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 1,656 bytes
コンパイル時間 763 ms
コンパイル使用メモリ 79,320 KB
実行使用メモリ 6,432 KB
最終ジャッジ日時 2023-08-25 02:14:40
合計ジャッジ時間 5,706 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 117 ms
6,404 KB
testcase_09 AC 118 ms
6,268 KB
testcase_10 AC 118 ms
6,332 KB
testcase_11 AC 117 ms
6,084 KB
testcase_12 AC 118 ms
6,128 KB
testcase_13 AC 127 ms
6,280 KB
testcase_14 AC 128 ms
6,432 KB
testcase_15 AC 127 ms
6,132 KB
testcase_16 AC 128 ms
6,232 KB
testcase_17 AC 129 ms
6,204 KB
testcase_18 AC 129 ms
6,084 KB
testcase_19 AC 128 ms
6,208 KB
testcase_20 AC 126 ms
6,160 KB
testcase_21 AC 126 ms
6,084 KB
testcase_22 AC 129 ms
6,204 KB
testcase_23 AC 76 ms
4,384 KB
testcase_24 AC 93 ms
6,140 KB
testcase_25 AC 92 ms
6,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<sstream>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())
#define indexOf(v,x) (find(all(v),x)-v.begin())




class BIT{
	std::vector<long long> bit;
public:
	BIT(int size):bit(size+1,0){}
	void add(int i,int x){//i番目にx加える
		i++;
		while(i<(int)bit.size()){
			bit[i]+=x;
			i+= i&-i;
		}
	}
	long long sum(int a)const{//[0,a]の和
		a++;
		long long res=0;
		while(0<a){
			res+=bit[a];
			a-= a&-a;
		}
		return res;
	}
	long long sum(int a,int b)const{//[a,b]の合計
		return sum(b)-sum(a-1);
	}
	void zeroclear(){
		bit.assign(bit.size(),0);
	}
};


int n,q;

int code(char dir,int x,int t){
	int ret;
	if(dir=='R'){
		ret = x;
	}else{
		ret = n+(n-x-1);
	}
	return (ret-t%(2*n)+2*n)%(2*n);
}

long long sum(BIT &bit,int s,int e){
	if(s<=e){
		return bit.sum(s,e);
	}else{
		return bit.sum(2*n-1)-bit.sum(s-1)+bit.sum(e);
	}
}


int main(){
	cin>>n>>q;
	BIT bit(2*n);
	rep(_,q){
		char x;
		int t,y,z;
		cin>>x>>t>>y>>z;
		if(x=='R'){
			int val=code('R',y,t);
			bit.add(val,z);
		}else if(x=='L'){
			int val=code('L',y,t);
			bit.add(val,z);
		}else{
			z=min(z-1,n-1);
			long long ans=0;
			int s,e;
			s=code('R',y,t);
			e=code('R',z,t);
			ans+=sum(bit,s,e);
			s=code('L',z,t);
			e=code('L',y,t);
			ans+=sum(bit,s,e);
			cout<<ans<<endl;
		}
	}
	return 0;
}
0