Submission #731886

#TimeUsernameProblemLanguageResultExecution timeMemory
731886senthetaGap (APIO16_gap)C++17
0 / 100
38 ms1868 KiB
#include "gap.h"
// author : sentheta aka vanwij
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cassert>
#include<random>
#include<chrono>
#include<cmath>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;

#define Int long long
#define V vector
#define pii pair<Int,Int>
#define ff first
#define ss second

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

#define pow2(x) (1LL<<(x))
#define msb(x) (63-__builtin_clzll(x))
#define bitcnt(x) (__builtin_popcountll(x))

#define nl '\n'
#define _ << ' ' <<
#define all(x) (x).begin(), (x).end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define dbg(x) if(1) cout << "?" << #x << " : " << (x) << endl << flush;

pii query(int l,int r){
	Int a, b;
	MinMax(l,r, &a,&b);
	return {a,b};
}
int n;

Int findGap(int T,int _n){
	n = _n;
	if(T==1){
		V<int> l, r;
		{
			auto[a,b] = query(0,1e18);
			l = {a};
			r = {b};
		}
		while((int)l.size() + (int)r.size() < n){
			auto[a,b] = query(l.back()+1, r.back()-1);
			l.push_back(a);
			r.push_back(b);
		}
		reverse(all(r));
		for(int x : r) l.push_back(x);

		int prv = l[0], ans = 0;
		for(int x : l){
			ans = max(ans, x-prv);
			prv = x;
		}
		return ans;
	}
	return 0;
}

Compilation message (stderr)

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:49:24: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   49 |    auto[a,b] = query(0,1e18);
      |                        ^~~~
gap.cpp:50:9: warning: narrowing conversion of 'a' from 'std::tuple_element<0, std::pair<long long int, long long int> >::type' {aka 'long long int'} to 'int' [-Wnarrowing]
   50 |    l = {a};
      |         ^
gap.cpp:50:9: warning: narrowing conversion of 'a' from 'std::tuple_element<0, std::pair<long long int, long long int> >::type' {aka 'long long int'} to 'int' [-Wnarrowing]
gap.cpp:51:9: warning: narrowing conversion of 'b' from 'std::tuple_element<1, std::pair<long long int, long long int> >::type' {aka 'long long int'} to 'int' [-Wnarrowing]
   51 |    r = {b};
      |         ^
gap.cpp:51:9: warning: narrowing conversion of 'b' from 'std::tuple_element<1, std::pair<long long int, long long int> >::type' {aka 'long long int'} to 'int' [-Wnarrowing]
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...