Submission #444301

#TimeUsernameProblemLanguageResultExecution timeMemory
444301arwaeystoamnegGap (APIO16_gap)C++17
30 / 100
61 ms2708 KiB
// EXPLOSION! #define _CRT_SECURE_NO_WARNINGS #include<bits/stdc++.h> #include<unordered_set> #include<unordered_map> #include<chrono> using namespace std; typedef pair<int, int> pii; typedef long long ll; typedef pair<ll, ll> pll; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pair<int, int>> vpi; typedef vector<pair<ll, ll>> vpll; #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define F0R(i,a) FOR(i,0,a) #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i) #define R0F(i,a) ROF(i,0,a) #define trav(a,x) for (auto& a: x) #define pb push_back #define mp make_pair #define rsz resize #define sz(x) int(x.size()) #define all(x) x.begin(),x.end() #define f first #define s second #define cont continue #define endl '\n' //#define ednl '\n' #define test int testc;cin>>testc;while(testc--) #define pr(a, b) trav(x,a)cerr << x << b; cerr << endl; #define message cout << "Hello World" << endl; const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 }; // for every grid problem!! const ll linf = 4000000000000000000LL; const ll inf = 1000000007;//998244353 void pv(vi a) { trav(x, a)cout << x << " "; cout << endl; }void pv(vll a) { trav(x, a)cout << x << " "; cout << endl; }void pv(vector<vi>a) { F0R(i, sz(a)) { cout << i << endl; pv(a[i]); cout << endl; } }void pv(vector<vll>a) { F0R(i, sz(a)) { cout << i << endl; pv(a[i]); }cout << endl; }void pv(vector<string>a) { trav(x, a)cout << x << endl; cout << endl; } void setIO(string s) { ios_base::sync_with_stdio(0); cin.tie(0); #ifdef arwaeystoamneg if (sz(s)) { freopen((s + ".in").c_str(), "r", stdin); if (s != "test1") freopen((s + ".out").c_str(), "w", stdout); } #endif } #ifndef arwaeystoamneg #include "gap.h" #endif #ifdef arwaeystoamneg static void my_assert(int k) { if (!k) exit(1); } static int subtask_num, N; static long long A[100001]; static long long call_count; void MinMax(long long s, long long t, long long* mn, long long* mx) { int lo = 1, hi = N, left = N + 1, right = 0; my_assert(s <= t && mn != NULL && mx != NULL); while (lo <= hi) { int mid = (lo + hi) >> 1; if (A[mid] >= s) hi = mid - 1, left = mid; else lo = mid + 1; } lo = 1, hi = N; while (lo <= hi) { int mid = (lo + hi) >> 1; if (A[mid] <= t) lo = mid + 1, right = mid; else hi = mid - 1; } if (left > right) *mn = *mx = -1; else { *mn = A[left]; *mx = A[right]; } if (subtask_num == 1) call_count++; else if (subtask_num == 2) call_count += right - left + 2; } #endif int n; const int MAX = 111111; ll a[MAX]; ll solve1() { int l = 0, r = n - 1; ll L = 0, R = 1e18; while (l <= r) { MinMax(L, R, &a[l], &a[r]); L = a[l++] + 1; R = a[r--] - 1; } ll ans = -linf; F0R(i, n - 1) { ans = max(ans, a[i + 1] - a[i]); } return ans; } pll b[MAX]; ll solve() { ll L = 0, R = 1e18; MinMax(L, R, &a[0], &a[n - 1]); L = a[0], R = a[n - 1]; ll d = (R - L - 1) / (n - 1) + 1; F0R(i, n - 1) { MinMax(L, min(R, L + d) - 1, &b[i].f, &b[i].s); L += d; } ll last = -linf, ans = -linf; F0R(i, n - 1) { if (b[i].f == -1) { // do nothing } else if (b[i].f == b[i].s) { if (last != -linf)ans = max(ans, b[i].f - last); last = b[i].s; } else { if (last != -linf)ans = max(ans, b[i].f - last); last = b[i].s; } } ans = max(ans, R - last); return ans; } long long findGap(int subtask, int N) { n = N; if (subtask == 1) { return solve1(); } else { return solve(); } } #ifdef arwaeystoamneg int main() { setIO("test1"); cin >> subtask_num >> N; my_assert(1 <= subtask_num && subtask_num <= 2); my_assert(2 <= N && N <= 100000); for (int i = 1; i <= N; i++) cin >> A[i]; for (int i = 1; i < N; i++) my_assert(A[i] < A[i + 1]); cout << findGap(subtask_num, N) << endl << call_count << endl; } #endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...