結果

問題 No.2735 Demarcation
ユーザー FplusFplusFFplusFplusF
提出日時 2024-04-10 15:48:54
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 4,250 bytes
コンパイル時間 4,041 ms
コンパイル使用メモリ 310,096 KB
実行使用メモリ 60,660 KB
最終ジャッジ日時 2024-04-19 19:40:40
合計ジャッジ時間 15,283 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
13,880 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 62 ms
19,004 KB
testcase_05 AC 508 ms
9,500 KB
testcase_06 AC 435 ms
22,076 KB
testcase_07 TLE -
testcase_08 AC 1,276 ms
18,760 KB
testcase_09 AC 746 ms
18,484 KB
testcase_10 AC 790 ms
33,536 KB
testcase_11 AC 67 ms
6,944 KB
testcase_12 AC 425 ms
6,944 KB
testcase_13 AC 1,104 ms
6,944 KB
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

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> inline bool chmin(T &a,T b){
    if(a>b){
        a=b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T &a,T b){
    if(a<b){
        a=b;
        return true;
    }
    return false;
}
template<class T> struct fenwick_tree{
    vector<T> v;
    int n;
    fenwick_tree(int x){
        n=x+1;
        v.assign(n+1,0);
    }
    fenwick_tree(vector<T> &a){
        n=(int)a.size()+1;
        v.assign(n+1,0);
        if((int)a.size()==0) return;
        v[1]=a[0];
        for(int i=0;i<n-2;i++) v[i+2]=a[i+1]-a[i];
        for(int idx=1;idx<=n;idx++){
            if(n<idx+(idx&(-idx))) continue;
            v[idx+(idx&(-idx))]+=v[idx];
        }
    }
    void add_sub(int i,T x){
        i++;
        for(int idx=i;idx<=n;idx+=(idx&(-idx))){
            v[idx]+=x;
        }
    }
    void add(int l,int r,T x){  //[l,r)
        assert(0<=l&&l<=n);
        assert(0<=r&&r<=n);
        assert(l<=r);
        add_sub(l,x);
        add_sub(r,-x);
    }
    T get(int i){
        assert(0<=i&&i<n);
        i++;
        T ret=0;
        for(int idx=i;0<idx;idx-=(idx&(-idx))){
            ret+=v[idx];
        }
        return ret;
    }
    int lower_bound(T w){
        if(w<=0) return 0;
        int x=0;
        static int r=1;
        if(r==1){
            while((r<<1)<=n) r<<=1;
        }
        while((r<<1)<=n) r<<=1;
        for(int k=r;0<k;k>>=1){
            if(x+k<=n&&v[x+k]<w){
                w-=v[x+k];
                x+=k;
            }
        }
        x++;
        return x;
    }
};
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
__gnu_pbds::gp_hash_table<ll,ll> mp;
ll f_log(vector<ll> a,ll n,ll k){  //O(nlogn)
    if(k==0) return 0;
    
    vector<ll> vr(n,0);
    ll r=0,sz=0;
    rep(l,n){
        auto g=[&](ll idx){
            ll p=0;
            if(mp[a[idx]]==0) p=1;
            return (sz+p)<=k;
        };
        while(r<n&&g(r)){
            if(mp[a[r]]==0) sz++;
            mp[a[r]]++;
            r++;
        }
        vr[l]=r;
        mp[a[l]]--;
        if(mp[a[l]]==0) sz--;
    }
    vector<__int128> st(n+1,0);
    st[0]=1;
    fenwick_tree<__int128> BIT(st);
    rep(i,n){
        if(INF<BIT.get(i))  return INF*2ll;
        BIT.add(i+1,1+vr[i],BIT.get(i));
    }
    return BIT.get(n);
}
void solve_linear(vector<ll> a,ll s,auto &f){  //O(N)
    ll n=(ll)a.size();
    ll ok=0;
    rep(i,n+1){
        if(f(a,n,i)<=s) chmax(ok,i);
    }
    cout << ok << '\n';

}
void solve_binary(vector<ll> a,ll s,auto &f){  //O(logN)
    ll n=(ll)a.size();
    ll ok=0,ng=n+1;
    while(1<abs(ok-ng)){
        ll mid=(ok+ng)/2;
        if(f(a,n,mid)<=s) ok=mid;
        else ng=mid;
    }
    cout << ok << '\n';
}

void solve_a(vector<ll> a,ll s){  //O(M^2logM)
    return solve_linear(a,s,f_log);
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin >> n;
    vector<ll> x(n);
    rep(i,n) cin >> x[i];
    x.push_back(INF);
    vector<ll> li,ri;
    ll cnt=1;
    rep(i,n){
        if(x[i]==x[i+1]) cnt++;
        else{
            if(cnt!=1){
                li.push_back(i-cnt+1);
                ri.push_back(i+1);
            }
            cnt=1;
        }
    }
    ll q;
    cin >> q;
    while(q--){
        ll l,r,s;
        cin >> l >> r >> s;
        l--;
        ll sz=r-l;
        if((1ll<<min(61ll,sz-1))<=s){
            cout << "-1\n";
            continue;
        }else if(sz<88){
            vector<ll> a;
            for(ll i=l;i<r;i++) a.push_back(x[i]);
            solve_a(a,s);
        }else{
            ll i=lower_bound(all(li),l)-li.begin();
            i=max(0ll,i-1);
            __int128 now=1;
            for(;i<(ll)li.size();i++){
                ll a=max(li[i],l),b=min(ri[i],r);
                ll k=b-a;
                if(k<=0) continue;
                now*=(1ll<<min(61ll,k-1));
                if(s<now) break;
            }
            if(s<now) cout << "0\n";
            else cout << "1\n";
        }
    }
}
0