結果

問題 No.151 セグメントフィッシング
ユーザー omuomu
提出日時 2015-04-07 13:22:13
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,354 bytes
コンパイル時間 628 ms
コンパイル使用メモリ 88,916 KB
実行使用メモリ 10,928 KB
最終ジャッジ日時 2023-09-17 06:36:59
合計ジャッジ時間 2,086 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,212 KB
testcase_01 AC 4 ms
8,236 KB
testcase_02 AC 3 ms
8,420 KB
testcase_03 AC 3 ms
8,376 KB
testcase_04 AC 3 ms
8,284 KB
testcase_05 AC 4 ms
8,264 KB
testcase_06 AC 3 ms
8,416 KB
testcase_07 AC 3 ms
8,188 KB
testcase_08 AC 8 ms
8,320 KB
testcase_09 AC 9 ms
8,344 KB
testcase_10 AC 9 ms
8,340 KB
testcase_11 AC 9 ms
8,320 KB
testcase_12 AC 29 ms
10,704 KB
testcase_13 AC 30 ms
10,800 KB
testcase_14 AC 28 ms
10,716 KB
testcase_15 AC 28 ms
10,708 KB
testcase_16 AC 29 ms
10,928 KB
testcase_17 AC 18 ms
10,732 KB
testcase_18 AC 20 ms
10,716 KB
testcase_19 AC 44 ms
10,796 KB
testcase_20 AC 44 ms
10,716 KB
testcase_21 AC 21 ms
10,700 KB
testcase_22 AC 21 ms
10,796 KB
testcase_23 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <list>
#include <iomanip>
#include <fstream>

using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }
typedef pair<int, int> P;
typedef long long ll;
typedef unsigned long long ull;

#define rep(i,n)  for(int (i) = 0;(i) < (n);(i)++)
#define clr(a) memset((a), 0 ,sizeof(a))
#define mclr(a) memset((a), -1 ,sizeof(a))
#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) (sizeof(a))
#define Fill(a,v) fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)
bool cheak(int x, int y, int xMax, int yMax){ return x >= 0 && y >= 0 && xMax > x && yMax > y; }
const int dx[4] = { -1, 0, 1, 0 }, dy[4] = { 0, 1, 0, -1 };
const int mod = 1000000007;
const int INF = 2147483647;

struct BIT{
	int n;
	ll bit[1000010];
	void init(int n){
		n += 100000;
		this->n = n;
		for (int x = 1; x < n; ++x)bit[x + (x & -x)] += bit[x];
	}

	void add(int a, ll w){
		a += 100000;
		for (int x = a; x <= n; x += x & -x) bit[x] += w;
	}
	ll sum(int a){
		a += 100000;
		ll ret = 0;
		for (int x = a; x > 0; x -= x & -x)ret += bit[x];
		return ret;
	}
};

BIT r, l;

int main()
{
	int n , q;
	cin >> n >> q;
	r.init(n*3), l.init(n*3);
	
	rep(t, q){


		char x;
		int y,z;
		cin >> x >> y >> z;
		if (x == 'L'){
			l.add(y+1+t,z);
		}else
		if (x == 'R'){
			r.add(y+1-t,z);
		}
		if(x == 'C'){
			ll sum = r.sum(z-t)-r.sum(y-t)+l.sum(z+t)-l.sum(y+t);
			if (z  == n)sum += l.sum(n+1+t)-l.sum(n+t);
			if (y+1== 1)sum += r.sum(0-t);
			cout << sum << endl;
		}

		ll ls = l.sum(1 + t);
		ll rs = r.sum(n - t) - r.sum(n - t - 1);
		l.add(1 + t, -ls);
		r.add(n - t, -rs);
		l.add(n + t + 1, rs);
		r.add(1 - t - 1, ls);
		/*
		for (int i = 1; i < n + 1; i++){
			z = i; y = i - 1;
			int sum = r.sum(z - t) - r.sum(y - t) + l.sum(z + t) - l.sum(y + t);
			if (z  == n)sum += l.sum(n + 1 + t) - l.sum(n + t);
			if (y  == 0)sum += r.sum(0 - t); 
			cout << i - 1 << " " << sum << endl;
		}
		*/
	}
	return 0;
}
0