35422023-02-28 20:50:23SleepyOverlordSíkság (55)cpp17Elfogadva 55/55105ms45164 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;
VI a;
VVI dp, dp2;

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 getMin(int l, int r)
{
	int lg = 0;
	while ((1 << lg) <= (r - l + 1)) ++lg;
	--lg;
	return min(dp2[l][lg], dp2[r - (1 << lg) + 1][lg]);
}

int main()
{
	//freopen(IN_FILE, "r", stdin);
	//freopen(OUT_FILE, "w", stdout);
	
	cin >> n;
	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));
	dp2.RS(n + 1, VI(lg + 1));
	FOR(i, 1, n) 
	{
		dp[i][0] = a[i];
		dp2[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]);
			dp2[j][i] = min(dp2[j][i - 1], dp2[r][i - 1]);
		}

	int l = 1, r = 1, best = 1, start = 1;

	while (l < n)
	{
		while (r <= n && getMax(l, r) - getMin(l, r) <= 1) ++r;
		if (r - l > best)
		{
			best = r - l;
			start = l;
		}
		++l;
	}

	PR(best, " ", start);

	return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base55/55
1Elfogadva0/03ms1688 KiB
2Elfogadva0/09ms6000 KiB
3Elfogadva2/23ms2264 KiB
4Elfogadva2/23ms2472 KiB
5Elfogadva2/23ms2480 KiB
6Elfogadva2/23ms2616 KiB
7Elfogadva3/33ms2708 KiB
8Elfogadva2/23ms3092 KiB
9Elfogadva3/33ms3348 KiB
10Elfogadva3/39ms7080 KiB
11Elfogadva3/38ms6952 KiB
12Elfogadva3/38ms6956 KiB
13Elfogadva3/3101ms44384 KiB
14Elfogadva3/381ms44516 KiB
15Elfogadva3/385ms44728 KiB
16Elfogadva3/3105ms44940 KiB
17Elfogadva3/394ms45032 KiB
18Elfogadva3/393ms45164 KiB
19Elfogadva3/3105ms44832 KiB
20Elfogadva3/3104ms44920 KiB
21Elfogadva3/346ms24576 KiB
22Elfogadva3/381ms36092 KiB