結果

問題 No.259 セグメントフィッシング+
ユーザー chocoruskchocorusk
提出日時 2019-12-31 15:13:51
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 128 ms / 2,000 ms
コード長 1,650 bytes
コンパイル時間 1,108 ms
コンパイル使用メモリ 111,384 KB
実行使用メモリ 6,328 KB
最終ジャッジ日時 2023-08-12 02:53:08
合計ジャッジ時間 6,665 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 116 ms
6,308 KB
testcase_09 AC 116 ms
6,156 KB
testcase_10 AC 118 ms
6,176 KB
testcase_11 AC 116 ms
6,204 KB
testcase_12 AC 118 ms
6,208 KB
testcase_13 AC 127 ms
6,120 KB
testcase_14 AC 128 ms
6,328 KB
testcase_15 AC 128 ms
6,260 KB
testcase_16 AC 127 ms
6,184 KB
testcase_17 AC 125 ms
6,060 KB
testcase_18 AC 126 ms
6,228 KB
testcase_19 AC 127 ms
6,244 KB
testcase_20 AC 128 ms
6,308 KB
testcase_21 AC 127 ms
6,268 KB
testcase_22 AC 128 ms
6,172 KB
testcase_23 AC 75 ms
4,376 KB
testcase_24 AC 93 ms
6,244 KB
testcase_25 AC 95 ms
6,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<typename T>
struct BIT{ //1-indexed
    vector<T> bit;
    int size;
    BIT(int n):size(n), bit(n+1, 0){}
    T sum(int i){
        T s=0;
        while(i>0){
            s+=bit[i];
            i-=(i&(-i));
        }
        return s;
    }
	T sum(int l, int r){
		return sum(r-1)-sum(l-1);
	}
    void add(int i, T x){
        while(i<=size){
            bit[i]+=x;
            i+=(i&(-i));
        }
    }
};
int main()
{
	int n, q;
	cin>>n>>q;
	BIT<ll> bit(2*n);
	for(int i=0; i<q; i++){
		char x;
		int t, y, z;
		cin>>x>>t>>y>>z;
		if(x=='L'){
			bit.add((n-1-y+n-t%(2*n)+2*n)%(2*n)+1, z);
		}else if(x=='R'){
			bit.add((y-t%(2*n)+2*n)%(2*n)+1, z);
		}else{
			ll ans=0;
			int y1=(y-t%(2*n)+2*n)%(2*n), z1=(z-t%(2*n)+2*n)%(2*n);
			if(y1>z1){
				ans+=bit.sum(y1+1, 2*n+1);
				ans+=bit.sum(z1);
			}else{
				ans+=bit.sum(y1+1, z1+1);
			}
			y=n-1-y, z=n-z;
			swap(y, z);
			z++;
			y1=(y+n-t%(2*n)+2*n)%(2*n), z1=(z+n-t%(2*n)+2*n)%(2*n);
			if(y1>z1){
				ans+=bit.sum(y1+1, 2*n+1);
				ans+=bit.sum(z1);
			}else{
				ans+=bit.sum(y1+1, z1+1);
			}
			cout<<ans<<endl;
		}
	}
	return 0;
}
0