結果

問題 No.469 区間加算と一致検索の問題
ユーザー 0w10w1
提出日時 2016-12-19 22:09:11
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 255 ms / 5,000 ms
コード長 1,782 bytes
コンパイル時間 1,733 ms
コンパイル使用メモリ 176,316 KB
実行使用メモリ 25,068 KB
最終ジャッジ日時 2023-08-23 13:27:04
合計ジャッジ時間 8,957 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 8 ms
8,360 KB
testcase_03 AC 6 ms
4,380 KB
testcase_04 AC 7 ms
4,376 KB
testcase_05 AC 8 ms
4,380 KB
testcase_06 AC 10 ms
4,376 KB
testcase_07 AC 10 ms
4,380 KB
testcase_08 AC 11 ms
4,376 KB
testcase_09 AC 5 ms
4,376 KB
testcase_10 AC 7 ms
4,376 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 12 ms
4,456 KB
testcase_13 AC 7 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 5 ms
4,380 KB
testcase_16 AC 10 ms
4,380 KB
testcase_17 AC 9 ms
4,376 KB
testcase_18 AC 9 ms
4,376 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 11 ms
4,380 KB
testcase_21 AC 4 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 66 ms
8,408 KB
testcase_24 AC 66 ms
8,392 KB
testcase_25 AC 67 ms
8,488 KB
testcase_26 AC 66 ms
8,404 KB
testcase_27 AC 68 ms
8,556 KB
testcase_28 AC 66 ms
8,424 KB
testcase_29 AC 69 ms
8,516 KB
testcase_30 AC 69 ms
8,416 KB
testcase_31 AC 67 ms
8,568 KB
testcase_32 AC 71 ms
8,424 KB
testcase_33 AC 254 ms
24,940 KB
testcase_34 AC 247 ms
24,948 KB
testcase_35 AC 253 ms
24,916 KB
testcase_36 AC 248 ms
25,068 KB
testcase_37 AC 255 ms
24,900 KB
testcase_38 AC 228 ms
22,480 KB
testcase_39 AC 227 ms
22,472 KB
testcase_40 AC 227 ms
22,436 KB
testcase_41 AC 231 ms
22,596 KB
testcase_42 AC 228 ms
22,488 KB
testcase_43 AC 231 ms
22,368 KB
testcase_44 AC 232 ms
22,572 KB
testcase_45 AC 226 ms
22,396 KB
testcase_46 AC 225 ms
22,568 KB
testcase_47 AC 234 ms
22,516 KB
testcase_48 AC 2 ms
4,376 KB
testcase_49 AC 1 ms
4,380 KB
testcase_50 AC 229 ms
22,472 KB
testcase_51 AC 227 ms
22,616 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 = 3;
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