結果

問題 No.151 セグメントフィッシング
ユーザー omuomu
提出日時 2015-04-07 14:09:09
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 2,379 bytes
コンパイル時間 692 ms
コンパイル使用メモリ 89,396 KB
実行使用メモリ 784,868 KB
最終ジャッジ日時 2023-09-17 15:41:56
合計ジャッジ時間 17,093 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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[50000000];
	void init(){
		this->n = 50000000;
		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