結果

問題 No.469 区間加算と一致検索の問題
ユーザー 0w10w1
提出日時 2016-12-19 22:10:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,796 bytes
コンパイル時間 1,652 ms
コンパイル使用メモリ 175,596 KB
実行使用メモリ 17,328 KB
最終ジャッジ日時 2023-08-21 01:19:56
合計ジャッジ時間 7,520 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 3 ms
4,384 KB
testcase_03 AC 6 ms
4,380 KB
testcase_04 AC 7 ms
4,380 KB
testcase_05 AC 8 ms
4,376 KB
testcase_06 AC 9 ms
4,376 KB
testcase_07 AC 9 ms
4,376 KB
testcase_08 AC 11 ms
4,380 KB
testcase_09 AC 5 ms
4,380 KB
testcase_10 AC 7 ms
4,376 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 11 ms
4,376 KB
testcase_13 AC 7 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 10 ms
4,380 KB
testcase_17 AC 8 ms
4,380 KB
testcase_18 AC 9 ms
4,376 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 11 ms
4,376 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 61 ms
8,332 KB
testcase_24 AC 59 ms
8,260 KB
testcase_25 AC 58 ms
8,304 KB
testcase_26 AC 58 ms
8,300 KB
testcase_27 AC 57 ms
8,424 KB
testcase_28 AC 58 ms
8,348 KB
testcase_29 AC 58 ms
8,300 KB
testcase_30 WA -
testcase_31 AC 58 ms
8,284 KB
testcase_32 AC 57 ms
8,528 KB
testcase_33 AC 160 ms
17,328 KB
testcase_34 WA -
testcase_35 AC 169 ms
17,044 KB
testcase_36 AC 164 ms
17,064 KB
testcase_37 AC 162 ms
17,064 KB
testcase_38 AC 148 ms
14,588 KB
testcase_39 AC 144 ms
14,644 KB
testcase_40 AC 151 ms
14,620 KB
testcase_41 AC 144 ms
14,728 KB
testcase_42 AC 151 ms
14,560 KB
testcase_43 AC 146 ms
14,640 KB
testcase_44 AC 151 ms
14,624 KB
testcase_45 WA -
testcase_46 AC 149 ms
14,564 KB
testcase_47 AC 147 ms
14,624 KB
testcase_48 AC 1 ms
4,380 KB
testcase_49 AC 1 ms
4,376 KB
testcase_50 AC 145 ms
14,568 KB
testcase_51 AC 153 ms
14,604 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, Q;

void init(){
  cin >> N >> Q;
}

const int HASH_T = 1;
const int MAXN = ( int ) 1e6;

int base[ HASH_T ] = { 10003 }; // , 10007, 10009 };
int base_psum[ HASH_T ][ MAXN + 1 ];
int mod[ HASH_T ] = { ( int ) 1e9 + 7 }; // , ( int ) 1e9 + 9, 1114111 };

void preprocess(){
  for( int t = 0; t < HASH_T; ++t ){
    int cb = 1;
    for( int i = 0; i < N; ++i ){
      base_psum[ t ][ i + 1 ] = ( base_psum[ t ][ i ] + cb ) % mod[ t ];
      cb = 1LL * cb * base[ t ] % mod[ t ];
    }
  }
}

void solve(){
  map< vi, int > earliest;
  vi chv( HASH_T ); // current hash values
  earliest[ chv ] = 0;
  for( int i = 0; i < Q; ++i ){
    string op; cin >> op;
    if( op == "!" ){
      int L, R, K; cin >> L >> R >> K;
      for( int t = 0; t < HASH_T; ++t ){
        int diff = ( base_psum[ t ][ R ] - base_psum[ t ][ L ] ) % mod[ t ];
        diff = 1LL * diff * K % mod[ t ];
        ( chv[ t ] += diff ) %= mod[ t ];
        if( chv[ t ] < 0 )
          chv[ t ] += mod[ t ];
      }
      if( not earliest.count( chv ) )
        earliest[ chv ] = i + 1;
    } else{
      cout << earliest[ chv ] << endl;
    }
  }
}

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