結果

問題 No.151 セグメントフィッシング
ユーザー 0w10w1
提出日時 2017-01-02 19:05:36
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 5,000 ms
コード長 2,301 bytes
コンパイル時間 1,693 ms
コンパイル使用メモリ 172,680 KB
実行使用メモリ 7,472 KB
最終ジャッジ日時 2023-08-22 09:29:41
合計ジャッジ時間 3,342 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 6 ms
4,380 KB
testcase_09 AC 7 ms
4,376 KB
testcase_10 AC 7 ms
4,380 KB
testcase_11 AC 7 ms
4,380 KB
testcase_12 AC 22 ms
7,072 KB
testcase_13 AC 22 ms
7,316 KB
testcase_14 AC 22 ms
7,080 KB
testcase_15 AC 22 ms
7,100 KB
testcase_16 AC 22 ms
7,160 KB
testcase_17 AC 11 ms
7,156 KB
testcase_18 AC 12 ms
7,168 KB
testcase_19 AC 37 ms
7,096 KB
testcase_20 AC 37 ms
7,068 KB
testcase_21 AC 14 ms
7,076 KB
testcase_22 AC 13 ms
7,472 KB
testcase_23 AC 19 ms
5,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef pair< int, int > pii;
typedef vector< pii > vp;
typedef vector< double > vd;
typedef vector< vd > vvd;
typedef vector< string > vs;

template< class T1, class T2 >
int upmin( T1 &x, T2 v ){
  if( x > v ){
    x = v;
    return 1;
  }
  return 0;
}

template< class T1, class T2 >
int upmax( T1 &x, T2 v ){
  if( x < v ){
    x = v;
    return 1;
  }
  return 0;
}

const int INF = 0x3f3f3f3f;

int N, Q;
vs X;
vi Y, Z;

void init(){
  cin >> N >> Q;
  X = vs( Q );
  Y = Z = vi( Q );
  for( int i = 0; i < Q; ++i ){
    cin >> X[ i ] >> Y[ i ] >> Z[ i ];
  }
}

struct fenwick{
  vi dat;
  fenwick( int sz ){
    dat = vi( sz );
  }
  void add( int x, int v ){
    for( int i = x; i < dat.size(); i += i & -i ){
      dat[ i ] += v;
    }
  }
  int sum( int x ){
    int res = 0;
    for( int i = x; i > 0; i -= i & -i ){
      res += dat[ i ];
    }
    return res;
  }
} *to_left, *to_right;

void preprocess(){
  const int origin = 2 * ( N + Q );
  to_left = new fenwick( 5 * ( N + Q ) );
  to_right = new fenwick( 5 * ( N + Q ) );
  for( int i = 0; i < Q; ++i ){
    int to_left_lb = origin + i;
    int to_left_rb = origin + N - 1 + i;
    int to_right_lb = origin - i;
    int to_right_rb = origin + N - 1 - i;
    if( to_left->sum( to_left_lb - 1 ) - to_left->sum( to_left_lb - 2 ) ){
      to_right->add( to_right_lb, to_left->sum( to_left_lb - 1 ) - to_left->sum( to_left_lb - 2 ) );
    }
    if( to_right->sum( to_right_rb + 1 ) - to_right->sum( to_right_rb ) ){
      to_left->add( to_left_rb, to_right->sum( to_right_rb + 1 ) - to_right->sum( to_right_rb ) );
    }
    if( X[ i ] == "R" ){
      to_right->add( Y[ i ] + to_right_lb, Z[ i ] );
    } else if( X[ i ] == "L" ){
      to_left->add( Y[ i ] + to_left_lb, Z[ i ] );
    } else{ // X[ i ] == "C"
      cout << to_left->sum( Z[ i ] - 1 + to_left_lb ) - to_left->sum( Y[ i ] - 1 + to_left_lb )
            + to_right->sum( Z[ i ] - 1 + to_right_lb ) - to_right->sum( Y[ i ] - 1 + to_right_lb ) << endl;
    }
  }
}

void solve(){

}

signed main(){
  ios::sync_with_stdio( 0 );
  init();
  preprocess();
  solve();
  return 0;
}
0