結果
| 問題 |
No.2735 Demarcation
|
| コンテスト | |
| ユーザー |
FplusFplusF
|
| 提出日時 | 2024-04-18 18:38:42 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,911 bytes |
| コンパイル時間 | 3,098 ms |
| コンパイル使用メモリ | 249,852 KB |
| 実行使用メモリ | 30,112 KB |
| 最終ジャッジ日時 | 2024-10-11 11:53:51 |
| 合計ジャッジ時間 | 8,481 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 21 TLE * 1 -- * 6 |
ソースコード
#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;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
vector<ll> cnt(1000001,0);
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--;
ll w=r-l,ok=0;
if((1ll<<min(61ll,w-1))<=s){
cout << "-1\n";
continue;
}
for(ll k=1;k<=w;k++){
vector<ll> vr(w,0);
ll nr=0,sz=0;
rep(nl,w){
auto g=[&](ll idx){
ll p=0;
if(cnt[x[l+idx]]==0) p=1;
return (sz+p)<=k;
};
while(nr<w&&g(nr)){
if(cnt[x[l+nr]]==0) sz++;
cnt[x[l+nr]]++;
nr++;
}
vr[nl]=nr;
cnt[x[l+nl]]--;
if(cnt[x[l+nl]]==0) sz--;
}
vector<__int128> dp(w+1,0),sum(w+2,0);
dp[0]=1;
rep(i,w+1){
dp[i]+=sum[i];
if(s<dp[i]){
dp[w]=s+1;
break;
}
if(i==w) break;
sum[i+1]+=dp[i];
sum[1+vr[i]]-=dp[i];
sum[i+1]+=sum[i];
}
if(dp[w]<=s) chmax(ok,k);
else break;
}
cout << ok << '\n';
}
}
FplusFplusF