結果

問題 No.2735 Demarcation
ユーザー FplusFplusFFplusFplusF
提出日時 2024-04-03 14:19:35
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 3,105 bytes
コンパイル時間 3,954 ms
コンパイル使用メモリ 282,484 KB
実行使用メモリ 17,920 KB
最終ジャッジ日時 2024-04-19 19:38:45
合計ジャッジ時間 9,949 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,888 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
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 AC 109 ms
8,364 KB
testcase_22 AC 95 ms
10,624 KB
testcase_23 TLE -
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;
    }
};
ll cnt[1000001];
ll f(vector<ll> a,ll n,ll k){
    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(cnt[a[idx]]==0) p=1;
            return (sz+p)<=k;
        };
        while(r<n&&g(r)){
            if(cnt[a[r]]==0) sz++;
            cnt[a[r]]++;
            r++;
        }
        vr[l]=r;
        cnt[a[l]]--;
        if(cnt[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(vector<ll> a,ll s){
    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 << f(a,n,ok) << '\n';

}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin >> n;
    vector<ll> x(n);
    rep(i,n) cin >> x[i];
    ll q;
    cin >> q;
    while(q--){
        ll l,r,s;
        cin >> l >> r >> s;
        l--;
        if((1ll<<min(61ll,r-l-1))<=s){
            cout << "-1\n";
            continue;
        }
        vector<ll> a;
        for(ll i=l;i<r;i++) a.push_back(x[i]);
        solve(a,s);
    }
}
0