35402023-02-28 20:26:48SleepyOverlordFasor (40)cpp17Accepted 40/40156ms52504 KiB
#include <vector>
#include <string> 
#include <set> 
#include <map> 
#include <unordered_set>
#include <unordered_map>
#include <queue> 
#include <bitset> 
#include <stack>
#include <list>

#include <numeric> 
#include <algorithm> 
#include <random>
#include <chrono>

#include <cstdio>
#include <fstream>
#include <iostream> 
#include <sstream> 
#include <iomanip>
#include <climits>

#include <cctype>
#include <cmath> 
#include <ctime>
#include <cassert>

using namespace std;

#define ULL unsigned long long
#define LL long long
#define PII pair <int, int>
#define VB vector <bool>
#define VI vector <int>
#define VLL vector <LL>
#define VD vector <double>
#define VS vector <string>
#define VPII vector <pair <int, int> >
#define VVI vector < VI >
#define VVB vector < VB >
#define SI set < int >
#define USI unordered_set <int>
#define MII map <int, int>
#define UMII unordered_map <int, int>
#define MS multiset
#define US unordered_set
#define UM unordered_map
#define UMS unordered_multiset
#define UMM unordered_multimap

#define FORN(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)

#define SZ size()
#define BG begin() 
#define EN end() 
#define CL clear()
#define X first
#define Y second
#define RS resize
#define PB push_back
#define MP make_pair
#define ALL(x) x.begin(), x.end()
#define INS insert
#define ER erase
#define CNT count

#define IN_FILE "a.in"
#define OUT_FILE "a.out"

template <typename T>
void PR(T var1)
{
	cout << var1 <<endl;
}
template <typename T, typename... Types>
void PR(T var1, Types... var2)
{
	cout << var1;
	PR(var2...);
}

int n, k;
VI a;
VVI dp;

int getMax(int l, int r)
{
	int lg = 0;
	while ((1 << lg) <= (r - l + 1)) ++lg;
	--lg;
	return max(dp[l][lg], dp[r - (1 << lg) + 1][lg]);
}

int main()
{
	//freopen(IN_FILE, "r", stdin);
	//freopen(OUT_FILE, "w", stdout);

	cin >> n >> k;
	a.RS(n + 1);
	FOR(i, 1, n) cin >> a[i];

	int lg = 0;
	while ((1 << lg) < n) ++lg;
	dp.RS(n + 1, VI(lg + 1));
	FOR(i, 1, n) dp[i][0] = a[i];
	FOR(i, 1, lg)
		FOR(j, 1, n) 
		{
			int r = min(j + (1 << (i - 1)), n - (1 << (i - 1)) + 1);
			if (r < j) r = j;
			dp[j][i] = max(dp[j][i - 1], dp[r][i - 1]);
		}

	FOR(i, 1, n)
	{
		int l = max(i - k, 1);
		int r = min(i + k, n);
		if (getMax(l, r) == a[i])
		{
			PR(i);
			return 0;
		}
	}

	PR(-1);
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/03ms1688 KiB
2Accepted0/07ms3852 KiB
3Accepted2/22ms1932 KiB
4Accepted2/23ms2064 KiB
5Accepted2/23ms2308 KiB
6Accepted2/23ms2544 KiB
7Accepted2/23ms2940 KiB
8Accepted2/24ms3344 KiB
9Accepted2/27ms5120 KiB
10Accepted2/28ms5072 KiB
11Accepted2/28ms5332 KiB
12Accepted2/26ms5264 KiB
13Accepted2/261ms24500 KiB
14Accepted2/263ms24456 KiB
15Accepted2/2123ms52160 KiB
16Accepted2/2151ms52216 KiB
17Accepted2/2137ms52220 KiB
18Accepted2/2136ms52472 KiB
19Accepted2/2156ms52504 KiB
20Accepted2/246ms25004 KiB
21Accepted2/2125ms52468 KiB
22Accepted2/2136ms52436 KiB