結果

問題 No.2735 Demarcation
ユーザー 👑 kmjpkmjp
提出日時 2024-04-20 00:44:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,858 bytes
コンパイル時間 1,944 ms
コンパイル使用メモリ 199,044 KB
実行使用メモリ 14,856 KB
最終ジャッジ日時 2024-04-20 00:45:00
合計ジャッジ時間 5,782 ms
ジャッジサーバーID
(参考情報)
judge3 / 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
7,648 KB
testcase_04 WA -
testcase_05 AC 19 ms
6,944 KB
testcase_06 AC 83 ms
13,612 KB
testcase_07 AC 120 ms
14,856 KB
testcase_08 AC 112 ms
13,212 KB
testcase_09 AC 47 ms
11,192 KB
testcase_10 AC 61 ms
13,508 KB
testcase_11 AC 22 ms
7,140 KB
testcase_12 AC 18 ms
6,940 KB
testcase_13 AC 43 ms
6,940 KB
testcase_14 AC 96 ms
12,748 KB
testcase_15 AC 35 ms
6,940 KB
testcase_16 AC 84 ms
13,964 KB
testcase_17 AC 81 ms
9,408 KB
testcase_18 AC 36 ms
6,944 KB
testcase_19 AC 113 ms
14,704 KB
testcase_20 AC 119 ms
14,204 KB
testcase_21 AC 72 ms
10,104 KB
testcase_22 AC 90 ms
13,292 KB
testcase_23 AC 33 ms
7,012 KB
testcase_24 AC 55 ms
12,760 KB
testcase_25 AC 82 ms
12,832 KB
testcase_26 AC 69 ms
12,224 KB
testcase_27 AC 73 ms
12,020 KB
testcase_28 AC 108 ms
13,468 KB
testcase_29 AC 110 ms
13,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N,Q;
int X[1010101];
int same[1010101];
ll S;
int L,R;

ll dp[101];
int num[1010101];
ll hoge(int k,vector<int>& V) {
	int i;
	int B=V.size();
	dp[0]=1;
	ll sum=1;
	int cnum=0;
	int cur=1,pre=0;
	FORR(v,V) num[v]=0;
	for(;cur<=B;cur++) {
		if(num[V[cur-1]]++==0) cnum++;
		while(cnum>k) {
			sum-=dp[pre];
			if(--num[V[pre]]==0) cnum--;
			pre++;
		}
		dp[cur]=sum;
		if(sum>=1LL<<60) return sum;
		sum+=dp[cur];
	}
	return dp[B];
	
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>X[i];
		if(i) same[i]=same[i-1]+(X[i]==X[i-1]);
	}
	cin>>Q;
	while(Q--) {
		cin>>L>>R>>S;
		L--;
		if(R-L>=100) {
			int cand=same[R-1]-same[L];
			if(cand>=60||S<(1LL<<cand)) {
				cout<<0<<endl;
			}
			else {
				cout<<1<<endl;
			}
			continue;
		}
		vector<int> V;
		for(i=L;i<R;i++) V.push_back(X[i]);
		int TL=0,TR=V.size()+2;
		while(TL+1<TR) {
			int TM=(TL+TR)/2;
			ll ret=hoge(TM,V);
			if(ret<=S) {
				TL=TM;
			}
			else {
				TR=TM;
			}
		}
		if(TL>V.size()) {
			cout<<-1<<endl;
		}
		else {
			cout<<TL<<endl;
		}
		
	}
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0