結果

問題 No.151 セグメントフィッシング
ユーザー shimomireshimomire
提出日時 2015-02-10 23:35:00
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,976 bytes
コンパイル時間 900 ms
コンパイル使用メモリ 113,096 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 23:05:57
合計ジャッジ時間 12,397 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cassert>// c
#include <iostream>// io
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>// container
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <algorithm>// other
#include <complex>
#include <numeric>
#include <functional>
#include <random>
#include <regex>
using namespace std;

using ll =long long;

#define ALL(c) (begin(c)),(end(c))
#define REP(i,n) FOR(i,0,n)
#define REPr(i,n) FORr(i,0,n)
#define FOR(i,l,r) for(int i=(int)(l);i<(int)(r);++i)
#define FORr(i,l,r) for(int i=(int)(r)-1;i>=(int)(l);--i)
#define EACH(it,o) for(auto it = (o).begin(); it != (o).end(); ++it)
#define IN(l,v,r) ((l)<=(v) && (v)<(r))
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end())
//debug
#define DUMP(x)  cerr << #x << " = " << (x)
#define LINE()    cerr<< " (L" << __LINE__ << ")"

template<typename T> class Fenwick{
public:
	int size;vector<T> bit;
	Fenwick():Fenwick(0){}
	Fenwick(int n):size(n){bit = vector<T>(n+1);}
	T sum(int n){// [0,n)
		T s=0;
		while(n>0){
			s+=bit[n];
			n-=n&-n;//low
		}
		return s;
	}
	void add(int i,T x){//[0,...i...,n)
		i++;
		while(i<=size){
			bit[i]+=x;
			i+=i & -i;//next
		}
	}
	T sum(int a,int b){// [a,b)
		return sum(b)-sum(a);
	}
};
//O(Q * NlogN)
class Main{
	public:
	void run(){
		int N,Q;cin >> N >> Q;

		Fenwick<ll> fenL(N),fenR(N);
		REP(q,Q){
			char x;ll y,z;cin >> x >> y >> z;
			if(x=='L')fenL.add(y,z);
			if(x=='R')fenR.add(y,z);
			if(x=='C'){
				cout << fenL.sum(y,z) + fenR.sum(y,z)<<endl;
			}

			//shift
			ll lv=fenL.sum(0,1);fenL.add(0,-lv);
			for(int i=1;i<N;i++){
				ll v=fenL.sum(i,i+1);fenL.add(i-1,v);fenL.add(i,-v);
			}
			//shift
			ll rv=fenR.sum(N-1,N);fenR.add(N-1,-rv);
			for(int i=N-2;i>=0;i--){
				ll v=fenR.sum(i,i+1);fenR.add(i+1,v);fenR.add(i,-v);
			}
			fenR.add(0,lv);fenL.add(N-1,rv);
		}
	}
};

int main(){
	cout <<fixed<<setprecision(20);
	cin.tie(0);
	ios::sync_with_stdio(false);
	Main().run();
	return 0;
}
0