# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
967146 |
2024-04-21T10:35:05 Z |
Nhoksocqt1 |
Gap (APIO16_gap) |
C++17 |
|
458 ms |
3288 KB |
#ifndef Nhoksocqt1
#include "gap.h"
#endif // Nhoksocqt1
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define sz(x) int((x).size())
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;
template<class X, class Y>
inline bool maximize(X &x, const Y &y) {return (x < y ? x = y, 1 : 0);}
template<class X, class Y>
inline bool minimize(X &x, const Y &y) {return (x > y ? x = y, 1 : 0);}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int Random(int l, int r) {
return uniform_int_distribution<int>(l, r)(rng);
}
const int MAXN = 100005;
ll a[MAXN];
int nArr;
#ifdef Nhoksocqt1
ll _A[MAXN], M;
void MinMax(ll s, ll t, ll *a, ll *b) {
int l(1), r(nArr), optL(nArr + 1), optR(-1);
while(l <= r) {
int mid = (l + r) >> 1;
if(_A[mid] >= s) {
optL = mid;
r = mid - 1;
} else {
l = mid + 1;
}
}
l = 1, r = nArr;
while(l <= r) {
int mid = (l + r) >> 1;
if(_A[mid] <= t) {
optR = mid;
l = mid + 1;
} else {
r = mid - 1;
}
}
M += optR - optL + 2;
if(optL > optR) {
*a = *b = -1;
} else {
*a = _A[optL], *b = _A[optR];
}
}
#endif // Nhoksocqt1
ll findGap(int T, int N) {
nArr = N;
MinMax(0, ll(1e18), &a[1], &a[nArr]);
if(T == 1) {
for (int i = 2; i <= (nArr + 1) / 2; ++i)
MinMax(a[i - 1] + 1, a[nArr - i + 2] - 1, &a[i], &a[nArr - i + 1]);
ll res(0);
for (int i = 1; i < nArr; ++i)
res = max(res, a[i + 1] - a[i]);
return res;
}
ll answer = 1, lst = a[1];
bool check = 1;
while(check) {
check = 0;
ll pos(lst);
for (int i = 0; i < 60; ++i) {
ll s, t;
MinMax(pos + 1, pos + (1LL << i), &s, &t);
if(s != -1) {
answer = max(answer, s - lst);
lst = t;
check = 1;
break;
}
}
}
return answer;
}
#ifdef Nhoksocqt1
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define TASK "GAP"
if(fopen(TASK".inp", "r")) {
freopen(TASK".inp", "r", stdin);
freopen(TASK".out", "w", stdout);
}
int T, N;
cin >> T >> N;
for (int i = 1; i <= N; ++i) {
cin >> _A[i];
//_A[i] = _A[i - 1] + Random(1, 1e9); cout << _A[i] << " \n"[i == N];
}
M = 0;
cout << "ANSWER: " << findGap(T, N) << '\n';
cout << "COST ASK: " << M << '\n';
return 0;
}
#endif // Nhoksocqt1
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
0 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
10 ms |
2728 KB |
Output is correct |
17 |
Correct |
8 ms |
2592 KB |
Output is correct |
18 |
Correct |
7 ms |
2592 KB |
Output is correct |
19 |
Correct |
7 ms |
2588 KB |
Output is correct |
20 |
Correct |
6 ms |
2572 KB |
Output is correct |
21 |
Correct |
28 ms |
2852 KB |
Output is correct |
22 |
Correct |
28 ms |
2876 KB |
Output is correct |
23 |
Correct |
28 ms |
2880 KB |
Output is correct |
24 |
Correct |
30 ms |
3288 KB |
Output is correct |
25 |
Correct |
26 ms |
2868 KB |
Output is correct |
26 |
Correct |
28 ms |
2880 KB |
Output is correct |
27 |
Correct |
32 ms |
2860 KB |
Output is correct |
28 |
Correct |
28 ms |
2876 KB |
Output is correct |
29 |
Correct |
28 ms |
2856 KB |
Output is correct |
30 |
Correct |
23 ms |
2944 KB |
Output is correct |
31 |
Correct |
1 ms |
2392 KB |
Output is correct |
32 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
2392 KB |
Partially correct |
2 |
Partially correct |
1 ms |
2392 KB |
Partially correct |
3 |
Partially correct |
1 ms |
2392 KB |
Partially correct |
4 |
Partially correct |
1 ms |
2392 KB |
Partially correct |
5 |
Partially correct |
1 ms |
2392 KB |
Partially correct |
6 |
Partially correct |
1 ms |
2392 KB |
Partially correct |
7 |
Partially correct |
1 ms |
2392 KB |
Partially correct |
8 |
Partially correct |
1 ms |
2392 KB |
Partially correct |
9 |
Partially correct |
1 ms |
2392 KB |
Partially correct |
10 |
Partially correct |
1 ms |
2392 KB |
Partially correct |
11 |
Partially correct |
5 ms |
2392 KB |
Partially correct |
12 |
Partially correct |
5 ms |
2392 KB |
Partially correct |
13 |
Partially correct |
6 ms |
2516 KB |
Partially correct |
14 |
Partially correct |
5 ms |
2392 KB |
Partially correct |
15 |
Partially correct |
4 ms |
2392 KB |
Partially correct |
16 |
Partially correct |
96 ms |
2588 KB |
Partially correct |
17 |
Partially correct |
94 ms |
2592 KB |
Partially correct |
18 |
Partially correct |
98 ms |
2588 KB |
Partially correct |
19 |
Partially correct |
95 ms |
2592 KB |
Partially correct |
20 |
Correct |
4 ms |
2576 KB |
Output is correct |
21 |
Partially correct |
418 ms |
2884 KB |
Partially correct |
22 |
Partially correct |
419 ms |
2880 KB |
Partially correct |
23 |
Partially correct |
420 ms |
2872 KB |
Partially correct |
24 |
Partially correct |
416 ms |
2880 KB |
Partially correct |
25 |
Partially correct |
341 ms |
3116 KB |
Partially correct |
26 |
Partially correct |
427 ms |
2876 KB |
Partially correct |
27 |
Partially correct |
458 ms |
2888 KB |
Partially correct |
28 |
Partially correct |
424 ms |
2868 KB |
Partially correct |
29 |
Partially correct |
436 ms |
2872 KB |
Partially correct |
30 |
Correct |
17 ms |
2872 KB |
Output is correct |
31 |
Partially correct |
1 ms |
2392 KB |
Partially correct |
32 |
Partially correct |
1 ms |
2392 KB |
Partially correct |