結果

問題 No.469 区間加算と一致検索の問題
ユーザー parukiparuki
提出日時 2016-12-19 01:06:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 128 ms / 5,000 ms
コード長 1,464 bytes
コンパイル時間 1,925 ms
コンパイル使用メモリ 174,972 KB
実行使用メモリ 24,524 KB
最終ジャッジ日時 2023-08-23 13:20:34
合計ジャッジ時間 6,521 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 4 ms
4,640 KB
testcase_03 AC 5 ms
4,376 KB
testcase_04 AC 6 ms
4,380 KB
testcase_05 AC 6 ms
4,380 KB
testcase_06 AC 7 ms
4,384 KB
testcase_07 AC 7 ms
4,380 KB
testcase_08 AC 8 ms
4,380 KB
testcase_09 AC 4 ms
4,376 KB
testcase_10 AC 6 ms
4,380 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 8 ms
4,380 KB
testcase_13 AC 5 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 3 ms
4,384 KB
testcase_16 AC 8 ms
4,380 KB
testcase_17 AC 7 ms
4,380 KB
testcase_18 AC 7 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 8 ms
4,384 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 47 ms
6,360 KB
testcase_24 AC 46 ms
6,352 KB
testcase_25 AC 49 ms
6,016 KB
testcase_26 AC 48 ms
6,124 KB
testcase_27 AC 48 ms
5,932 KB
testcase_28 AC 48 ms
6,252 KB
testcase_29 AC 48 ms
6,264 KB
testcase_30 AC 49 ms
6,180 KB
testcase_31 AC 47 ms
6,296 KB
testcase_32 AC 47 ms
5,980 KB
testcase_33 AC 128 ms
24,260 KB
testcase_34 AC 128 ms
24,248 KB
testcase_35 AC 126 ms
24,296 KB
testcase_36 AC 124 ms
24,524 KB
testcase_37 AC 124 ms
24,392 KB
testcase_38 AC 112 ms
23,088 KB
testcase_39 AC 112 ms
22,748 KB
testcase_40 AC 109 ms
22,748 KB
testcase_41 AC 112 ms
22,900 KB
testcase_42 AC 115 ms
22,952 KB
testcase_43 AC 110 ms
22,796 KB
testcase_44 AC 112 ms
22,944 KB
testcase_45 AC 111 ms
22,892 KB
testcase_46 AC 109 ms
23,032 KB
testcase_47 AC 111 ms
22,744 KB
testcase_48 AC 1 ms
4,380 KB
testcase_49 AC 1 ms
4,376 KB
testcase_50 AC 110 ms
23,004 KB
testcase_51 AC 110 ms
22,888 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;

static 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;
    }

    map<pair<ll,ll>, int> aa;

    ll x1 = 0, x2 = 0;
    rep(i, Q) {
        auto p = mp(x1, 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