結果

問題 No.469 区間加算と一致検索の問題
ユーザー chocoruskchocorusk
提出日時 2019-07-10 05:32:10
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 581 ms / 5,000 ms
コード長 1,648 bytes
コンパイル時間 1,031 ms
コンパイル使用メモリ 107,104 KB
実行使用メモリ 19,712 KB
最終ジャッジ日時 2024-04-21 09:36:12
合計ジャッジ時間 14,340 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,272 KB
testcase_01 AC 4 ms
6,272 KB
testcase_02 AC 13 ms
7,040 KB
testcase_03 AC 14 ms
6,400 KB
testcase_04 AC 16 ms
6,656 KB
testcase_05 AC 19 ms
6,656 KB
testcase_06 AC 21 ms
6,784 KB
testcase_07 AC 23 ms
6,784 KB
testcase_08 AC 26 ms
6,784 KB
testcase_09 AC 11 ms
6,400 KB
testcase_10 AC 16 ms
6,400 KB
testcase_11 AC 9 ms
6,400 KB
testcase_12 AC 28 ms
6,656 KB
testcase_13 AC 17 ms
6,656 KB
testcase_14 AC 7 ms
6,400 KB
testcase_15 AC 10 ms
6,400 KB
testcase_16 AC 24 ms
6,784 KB
testcase_17 AC 21 ms
6,656 KB
testcase_18 AC 21 ms
6,784 KB
testcase_19 AC 6 ms
6,400 KB
testcase_20 AC 27 ms
6,784 KB
testcase_21 AC 8 ms
6,272 KB
testcase_22 AC 4 ms
6,400 KB
testcase_23 AC 165 ms
9,216 KB
testcase_24 AC 173 ms
8,960 KB
testcase_25 AC 167 ms
9,216 KB
testcase_26 AC 171 ms
9,088 KB
testcase_27 AC 172 ms
9,216 KB
testcase_28 AC 166 ms
9,216 KB
testcase_29 AC 169 ms
9,216 KB
testcase_30 AC 173 ms
9,216 KB
testcase_31 AC 161 ms
9,088 KB
testcase_32 AC 177 ms
9,216 KB
testcase_33 AC 575 ms
19,640 KB
testcase_34 AC 581 ms
19,548 KB
testcase_35 AC 567 ms
19,664 KB
testcase_36 AC 563 ms
19,712 KB
testcase_37 AC 569 ms
19,648 KB
testcase_38 AC 469 ms
18,304 KB
testcase_39 AC 466 ms
18,144 KB
testcase_40 AC 471 ms
18,176 KB
testcase_41 AC 459 ms
18,176 KB
testcase_42 AC 471 ms
18,180 KB
testcase_43 AC 480 ms
18,244 KB
testcase_44 AC 470 ms
18,176 KB
testcase_45 AC 463 ms
18,260 KB
testcase_46 AC 465 ms
18,304 KB
testcase_47 AC 462 ms
18,344 KB
testcase_48 AC 4 ms
6,272 KB
testcase_49 AC 3 ms
6,272 KB
testcase_50 AC 457 ms
18,304 KB
testcase_51 AC 473 ms
18,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
ll mod[3]={1000000007, 1000000009, 998244353};
ll b0[2]={314159265, 358979323};
ll powmod(ll a, ll k, ll MOD){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a, ll MOD){
	return powmod(a, MOD-2, MOD);
}
int n;
ll p[1000010];
int main()
{
    int q; cin>>n>>q;
    char c[100010];
    ll l[100010], r[100010], k[100010];
    for(int i=1; i<=q; i++){
        cin>>c[i];
        if(c[i]=='!') cin>>l[i]>>r[i]>>k[i];
    }
    int ans[100010]={};
    for(int t=0; t<6; t++){
        ll b=b0[t%2], MOD=mod[t%3];
        ll bv=inv(b-1, MOD);
        p[0]=1;
        for(int i=1; i<n; i++) p[i]=p[i-1]*b%MOD;
        ll s=0;
        map<ll, int> mp;
        mp[0]=0;
        for(int i=1; i<=q; i++){
            if(c[i]=='!'){
                (s+=(k[i]+MOD)*(p[r[i]]-p[l[i]]+MOD)%MOD*bv)%=MOD;
                if(mp.find(s)==mp.end()){
                    mp[s]=i;
                }
            }else{
                ans[i]=max(ans[i], mp[s]);
            }
        }
    }
    for(int i=1; i<=q; i++){
        if(c[i]=='?') cout<<ans[i]<<endl;
    }
    return 0;
}
0