結果

問題 No.449 ゆきこーだーの雨と雪 (4)
ユーザー 0w10w1
提出日時 2017-01-04 17:21:45
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 409 ms / 5,000 ms
コード長 2,534 bytes
コンパイル時間 2,366 ms
コンパイル使用メモリ 197,528 KB
実行使用メモリ 32,632 KB
最終ジャッジ日時 2023-10-23 16:06:13
合計ジャッジ時間 14,200 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 3 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 4 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 3 ms
4,348 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 219 ms
14,828 KB
testcase_13 AC 309 ms
18,452 KB
testcase_14 AC 295 ms
16,584 KB
testcase_15 AC 309 ms
19,340 KB
testcase_16 AC 298 ms
17,380 KB
testcase_17 AC 302 ms
17,436 KB
testcase_18 AC 222 ms
14,544 KB
testcase_19 AC 289 ms
16,536 KB
testcase_20 AC 290 ms
16,520 KB
testcase_21 AC 304 ms
18,400 KB
testcase_22 AC 309 ms
18,464 KB
testcase_23 AC 217 ms
14,532 KB
testcase_24 AC 309 ms
17,436 KB
testcase_25 AC 214 ms
13,296 KB
testcase_26 AC 210 ms
11,836 KB
testcase_27 AC 303 ms
18,400 KB
testcase_28 AC 305 ms
18,428 KB
testcase_29 AC 283 ms
16,532 KB
testcase_30 AC 308 ms
19,348 KB
testcase_31 AC 307 ms
18,460 KB
testcase_32 AC 300 ms
16,580 KB
testcase_33 AC 309 ms
17,472 KB
testcase_34 AC 218 ms
13,332 KB
testcase_35 AC 315 ms
19,392 KB
testcase_36 AC 224 ms
13,348 KB
testcase_37 AC 409 ms
32,632 KB
testcase_38 AC 306 ms
23,512 KB
testcase_39 AC 257 ms
23,512 KB
testcase_40 AC 252 ms
23,512 KB
testcase_41 AC 331 ms
27,236 KB
testcase_42 AC 331 ms
27,236 KB
testcase_43 AC 185 ms
18,216 KB
testcase_44 AC 177 ms
21,252 KB
testcase_45 AC 215 ms
32,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

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;
vi L;
int T;
vs name, P;


void init(){
  cin >> N;
  L = vi( N );
  for( int i = 0; i < N; ++i ){
    cin >> L[ i ];
  }
  cin >> T;
  name = P = vs( T );
  for( int i = 0; i < T; ++i ){
    cin >> name[ i ] >> P[ i ];
  }
}

vp vis_scr_clk;
map< pii, int > mp;

struct fenwick{
  vi dat;
  fenwick( int sz ){
    dat = vi( sz );
  }
  void update( 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;
  }
} *ftree;

void preprocess(){
  vi prob_ac_cnt( N );
  map< string, pii > user2scr_clk;
  vis_scr_clk.emplace_back( 0, 0 );
  for( int i = 0; i < T; ++i ){
    if( P[ i ][ 0 ] == '?' ) continue;
    int p = P[ i ][ 0 ] - 'A';
    pii v = user2scr_clk[ name[ i ] ];
    v.first += 50 * L[ p ] + 500 * L[ p ] / ( 8 + 2 * ++prob_ac_cnt[ p ] );
    v.second = -i;
    user2scr_clk[ name[ i ] ] = v;
    vis_scr_clk.emplace_back( v );
  }
  sort( vis_scr_clk.begin(), vis_scr_clk.end() );
  vis_scr_clk.erase( unique( vis_scr_clk.begin(), vis_scr_clk.end() ), vis_scr_clk.end() );
  for( int i = 0; i < vis_scr_clk.size(); ++i ){
    mp[ vis_scr_clk[ i ] ] = i + 1;
  }
  ftree = new fenwick( vis_scr_clk.size() + 1 );
}

void solve(){
  vi prob_ac_cnt( N );
  map< string, pii > user2scr_clk;
  for( int i = 0; i < T; ++i ){
    if( P[ i ][ 0 ] == '?' ){
      pii v = user2scr_clk[ name[ i ] ];
      cout << ftree->sum( vis_scr_clk.size() ) - ftree->sum( mp[ v ] ) + 1 << endl;
    } else{
      int p = P[ i ][ 0 ] - 'A';
      pii v = user2scr_clk[ name[ i ] ];
      ftree->update( mp[ v ], -1 );
      v.first += 50 * L[ p ] + 500 * L[ p ] / ( 8 + 2 * ++prob_ac_cnt[ p ] );
      v.second = -i;
      user2scr_clk[ name[ i ] ] = v;
      ftree->update( mp[ v ], 1 );
    }
  }
}

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