結果

問題 No.259 セグメントフィッシング+
ユーザー Kmcode1Kmcode1
提出日時 2015-07-31 23:19:31
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,149 bytes
コンパイル時間 1,872 ms
コンパイル使用メモリ 97,700 KB
実行使用メモリ 6,940 KB
最終ジャッジ日時 2023-09-24 23:03:07
合計ジャッジ時間 3,154 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,800 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 4 ms
6,576 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<complex>
#include<functional>
#include<climits>
#include<cassert>
#include<iterator>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define MAX 200002
int n;
int q;
char buf[3];
pair<int, int> mo(long long int t, long long int ich,bool x){  //false left,true right
	if (x){
		t %= n;
		ich -= t;
		if (ich < 0){
			ich++;
			x ^= 1;
		}
		ich = abs(ich);
	}
	else{
		t %= n;
		ich += t;
		if (ich >= n){
			ich -= n;
			ich = n - 1 - ich;
			x ^= 1;
		}
	}
	return make_pair(ich, x);
}
pair<int, int> kari;
struct BIT{
	long long int bit[MAX];
	BIT(){
		for (int i = 0; i < MAX; i++){
			bit[i] = 0;
		}
	}
	void add(int i, long long int x){
		i++;
		while (i < MAX){
			bit[i] += x;
			i += i&-i;
		}
	}
	long long int sum(int i){
		long long int r = 0;
		i++;
		while (i){
			r += bit[i];
			i -= i&-i;
		}
		return r;
	}
	long long int q(int a, int b){
		return sum(b) - sum(a - 1);
	}
};
BIT B[2];
void ins(int a, int b, int c){
	B[b].add(a, c);
}
int main(){
	scanf("%d%d", &n, &q);
	while (q--){
		scanf("%s", buf);
		int t, y, z;
		scanf("%d%d%d", &t, &y, &z);
		if (buf[0] == 'L'){
			kari = mo(t, y, false);
			ins(kari.first, kari.second, z);
			continue;
		}
		if (buf[0] == 'R'){
			kari = mo(t, y, true);
			ins(kari.first, kari.second, z);
			continue;
		}
		long long int ans = 0;
		t %= n;
		{
			int l = y;
			int r = z;
			l -= t;
			if (l < 0){
				l++;
				l = abs(l);
			}
			r -= t;
			if (r < 0){
				r++;
				r = abs(r);
			}
			if (l > r){
				swap(l, r);
			}
			ans += B[1].q(l, r-1);
		}
		{
			int l = y;
			int r = z;
			l += t;
			r += t;
			if (l >= n){
				l -= n;
				l = n - 1 - l;
			}
			if (r >= n){
				r -= n ;
				r = n - 1 - r;
			}
			if (l > r){
				swap(l, r);
			}
			ans += B[0].q(l, r-1);
		}
		printf("%lld\n", ans);
	}
	return 0;
}
0