結果

問題 No.2359 A in S ?
ユーザー FplusFplusFFplusFplusF
提出日時 2023-06-23 22:20:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,156 bytes
コンパイル時間 2,496 ms
コンパイル使用メモリ 204,936 KB
実行使用メモリ 11,712 KB
最終ジャッジ日時 2023-09-13 17:21:38
合計ジャッジ時間 6,718 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,212 KB
testcase_01 AC 4 ms
7,316 KB
testcase_02 AC 5 ms
7,312 KB
testcase_03 AC 5 ms
7,204 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll,ll>;
using ld=long double;
const ll INF=(1ll<<60);
#define rep(i,n) for (ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(),v.end()
template<class T> void chmin(T &a,T b){
    if(a>b){
        a=b;
    }
}
template<class T> void chmax(T &a,T b){
    if(a<b){
        a=b;
    }
}
struct segment_tree{
    vector<ll> v,lazy;
    ll n;
    segment_tree(ll x){
        ll s=1;
        while(s<x) s*=2;
        n=s;
        v.assign(s*2-1,0);
        lazy.assign(s*2-1,0);
    }
    void eval(ll k,ll l,ll r){
        if(lazy[k]!=0){
            v[k]+=lazy[k];
            if(1<r-l){
                lazy[2*k+1]+=lazy[k]/2;
                lazy[2*k+2]+=lazy[k]/2;
            }
        }
        lazy[k]=0;
    }
    void add(ll a,ll b,ll x){
        add_sub(a,b,x,0ll,0ll,n);
    }
    void add_sub(ll a,ll b,ll x,ll k,ll l, ll r){
        eval(k,l,r);
        if(r<=a||b<=l){
            return;
        }else if(a<=l&&r<=b){
            lazy[k]+=(r-l)*x;
            eval(k,l,r);
            return;
        }else{
            add_sub(a,b,x,k*2+1,l,(l+r)/2);
            add_sub(a,b,x,k*2+2,(l+r)/2,r);
            v[k]=v[k*2+1]+v[k*2+2];
            return;
        }
    }
    ll query(ll a,ll b){
        return query_sub(a,b,0ll,0ll,n);
    }
    ll query_sub(ll a,ll b,ll k,ll l,ll r){
        if(r<=a||b<=l){
            return 0;
        }
        eval(k,l,r);
        if(a<=l&&r<=b){
            return v[k];
        }else{
            ll vl=query_sub(a,b,k*2+1,l,(l+r)/2);
            ll vr=query_sub(a,b,k*2+2,(l+r)/2,r);
            return vl+vr;
        }
    }
};
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n,m;
    cin >> n >> m;
    segment_tree cnt(1e5+1);
    while(n--){
        ll l,r,x,y;
        cin >> l >> r >> x >> y;
        if(x==1){
            cnt.add(l,r+1,1);
            continue;
        }
        ll k=(l/x)*x+y;
        if(k<l) k+=x;
        for(ll i=k;i<=r;i+=x) cnt.add(i,i+1,1);
    }
    while(m--){
        ll a;
        cin >> a;
        cout << cnt.query(a,a+1) << '\n';
    }
}
0