結果

問題 No.2735 Demarcation
ユーザー 沙耶花沙耶花
提出日時 2024-04-19 22:25:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,344 bytes
コンパイル時間 4,208 ms
コンパイル使用メモリ 257,996 KB
実行使用メモリ 22,944 KB
最終ジャッジ日時 2024-04-19 22:25:49
合計ジャッジ時間 13,119 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 89 ms
5,376 KB
testcase_06 AC 278 ms
18,816 KB
testcase_07 AC 503 ms
21,376 KB
testcase_08 WA -
testcase_09 AC 168 ms
10,112 KB
testcase_10 AC 208 ms
12,800 KB
testcase_11 AC 63 ms
7,296 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 445 ms
16,532 KB
testcase_15 AC 208 ms
5,376 KB
testcase_16 AC 299 ms
19,072 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 425 ms
21,248 KB
testcase_20 AC 494 ms
20,040 KB
testcase_21 AC 413 ms
16,128 KB
testcase_22 AC 304 ms
22,016 KB
testcase_23 AC 92 ms
8,832 KB
testcase_24 AC 158 ms
12,544 KB
testcase_25 AC 244 ms
18,432 KB
testcase_26 AC 218 ms
17,152 KB
testcase_27 AC 200 ms
14,976 KB
testcase_28 AC 317 ms
22,912 KB
testcase_29 AC 325 ms
22,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 1000000000000000001



int main(){
	
	int N;
	cin>>N;
	
	vector<long long> x(N);
	rep(i,N)cin>>x[i];
	fenwick_tree<long long> F(N-1);
	rep(i,N-1){
		if(x[i]==x[i+1])F.add(i,1);
	}
	vector<int> cnt(N+5,0);
	int Q;
	cin>>Q;
	rep(_,Q){
		long long l,r,S;
		cin>>l>>r>>S;
		l--;
		if(r-l>=100){
			long long t = F.sum(l,r-1);
			if(t<=60 && (1LL<<t)<=S){
				cout<<1<<endl;
				continue;
			}
			else{
				cout<<0<<endl;
				continue;
			}
		}
		else{
			
			int n = r-l;
			int ok = 0,ng = n+2;
			while(ng-ok>1){
				int mid = (ok+ng)/2;
				vector<long long> dp(n+1,0);
				dp[0] = 1;
				rep(j,n){
					int C = 0;
					for(int k=0;k<n;k++){
						if(j+k>=n)break;
						if(cnt[x[l+j+k]]==0){
							C++;
							if(C>mid)break;
							cnt[x[l+j+k]] = 1;
						}
						
						dp[j+k+1] += dp[j];
						if(dp[j+k+1]>S){
							dp.back() = S+1;
							goto L;
						}
					}
					for(int k=0;k<n;k++){
						if(j+k>=n)break;
						cnt[x[l+j+k]] = 0;
						
					}
				}
				L:;
				if(dp.back()>S)ng = mid;
				else ok = mid;
			}
			if(ok==n+1)cout<<-1<<endl;
			else cout<<ok<<endl;
			
		}
		
		
	}
	
	
	return 0;
}
0