結果

問題 No.469 区間加算と一致検索の問題
ユーザー koprickykopricky
提出日時 2018-04-25 01:24:31
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 3,768 bytes
コンパイル時間 3,147 ms
コンパイル使用メモリ 178,164 KB
実行使用メモリ 41,752 KB
最終ジャッジ日時 2023-09-10 05:13:40
合計ジャッジ時間 11,569 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 7 ms
7,352 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 AC 2 ms
4,384 KB
testcase_50 WA -
testcase_51 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

ll ad(ll x,ll y)
{
    return (x + y)%MOD;
}

class segtree{
private:
    int n,sz,cnt;
    vector<ll> node[2];
    ll mul[2][21];
    const ll add[2] = {1000010007, 1003333331};
    const ll mod[2] = {1000000007, 1000000009};
public:
    segtree(int ag){
        sz = ag;
        n = 1;
        cnt = 0;
        while(n < sz){
            cnt++;
            n *= 2;
        }
        mul[0][0] = mul[1][0] = 1;
        ll rr[2] = {10009+(((ll)&mul[0][0])>>5)%259, 10007+(((ll)&mul[1][0])>>5)%257};
        rep(i,2){
            rep(j,cnt){
                mul[i][j+1] = (mul[i][j] * rr[i]) % MOD;
            }
        }
        rep(i,2){
            node[i].resize(2*n-1);
        }
        rep(i,2){
            rep(j,sz){
                node[i][j+n-1] = add[i];
            }
        }
        rep(i,2){
            init(i,0,0);
        }
    }
    void init(int id, int index, int depth)
    {
        if(depth == cnt) return;
        init(id,2*index+1,depth+1);
        init(id,2*index+2,depth+1);
        node[id][index] = ad(mul[id][cnt-depth]*node[id][2*index+1]%MOD,node[id][2*index+2]);
    }
    void update(int k,ll a){
        a = (a+MOD)%MOD;
        int h = 1;
    	node[0][k] = ad(node[0][k],a), node[1][k] = ad(node[1][k],a);
    	while(k>0){
    		k = (k-1)/2;
            rep(i,2){
                node[i][k] = ad(mul[i][h++]*node[i][2*k+1]%MOD,node[i][2*k+2]);
            }
    	}
    }
    pll query(int a,int b,int dep=0,int k=0,int l=0,int r=-1){
        if(r < 0) r = n;
    	if(r <= a || b <= l){
    		return pll(0,0);
    	}
    	if(a <= l && r <= b){
    		return pll(node[0][k],node[1][k]);
    	}else{
    		pll vl = query(a,b,dep+1,2*k+1,l,(l+r)/2);
    		pll vr = query(a,b,dep+1,2*k+2,(l+r)/2,r);
    		return pll(ad(mul[0][cnt-dep]*vl.fi%MOD,vr.fi),ad(mul[1][cnt-dep]*vl.se%MOD,vr.se));
    	}
    }
};

map<pll,int> mp;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,q;
    cin >> n >> q;
    segtree sg(n);
    mp[sg.query(0, n)] = 0;
    rep(i,q){
        string s;
        cin >> s;
        if(s == "!"){
            int a,b,c;
            cin >> a >> b >> c;
            sg.update(a,c);
            sg.update(b-1,-c);
            auto res = sg.query(0, n);
            if(mp.find(res) == mp.end()){
                mp[res] = i+1;
            }
        }else{
            cout << mp[sg.query(0, n)] << "\n";
        }
    }
    return 0;
}
0