結果

問題 No.2735 Demarcation
ユーザー kaichou243kaichou243
提出日時 2024-04-20 01:09:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,461 bytes
コンパイル時間 1,961 ms
コンパイル使用メモリ 199,604 KB
実行使用メモリ 21,128 KB
最終ジャッジ日時 2024-04-20 01:09:46
合計ジャッジ時間 6,793 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
13,752 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 66 ms
15,080 KB
testcase_05 AC 101 ms
6,940 KB
testcase_06 AC 822 ms
12,516 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
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>
#define endl '\n'
using namespace std;
using ll=long long;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin>>n;
	vector<int> x(n);
	for(int i=0;i<n;i++) cin>>x[i];
	vector<int> sum(n);
	for(int i=0;i<n-1;i++) sum[i+1]=sum[i]+(x[i]==x[i+1]?1:0);
	int q;
	cin>>q;
	while(q--){
	    ll l,r,s;
	    cin>>l>>r>>s;
	    --l;
	    --r;
	    if(sum[r]-sum[l]>60||(1ll<<(sum[r]-sum[l]))>s){
	        cout<<0<<endl;
	        continue;
	    }
	    if(r-l+1<=61&&(1ll<<(r-l))<=s){
	        cout<<-1<<endl;
	        continue;
	    }
	    if(r-l+1>=90){
	        cout<<1<<endl;
	        continue;
	    }
	    int ok=1,ng=r-l+2;
	    while(ng-ok>1){
	        int m=(ok+ng)/2;
	        vector<int> mp(n+1);
	        int cnt=0;
	        vector<ll> dp(r-l+3);
	        bool isok=false;
	        dp[0]=1;
	        dp[1]=-1;
	        for(int i=0,j=0;i<r-l+1;i++){
	            while(j<r-l+1&&cnt<=m){
	                if(mp[x[j+l]]==0) cnt++;
	                if(cnt>m){
	                    cnt--;
	                    break;
	                }
	                mp[x[j+l]]++;
	                j++;
	            }
	            if(dp[i]>s){
	                isok=true;
	                break;
	            }
	            dp[i+1]+=dp[i]*2;
	            dp[j+1]-=dp[i];
	            mp[x[i+l]]--;
	            if(mp[x[i+l]]==0) cnt--;
	        }
	        if(isok||dp[r-l+1]>s) ng=m;
	        else ok=m;
	    }
	    cout<<ok<<endl;
	}
}
0