結果
| 問題 |
No.151 セグメントフィッシング
|
| コンテスト | |
| ユーザー |
yaoshimax
|
| 提出日時 | 2015-05-01 13:13:33 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,114 bytes |
| コンパイル時間 | 861 ms |
| コンパイル使用メモリ | 88,212 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-05 17:20:16 |
| 合計ジャッジ時間 | 2,585 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 7 WA * 12 |
ソースコード
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
using namespace std;
class BIT{
/*binary indexed tree*/
private:
vector<long long> data;
int size;
public:
BIT(int n): data(n+1,0),size(n){
return;
}
long long sum(int l, int r ){
// return sum in [l+1,r] or (l,r]
return sum_(r)-sum_(l);
}
long long sum_(int i){
// return sum (0, i]
long long ans = 0;
while( 0 < i ){
ans += data[i];
i -= i&-i; // 11010110 -> 1010100
}
return ans;
}
void add(int i, int x){
// add x to i
while( i <= size ){
data[i] += x;
i+= i&-i;
}
return;
}
};
int main(){
int N,Q;
cin >> N >> Q;
int range=2*N;
BIT b(range); //[1,N],[N+1,2*N] note that 2*N=1
for( int i = 1 ; i <= Q; i++){
char c;
int x,y;
cin >> c >> x>>y;
if( c=='R'){
x-=i;
x=(x%(range)+(range))%(range)+1;
//cout << x << endl;
b.add(x,y);
}
if( c=='L'){
x=2*N-1-x;
x-=i;
x=(x%(range)+(range))%(range)+1;
//cout << x << endl;
b.add(x,y);
}
if( c=='C'){
int x1,y1;
x1=x;
y1=y;
x1-=i;
y1-=i;
x1=(x1%(range)+(range))%(range)+1;
y1=(y1%(range)+(range))%(range)+1;
int ans = 0;
if( x1 > y1 ){
ans+=b.sum(x1-1,2*N);
ans+=b.sum(0,y1-1);
}
else{
ans += b.sum(x1-1,y1-1);
}
//cout << x1<<"-"<<y1<<":"<<ans<<endl;
x1=2*N-1-x;
y1=2*N-1-y;
x1-=i;
y1-=i;
x1=(x1%(range)+(range))%(range)+1;
y1=(y1%(range)+(range))%(range)+1;
if( x1 > y1 ){
ans += b.sum(y1,x1);
}
else{
ans+=b.sum(y1,2*N);
ans+=b.sum(0,x1);
}
//cout << x1<<"-"<<y1<<":"<<ans<<endl;
cout << ans<<endl;
}
}
return 0;
}
yaoshimax