結果

問題 No.2735 Demarcation
ユーザー kaichou243kaichou243
提出日時 2024-04-20 01:34:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 622 ms / 1,500 ms
コード長 1,446 bytes
コンパイル時間 2,073 ms
コンパイル使用メモリ 202,692 KB
実行使用メモリ 11,040 KB
最終ジャッジ日時 2024-04-20 01:34:29
合計ジャッジ時間 9,159 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 53 ms
11,040 KB
testcase_05 AC 151 ms
6,944 KB
testcase_06 AC 163 ms
9,520 KB
testcase_07 AC 575 ms
10,612 KB
testcase_08 AC 304 ms
10,348 KB
testcase_09 AC 197 ms
6,944 KB
testcase_10 AC 207 ms
7,040 KB
testcase_11 AC 29 ms
6,940 KB
testcase_12 AC 85 ms
6,940 KB
testcase_13 AC 187 ms
6,944 KB
testcase_14 AC 587 ms
8,556 KB
testcase_15 AC 465 ms
6,944 KB
testcase_16 AC 222 ms
9,564 KB
testcase_17 AC 362 ms
6,940 KB
testcase_18 AC 111 ms
6,940 KB
testcase_19 AC 455 ms
10,496 KB
testcase_20 AC 622 ms
10,100 KB
testcase_21 AC 59 ms
8,404 KB
testcase_22 AC 87 ms
10,800 KB
testcase_23 AC 29 ms
6,940 KB
testcase_24 AC 48 ms
7,040 KB
testcase_25 AC 75 ms
9,440 KB
testcase_26 AC 68 ms
8,716 KB
testcase_27 AC 59 ms
7,920 KB
testcase_28 AC 112 ms
10,992 KB
testcase_29 AC 97 ms
10,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
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<<"\n";
	        continue;
	    }
	    if(r-l+1<=61&&(1ll<<(r-l))<=s){
	        cout<<-1<<endl;
	        continue;
	    }
	    if(r-l+1>=100){
	        cout<<1<<"\n";
	        continue;
	    }
	    int ok=1,ng=r-l+2;
	    while(ng-ok>1){
	        int m=(ok+ng)/2;
	        unordered_map<int,int> mp;
	        int j=l,cnt=0;
	        vector<ll> dp(r-l+3);
	        bool isok=false;
	        dp[0]=1;
	        dp[1]=-1;
	        for(int i=l;i<=r;i++){
	            while(j<=r&&cnt<=m){
	                if(mp[x[j]]==0) cnt++;
	                if(cnt>m){
	                    cnt--;
	                    break;
	                }
	                mp[x[j]]++;
	                j++;
	            }
	            if(dp[i-l]>s){
	                isok=true;
	                break;
	            }
	            dp[i-l+1]+=dp[i-l]*2;
	            dp[j-l+1]-=dp[i-l];
	            mp[x[i]]--;
	            if(mp[x[i]]==0) cnt--;
	        }
	        if(isok||dp[r-l+1]>s) ng=m;
	        else ok=m;
	    }
	    cout<<ok<<"\n";
	}
}
0