結果

問題 No.1921 Range LthKth Query
ユーザー 👑 kmjpkmjp
提出日時 2022-05-13 00:41:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,853 ms / 4,000 ms
コード長 2,007 bytes
コンパイル時間 3,087 ms
コンパイル使用メモリ 208,456 KB
実行使用メモリ 238,156 KB
最終ジャッジ日時 2023-09-28 01:43:06
合計ジャッジ時間 48,792 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
193,164 KB
testcase_01 AC 78 ms
188,612 KB
testcase_02 AC 78 ms
193,264 KB
testcase_03 AC 78 ms
188,968 KB
testcase_04 AC 77 ms
188,640 KB
testcase_05 AC 78 ms
188,640 KB
testcase_06 AC 88 ms
188,616 KB
testcase_07 AC 78 ms
188,684 KB
testcase_08 AC 78 ms
188,748 KB
testcase_09 AC 79 ms
188,820 KB
testcase_10 AC 83 ms
188,956 KB
testcase_11 AC 150 ms
190,144 KB
testcase_12 AC 245 ms
190,836 KB
testcase_13 AC 2,287 ms
198,188 KB
testcase_14 AC 2,424 ms
205,576 KB
testcase_15 AC 2,853 ms
231,384 KB
testcase_16 AC 2,524 ms
206,016 KB
testcase_17 AC 2,486 ms
208,540 KB
testcase_18 AC 2,638 ms
232,196 KB
testcase_19 AC 2,625 ms
228,972 KB
testcase_20 AC 2,365 ms
220,048 KB
testcase_21 AC 2,192 ms
188,780 KB
testcase_22 AC 2,378 ms
238,156 KB
evil_01.txt TLE -
evil_02.txt TLE -
evil_03.txt MLE -
権限があれば一括ダウンロードができます

ソースコード

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,K,L;
int A[5525];
int dp[5525][5525];

template<class V,int MA> class BIT_2d {
public:
	V val[1<<MA][1<<MA];
	BIT_2d(){ZERO(val);};
	V total(int x,int y) {
		V s=0;
		for(int i=x+1;i>0;i-=i&-i) for(int j=y+1;j>0;j-=j&-j) s+=val[i-1][j-1];
		return s;
	}
	void update(int x,int y,V v) {
		for(int i=x+1;i<=1<<MA;i+=i&-i) for(int j=y+1;j<=1<<MA;j+=j&-j) val[i-1][j-1]+=v;
	}
};
BIT_2d<int,12> bit;

int R[5525];
int ret[2525][2525];
vector<pair<int,int>> cand[2525];

int get(int L,int R) {
	return bit.total(R+1,R+1)-bit.total(R+1,L)-bit.total(L,R+1)+bit.total(L,L);
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K>>L;
	FOR(i,N) cin>>A[i];
	
	MINUS(dp);
	FOR(x,N) {
		R[x]=N;
		multiset<int> S;
		for(y=x;y<N;y++) {
			S.insert(A[y]);
			if(S.size()>K) S.erase(S.find(*S.rbegin()));
			if(S.size()==K) {
				dp[x][y]=*S.rbegin();
				cand[dp[x][y]].push_back({x,y});
			}
		}
	}
	for(x=1;x<=N;x++) {
		FORR2(l,r,cand[x]) bit.update(l+1,r+1,1);
		FOR(i,N) {
			while(get(i,R[i]-1)>=L) {
				R[i]--;
				ret[i][R[i]]=x;
			}
		}
	}
	/*
	FOR(x,N) {
		for(y=x;y<N;y++) cout<<ret[x][y]<<" ";
		cout<<endl;
	}
	*/
	int Q;
	cin>>Q;
	while(Q--) {
		cin>>x>>y;
		cout<<ret[x-1][y-1]<<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