結果

問題 No.2735 Demarcation
ユーザー kaichou243kaichou243
提出日時 2024-04-20 01:33:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,103 ms / 1,500 ms
コード長 1,436 bytes
コンパイル時間 2,578 ms
コンパイル使用メモリ 205,856 KB
実行使用メモリ 11,032 KB
最終ジャッジ日時 2024-04-20 01:33:57
合計ジャッジ時間 12,521 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,812 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 60 ms
11,032 KB
testcase_05 AC 309 ms
6,944 KB
testcase_06 AC 223 ms
9,488 KB
testcase_07 AC 1,021 ms
10,600 KB
testcase_08 AC 301 ms
10,324 KB
testcase_09 AC 306 ms
6,940 KB
testcase_10 AC 333 ms
7,040 KB
testcase_11 AC 40 ms
6,944 KB
testcase_12 AC 61 ms
6,944 KB
testcase_13 AC 91 ms
6,948 KB
testcase_14 AC 1,079 ms
8,556 KB
testcase_15 AC 858 ms
6,940 KB
testcase_16 AC 373 ms
9,388 KB
testcase_17 AC 295 ms
6,940 KB
testcase_18 AC 92 ms
6,940 KB
testcase_19 AC 758 ms
10,356 KB
testcase_20 AC 1,103 ms
10,044 KB
testcase_21 AC 76 ms
8,552 KB
testcase_22 AC 101 ms
10,748 KB
testcase_23 AC 33 ms
6,944 KB
testcase_24 AC 55 ms
6,944 KB
testcase_25 AC 81 ms
9,300 KB
testcase_26 AC 78 ms
8,832 KB
testcase_27 AC 68 ms
7,960 KB
testcase_28 AC 107 ms
10,968 KB
testcase_29 AC 108 ms
10,992 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;
	        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