結果

問題 No.2359 A in S ?
ユーザー FplusFplusFFplusFplusF
提出日時 2023-06-23 22:20:41
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 2,156 bytes
コンパイル時間 2,163 ms
コンパイル使用メモリ 199,368 KB
最終ジャッジ日時 2025-02-15 01:12:33
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 2 TLE * 1 -- * 15
権限があれば一括ダウンロードができます

ソースコード

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