90952024-02-13 21:25:55RRoliFasor (40)cpp17Runtime error 38/40194ms33512 KiB
#include <bits/stdc++.h>
using namespace std;

int n, k, a[200001], sz[1000001], ln[200001];
set<int> van;

int main() {
	cin >> n >> k;
	for(int i = 1; i <= n; i++) cin >> a[i];

	for(int i = 1; i <= k+1; i++) {
		sz[a[i]]++;
		van.insert(a[i]*(-1));
	}
	for(int j : van) {ln[1] = j*(-1); break;}

	for(int i = k+2; i <= 2*k+1; i++) {
		sz[a[i]]++;
		van.insert(a[i]*(-1));
		for(int j : van) {ln[i-k] = j*(-1); break;}
	}

	for(int i = 2*k+2; i <= n; i++) {
		sz[a[i]]++;
		van.insert(a[i]*(-1));
		sz[a[i-2*k-1]]--;
		if(sz[a[i-2*k-1]] == 0) van.erase(a[i-2*k-1]*(-1));
		for(int j : van) {ln[i-k] = j*(-1); break;}
	}

	for(int i = n-k+1; i <= n; i++) {
		sz[a[i-k-1]]--;
		if(sz[a[i-k-1]] == 0) van.erase(a[i-k-1]*(-1));
		for(int j : van) {ln[i] = j*(-1); break;}
	}

	for(int i = 1; i <= n; i++) {
		if(a[i] == ln[i]) {
			cout << i;
			break;
		}
	}
 
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base38/40
1Accepted0/03ms1884 KiB
2Accepted0/08ms2500 KiB
3Accepted2/23ms2348 KiB
4Accepted2/23ms2712 KiB
5Accepted2/23ms2600 KiB
6Accepted2/23ms2832 KiB
7Accepted2/23ms3164 KiB
8Accepted2/26ms9912 KiB
9Accepted2/27ms3568 KiB
10Accepted2/29ms10412 KiB
11Accepted2/26ms3656 KiB
12Accepted2/24ms3700 KiB
13Accepted2/239ms5888 KiB
14Runtime error0/237ms5760 KiB
15Accepted2/259ms9180 KiB
16Accepted2/271ms10640 KiB
17Accepted2/275ms12060 KiB
18Accepted2/275ms13600 KiB
19Accepted2/275ms14812 KiB
20Accepted2/224ms13444 KiB
21Accepted2/261ms16108 KiB
22Accepted2/2194ms33512 KiB