結果
| 問題 |
No.151 セグメントフィッシング
|
| コンテスト | |
| ユーザー |
shimomire
|
| 提出日時 | 2015-02-10 23:31:27 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 33 ms / 5,000 ms |
| コード長 | 1,890 bytes |
| コンパイル時間 | 1,111 ms |
| コンパイル使用メモリ | 117,412 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-23 18:24:39 |
| 合計ジャッジ時間 | 3,192 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 19 |
ソースコード
#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__ << ")"
ll pmod(ll v,ll M){return (v%M+M)%M;}
template<typename T> class Fenwick{
public:
int size;vector<T> bit;
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 * log(Q+N))
int main(){
cout <<fixed<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
int N,Q;cin >> N >> Q;
Fenwick<ll> fenL(N+Q+1),fenR(N+Q+1);
int wll=0,wlr=N-1,wrl=Q,wrr=Q + N-1;
REP(t,Q){
char x;ll y,z;cin >> x >> y >> z;
if(x=='L') fenL.add(t+y,z);
if(x=='R') fenR.add(Q-t+y,z);
if(x=='C'){
cout << fenL.sum(t + y,t + z) + fenR.sum(Q - t + y,Q-t + z)<<endl;
}
//反転 get
ll lv=fenL.sum(wll,wll+1);fenL.add(wll,-lv);
ll rv=fenR.sum(wrr,wrr+1);fenR.add(wrr,-rv);
//next
wll++;wlr++;
wrl--;wrr--;
//反転 set
fenR.add(wrl,lv);
fenL.add(wlr,rv);
}
return 0;
}
shimomire