35402023-02-28 20:26:48SleepyOverlordFasor (40)cpp17Elfogadva 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;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base40/40
1Elfogadva0/03ms1688 KiB
2Elfogadva0/07ms3852 KiB
3Elfogadva2/22ms1932 KiB
4Elfogadva2/23ms2064 KiB
5Elfogadva2/23ms2308 KiB
6Elfogadva2/23ms2544 KiB
7Elfogadva2/23ms2940 KiB
8Elfogadva2/24ms3344 KiB
9Elfogadva2/27ms5120 KiB
10Elfogadva2/28ms5072 KiB
11Elfogadva2/28ms5332 KiB
12Elfogadva2/26ms5264 KiB
13Elfogadva2/261ms24500 KiB
14Elfogadva2/263ms24456 KiB
15Elfogadva2/2123ms52160 KiB
16Elfogadva2/2151ms52216 KiB
17Elfogadva2/2137ms52220 KiB
18Elfogadva2/2136ms52472 KiB
19Elfogadva2/2156ms52504 KiB
20Elfogadva2/246ms25004 KiB
21Elfogadva2/2125ms52468 KiB
22Elfogadva2/2136ms52436 KiB