結果

問題 No.469 区間加算と一致検索の問題
ユーザー parukiparuki
提出日時 2016-12-19 15:45:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 103 ms / 5,000 ms
コード長 1,460 bytes
コンパイル時間 1,624 ms
コンパイル使用メモリ 175,368 KB
実行使用メモリ 23,528 KB
最終ジャッジ日時 2023-08-23 13:25:48
合計ジャッジ時間 5,910 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 4 ms
4,532 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 AC 4 ms
4,380 KB
testcase_05 AC 5 ms
4,380 KB
testcase_06 AC 5 ms
4,376 KB
testcase_07 AC 5 ms
4,380 KB
testcase_08 AC 6 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 7 ms
4,376 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 6 ms
4,376 KB
testcase_17 AC 5 ms
4,376 KB
testcase_18 AC 5 ms
4,384 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 6 ms
4,380 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 32 ms
5,680 KB
testcase_24 AC 32 ms
5,608 KB
testcase_25 AC 32 ms
5,768 KB
testcase_26 AC 31 ms
5,620 KB
testcase_27 AC 31 ms
5,648 KB
testcase_28 AC 31 ms
5,740 KB
testcase_29 AC 32 ms
5,604 KB
testcase_30 AC 32 ms
5,860 KB
testcase_31 AC 32 ms
5,616 KB
testcase_32 AC 31 ms
5,896 KB
testcase_33 AC 101 ms
23,528 KB
testcase_34 AC 101 ms
23,388 KB
testcase_35 AC 101 ms
23,444 KB
testcase_36 AC 103 ms
23,464 KB
testcase_37 AC 103 ms
23,468 KB
testcase_38 AC 93 ms
21,404 KB
testcase_39 AC 91 ms
21,552 KB
testcase_40 AC 91 ms
21,276 KB
testcase_41 AC 91 ms
21,560 KB
testcase_42 AC 91 ms
21,388 KB
testcase_43 AC 91 ms
21,452 KB
testcase_44 AC 91 ms
21,272 KB
testcase_45 AC 91 ms
21,304 KB
testcase_46 AC 91 ms
21,416 KB
testcase_47 AC 90 ms
21,424 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 2 ms
4,380 KB
testcase_50 AC 87 ms
21,544 KB
testcase_51 AC 94 ms
21,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

const int C = 31, C2 = 29, P = 1000000007, P2 = 1000000009;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    int N, Q;
    cin >> N >> Q;

    vll c1(N+1), c2(N+1);
    c1[1] = c2[1] = 1;
    rep(i, N - 1) {
        c1[i+2] = c1[i+1] * C%P;
        c2[i+2] = c2[i+1] * C2%P2;
    }
    rep(i, N) {
        (c1[i + 1] += c1[i]) %= P;
        (c2[i + 1] += c2[i]) %= P2;
    }

    unordered_map<ll, int> aa;

    ll x1 = 0, x2 = 0;
    rep(i, Q) {
        auto p = x1 * P2 + x2;
        if(!aa.count(p)) {
            aa[p] = i;
        }

        char c; cin >> c;
        if(c == '!') {
            int l, r, y;
            cin >> l >> r >> y;
            ll z1 = (c1[r] - c1[l])*y;
            ll z2 = (c2[r] - c2[l])*y;
            (x1 += z1)%=P;
            (x2 += z2)%=P2;
            if(x1 < 0)x1 += P;
            if(x2 < 0)x2 += P2;
        } else {
            cout << aa[p] << endl;
        }
    }
}
0