結果

問題 No.469 区間加算と一致検索の問題
ユーザー 0w10w1
提出日時 2016-12-19 22:11:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,796 bytes
コンパイル時間 2,092 ms
コンパイル使用メモリ 178,120 KB
実行使用メモリ 17,152 KB
最終ジャッジ日時 2024-05-08 07:02:54
合計ジャッジ時間 7,852 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 4 ms
5,376 KB
testcase_03 AC 7 ms
5,376 KB
testcase_04 AC 7 ms
5,376 KB
testcase_05 AC 8 ms
5,376 KB
testcase_06 AC 9 ms
5,376 KB
testcase_07 AC 10 ms
5,376 KB
testcase_08 AC 11 ms
5,376 KB
testcase_09 AC 5 ms
5,376 KB
testcase_10 AC 7 ms
5,376 KB
testcase_11 AC 4 ms
5,376 KB
testcase_12 AC 11 ms
5,376 KB
testcase_13 AC 7 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 5 ms
5,376 KB
testcase_16 AC 10 ms
5,376 KB
testcase_17 AC 9 ms
5,376 KB
testcase_18 AC 10 ms
5,376 KB
testcase_19 AC 4 ms
5,376 KB
testcase_20 AC 11 ms
5,376 KB
testcase_21 AC 4 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 71 ms
8,448 KB
testcase_24 AC 71 ms
8,320 KB
testcase_25 AC 75 ms
8,320 KB
testcase_26 AC 77 ms
8,448 KB
testcase_27 AC 74 ms
8,320 KB
testcase_28 AC 72 ms
8,576 KB
testcase_29 AC 74 ms
8,448 KB
testcase_30 AC 72 ms
8,448 KB
testcase_31 AC 72 ms
8,448 KB
testcase_32 AC 69 ms
8,448 KB
testcase_33 AC 206 ms
17,152 KB
testcase_34 AC 198 ms
17,024 KB
testcase_35 WA -
testcase_36 AC 197 ms
17,024 KB
testcase_37 AC 194 ms
17,152 KB
testcase_38 AC 173 ms
14,592 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 174 ms
14,592 KB
testcase_42 AC 175 ms
14,592 KB
testcase_43 AC 172 ms
14,720 KB
testcase_44 AC 180 ms
14,720 KB
testcase_45 AC 179 ms
14,720 KB
testcase_46 WA -
testcase_47 AC 173 ms
14,720 KB
testcase_48 AC 2 ms
5,376 KB
testcase_49 AC 2 ms
5,376 KB
testcase_50 AC 173 ms
14,592 KB
testcase_51 AC 178 ms
14,592 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 ] = { 10007 }; // , 10007, 10009 };
int base_psum[ HASH_T ][ MAXN + 1 ];
int mod[ HASH_T ] = { ( int ) 1e9 + 9 }; // , ( 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