結果
| 問題 |
No.2735 Demarcation
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-04-19 22:25:05 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 124 ms / 1,500 ms |
| コード長 | 1,444 bytes |
| コンパイル時間 | 3,421 ms |
| コンパイル使用メモリ | 264,720 KB |
| 実行使用メモリ | 22,784 KB |
| 最終ジャッジ日時 | 2024-10-11 15:54:15 |
| 合計ジャッジ時間 | 7,025 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 28 |
ソースコード
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
long long big=(1ll<<61);
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n);
for(auto &nx : a){cin >> nx;}
vector<int> g(n,0);
for(int i=1;i<n;i++){
g[i]=g[i-1];
if(a[i-1]==a[i]){g[i]++;}
}
vector<long long> dp(n+5,0);
vector<int> mem(n+5,0);
int clk=0;
int q;
cin >> q;
while(q>0){
q--;
int l,r;
long long s;
cin >> l >> r >> s;
l--; r--;
int maxj=min(61,r-l);
if((1ll<<maxj)<=s){
cout << "-1\n"; // always <= S, so inf
continue;
}
int keep=min(61,g[r]-g[l]);
if((1ll<<keep)>s){
cout << "0\n"; // always > S, so 0
continue;
}
if(r-l>=100){
// f >= Fib_i
cout << "1\n";
continue;
}
int ans=-1;
for(int k=2;;k++){
dp[l]=1;
for(int i=l+1;i<=r+1;i++){
dp[i]=0;
clk++;
int cnt=0;
for(int j=i-1;j>=l;j--){
if(mem[a[j]]!=clk){
mem[a[j]]=clk;
cnt++;
}
if(cnt<=k){
dp[i]+=dp[j];
}
else{break;}
if(dp[i]>s){break;}
}
if(dp[i]>s){
ans=k-1;
break;
}
}
// cerr << dp[r] << "\n";
if(ans!=-1){break;}
}
cout << ans << "\n";
}
return 0;
}