結果

問題 No.469 区間加算と一致検索の問題
ユーザー Hoi_koroHoi_koro
提出日時 2016-12-19 12:02:27
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 313 ms / 5,000 ms
コード長 1,881 bytes
コンパイル時間 1,217 ms
コンパイル使用メモリ 125,696 KB
実行使用メモリ 67,560 KB
最終ジャッジ日時 2023-08-23 13:25:21
合計ジャッジ時間 9,496 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 16 ms
8,744 KB
testcase_03 AC 6 ms
4,380 KB
testcase_04 AC 6 ms
4,380 KB
testcase_05 AC 7 ms
4,380 KB
testcase_06 AC 9 ms
4,380 KB
testcase_07 AC 9 ms
4,376 KB
testcase_08 AC 10 ms
4,380 KB
testcase_09 AC 5 ms
4,376 KB
testcase_10 AC 6 ms
4,376 KB
testcase_11 AC 4 ms
4,380 KB
testcase_12 AC 11 ms
4,380 KB
testcase_13 AC 6 ms
4,380 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 9 ms
4,384 KB
testcase_17 AC 8 ms
4,376 KB
testcase_18 AC 8 ms
4,384 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 10 ms
4,376 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 61 ms
8,604 KB
testcase_24 AC 62 ms
8,576 KB
testcase_25 AC 61 ms
8,700 KB
testcase_26 AC 61 ms
8,556 KB
testcase_27 AC 62 ms
8,596 KB
testcase_28 AC 62 ms
8,640 KB
testcase_29 AC 62 ms
8,588 KB
testcase_30 AC 61 ms
8,580 KB
testcase_31 AC 61 ms
8,696 KB
testcase_32 AC 61 ms
8,560 KB
testcase_33 AC 308 ms
67,500 KB
testcase_34 AC 307 ms
67,556 KB
testcase_35 AC 311 ms
67,560 KB
testcase_36 AC 310 ms
67,492 KB
testcase_37 AC 313 ms
67,528 KB
testcase_38 AC 286 ms
65,252 KB
testcase_39 AC 284 ms
65,232 KB
testcase_40 AC 288 ms
65,188 KB
testcase_41 AC 286 ms
65,180 KB
testcase_42 AC 285 ms
65,312 KB
testcase_43 AC 293 ms
65,256 KB
testcase_44 AC 285 ms
65,232 KB
testcase_45 AC 283 ms
65,132 KB
testcase_46 AC 286 ms
65,172 KB
testcase_47 AC 288 ms
65,208 KB
testcase_48 AC 1 ms
4,380 KB
testcase_49 AC 1 ms
4,380 KB
testcase_50 AC 283 ms
65,236 KB
testcase_51 AC 288 ms
65,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <tuple>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <complex>
#include <bitset>
#include <numeric>
#include <random>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n) ;++(i))
#define REPN(i,a,n) FOR((i),(a),(a)+(n))
#define FOR(i,a,b) for(int (i)=(a); (i)<(b) ;++(i))
#define PB push_back
#define MP make_pair
#define SE second
#define FI first
#define DBG(a) cerr<<(a)<<endl;
#define dump(a) cerr<<#a <<' '<< a <<endl;
#define ALL(v) (v).begin(),(v).end()
typedef long long LL;  typedef pair<LL, LL> PLL; typedef vector<LL> VLL;
typedef pair<int,int>PI; typedef vector<int> VI;
const LL LINF=334ll<<53; const int INF=15<<26; const LL MOD=1E9+7;



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,q;
    cin >> n >>q;
    vector<VLL> h(n+1,VLL(3));
    map<VLL,int> m;

    LL b[3]={149853437,2345752,564565},p[3]={999999937,MOD,MOD+2};
    h[0]={0,0,0};
    h[1]={1,1,1};
    FOR(i,2,n+1){
        REP(j,3){
            h[i][j]=h[i-1][j]*b[j]%p[j];
        }
    }
    FOR(i,2,n+1){
        REP(j,3){
            h[i][j]=(h[i][j]+h[i-1][j])%p[j];
        }
    }
    VLL st(3);
    m[st]=0;
    REP(i,q){
        char op;cin >>op;
        if(op=='!'){
            int l,r,k;
            cin >> l >> r >> k;
            LL add[3];
            REP(j,3){
                add[j]=(h[n-l][j]-h[n-r][j]+p[j])%p[j];
                st[j]=(st[j]+add[j]*((k+p[j])%p[j]))%p[j];
            }
            if(m.count(st)==0)m[st]=i+1;
        }if(op=='?'){
            cout << m[st] <<endl;
        }
    }

    return 0;
}
0