結果

問題 No.151 セグメントフィッシング
ユーザー omuomu
提出日時 2015-04-07 14:11:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 136 ms / 5,000 ms
コード長 2,379 bytes
コンパイル時間 1,653 ms
コンパイル使用メモリ 88,212 KB
実行使用メモリ 159,840 KB
最終ジャッジ日時 2023-09-17 15:42:02
合計ジャッジ時間 5,672 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
159,540 KB
testcase_01 AC 85 ms
159,700 KB
testcase_02 AC 92 ms
159,660 KB
testcase_03 AC 87 ms
159,600 KB
testcase_04 AC 87 ms
159,608 KB
testcase_05 AC 90 ms
159,840 KB
testcase_06 AC 85 ms
159,612 KB
testcase_07 AC 88 ms
159,612 KB
testcase_08 AC 95 ms
159,612 KB
testcase_09 AC 95 ms
159,548 KB
testcase_10 AC 95 ms
159,660 KB
testcase_11 AC 94 ms
159,604 KB
testcase_12 AC 120 ms
159,704 KB
testcase_13 AC 122 ms
159,608 KB
testcase_14 AC 117 ms
159,724 KB
testcase_15 AC 119 ms
159,652 KB
testcase_16 AC 118 ms
159,656 KB
testcase_17 AC 106 ms
159,776 KB
testcase_18 AC 112 ms
159,544 KB
testcase_19 AC 136 ms
159,624 KB
testcase_20 AC 135 ms
159,616 KB
testcase_21 AC 110 ms
159,612 KB
testcase_22 AC 109 ms
159,776 KB
testcase_23 AC 114 ms
159,540 KB
権限があれば一括ダウンロードができます

ソースコード

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[10000000];
	void init(){
		this->n = 10000000;
		for (int x = 1; x < n; ++x){
			if (x + (x & -x) < n && x < n)
			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(), l.init();
	
	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