結果
問題 |
No.2735 Demarcation
|
ユーザー |
![]() |
提出日時 | 2024-04-18 18:46:55 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,161 bytes |
コンパイル時間 | 2,971 ms |
コンパイル使用メモリ | 250,156 KB |
実行使用メモリ | 63,216 KB |
最終ジャッジ日時 | 2024-10-11 11:54:23 |
合計ジャッジ時間 | 16,276 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 24 WA * 4 |
ソースコード
#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); auto start=chrono::system_clock::now(); 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; } auto now=chrono::system_clock::now(); int ms=chrono::duration_cast<chrono::milliseconds>(now-start).count(); if(1400<=ms){ 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'; } }