結果

問題 No.2735 Demarcation
ユーザー kaichou243kaichou243
提出日時 2024-04-20 01:04:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,475 bytes
コンパイル時間 2,901 ms
コンパイル使用メモリ 199,680 KB
実行使用メモリ 14,996 KB
最終ジャッジ日時 2024-04-20 01:04:44
合計ジャッジ時間 9,052 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 60 ms
14,996 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 AC 64 ms
8,476 KB
testcase_22 AC 93 ms
10,676 KB
testcase_23 AC 30 ms
6,944 KB
testcase_24 AC 51 ms
7,040 KB
testcase_25 WA -
testcase_26 AC 73 ms
8,832 KB
testcase_27 RE -
testcase_28 AC 99 ms
11,024 KB
testcase_29 AC 103 ms
10,996 KB
権限があれば一括ダウンロードができます

ソースコード

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=1,j=1;i<=r-l+1;i++){
	            while(j<=r-l+1&&cnt<=m){
	                if(mp[x[j+l-1]]==0) cnt++;
	                if(cnt>m){
	                    cnt--;
	                    break;
	                }
	                mp[x[j+l-1]]++;
	                j++;
	            }
	            if(dp[i-1]>s){
	                isok=true;
	                break;
	            }
	            dp[i]+=dp[i-1]*2;
	            dp[j+1]-=dp[i-1];
	            mp[x[i+l-1]]--;
	            if(mp[x[i+l-1]]==0) cnt--;
	        }
	        if(isok||dp[r-l+1]>s) ng=m;
	        else ok=m;
	    }
	    cout<<ok<<endl;
	}
}
0