답안 #63465

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
63465 2018-08-01T21:45:12 Z qkxwsm Gap (APIO16_gap) C++17
100 / 100
92 ms 3568 KB
#include "gap.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

struct chash
{
        int operator()(int x) const
        {
                x ^= (x >> 20) ^ (x >> 12);
                return x ^ (x >> 7) ^ (x >> 4);
        }
        int operator()(long long x) const
        {
                return x ^ (x >> 32);
        }
};

template<typename T> using orderedset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename U> using hashtable = gp_hash_table<T, U, chash>;

template<class T>
void readi(T &x)
{
        T input = 0;
        bool negative = false;
        char c = ' ';
        while (c < '-')
        {
                c = getchar();
        }
        if (c == '-')
        {
                negative = true;
                c = getchar();
        }
        while (c >= '0')
        {
                input = input * 10 + (c - '0');
                c = getchar();
        }
        if (negative)
        {
                input = -input;
        }
        x = input;
}
template<class T>
void printi(T output)
{
        if (output == 0)
        {
                putchar('0');
                return;
        }
        if (output < 0)
        {
                putchar('-');
                output = -output;
        }
        int aout[20];
        int ilen = 0;
        while(output)
        {
                aout[ilen] = ((output % 10));
                output /= 10;
                ilen++;
        }
        for (int i = ilen - 1; i >= 0; i--)
        {
                putchar(aout[i] + '0');
        }
        return;
}
template<class T>
void ckmin(T &a, T b)
{
        a = min(a, b);
}
template<class T>
void ckmax(T &a, T b)
{
        a = max(a, b);
}
template<class T, class U>
T normalize(T x, U mod = 1000000007)
{
	return (((x % mod) + mod) % mod);
}
static long long randomizell(long long mod)
{
        return ((1ll << 45) * rand() + (1ll << 30) * rand() + (1ll << 15) * rand() + rand()) % mod;
}
static int randomize(int mod)
{
        return ((1ll << 15) * rand() + rand()) % mod;
}

#define y0 ___y0
#define y1 ___y1
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define debug(x) cerr << #x << " = " << x << endl;

const long double PI = 4.0 * atan(1.0);
const long double EPS = 1e-10;

#define MAGIC 347
#define SINF 10007
#define CO 1000007
#define INF 1000000007
#define BIG 1000000931
#define LARGE 1696969696967ll
#define GIANT 2564008813937411ll
#define LLINF 2696969696969696969ll

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;

pll bound(ll L, ll R)
{
	pll res;
	MinMax(L, R, &res.fi, &res.se);
	return res;
}
long long findGap(int tc, int n)
{
	ll res = 0;
	if (tc == 1)
	{
		ll lo = 0, hi = 1'000'000'000'000'000'000;
		vector<ll> vals;
		for (int i = 0; i < (n + 1) / 2; i++)
		{
			// cerr << lo << ' ' << hi << endl;
			pll cur = bound(lo, hi);
			vals.PB(cur.fi);
			vals.PB(cur.se);
			lo = cur.fi + 1;
			hi = cur.se - 1;
		}
		sort(vals.begin(), vals.end());
		for (int i = 1; i < vals.size(); i++)
		{
			ckmax(res, vals[i] - vals[i - 1]);
		}
		return res;
	}
	//LARGEST value of a_i - a_(i-1)
	vector<ll> nums;
	ll lo, hi;
	pll st = bound(0, 1'000'000'000'000'000'000);
	lo = st.fi; hi = st.se;
	ll dif = (hi - lo + n - 1) / (n - 1);
	for (ll i = lo; i < hi; i += dif)
	{
		// cerr << "call " << i << ' ' << min(hi, i + dif - 1) << endl;
		pll cur = bound(i, min(hi, i + dif - 1));
		if (cur.fi != -1)
		{
			nums.PB(cur.fi);
			nums.PB(cur.se);
		}
	}
	for (int i = 1; i < nums.size(); i++)
	{
		ckmax(res, nums[i] - nums[i - 1]);
	}
	return res;
}

Compilation message

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:155:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 1; i < vals.size(); i++)
                   ~~^~~~~~~~~~~~~
gap.cpp:177:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 1; i < nums.size(); i++)
                  ~~^~~~~~~~~~~~~
gap.cpp: At global scope:
gap.cpp:97:12: warning: 'int randomize(int)' defined but not used [-Wunused-function]
 static int randomize(int mod)
            ^~~~~~~~~
gap.cpp:93:18: warning: 'long long int randomizell(long long int)' defined but not used [-Wunused-function]
 static long long randomizell(long long mod)
                  ^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 3 ms 432 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 3 ms 596 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 3 ms 596 KB Output is correct
11 Correct 4 ms 596 KB Output is correct
12 Correct 3 ms 764 KB Output is correct
13 Correct 4 ms 764 KB Output is correct
14 Correct 4 ms 764 KB Output is correct
15 Correct 3 ms 764 KB Output is correct
16 Correct 23 ms 1148 KB Output is correct
17 Correct 19 ms 1148 KB Output is correct
18 Correct 20 ms 1148 KB Output is correct
19 Correct 18 ms 1148 KB Output is correct
20 Correct 16 ms 1148 KB Output is correct
21 Correct 67 ms 2688 KB Output is correct
22 Correct 85 ms 2688 KB Output is correct
23 Correct 65 ms 2688 KB Output is correct
24 Correct 66 ms 2688 KB Output is correct
25 Correct 54 ms 2688 KB Output is correct
26 Correct 70 ms 2688 KB Output is correct
27 Correct 71 ms 2688 KB Output is correct
28 Correct 70 ms 2688 KB Output is correct
29 Correct 61 ms 2688 KB Output is correct
30 Correct 51 ms 2688 KB Output is correct
31 Correct 3 ms 2688 KB Output is correct
32 Correct 3 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2688 KB Output is correct
2 Correct 3 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 3 ms 2688 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Correct 2 ms 2688 KB Output is correct
7 Correct 3 ms 2688 KB Output is correct
8 Correct 2 ms 2688 KB Output is correct
9 Correct 2 ms 2688 KB Output is correct
10 Correct 29 ms 2688 KB Output is correct
11 Correct 4 ms 2688 KB Output is correct
12 Correct 4 ms 2688 KB Output is correct
13 Correct 3 ms 2688 KB Output is correct
14 Correct 3 ms 2688 KB Output is correct
15 Correct 4 ms 2688 KB Output is correct
16 Correct 27 ms 2688 KB Output is correct
17 Correct 28 ms 2688 KB Output is correct
18 Correct 24 ms 2688 KB Output is correct
19 Correct 21 ms 2688 KB Output is correct
20 Correct 12 ms 2688 KB Output is correct
21 Correct 92 ms 2688 KB Output is correct
22 Correct 78 ms 2688 KB Output is correct
23 Correct 79 ms 2688 KB Output is correct
24 Correct 78 ms 2688 KB Output is correct
25 Correct 78 ms 3568 KB Output is correct
26 Correct 82 ms 3568 KB Output is correct
27 Correct 88 ms 3568 KB Output is correct
28 Correct 90 ms 3568 KB Output is correct
29 Correct 84 ms 3568 KB Output is correct
30 Correct 70 ms 3568 KB Output is correct
31 Correct 3 ms 3568 KB Output is correct
32 Correct 2 ms 3568 KB Output is correct