#include <bits/stdc++.h>
#include "gap.h"
using namespace std;
typedef long long ll;
ll mn, mx, niz[100010];
vector<ll>niz2;
/*int T, N;
ll call_count, subtask_num, A[100000];
static void my_assert(int k){ if (!k) exit(1); }
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;
}
*/
ll findGap(int T, int N)
{
if(T==1)
{
int begg=0, endd=N-1;
ll low_bound=0, up_bound=LONG_LONG_MAX;
while(begg<=endd)
{
MinMax(low_bound, up_bound, &mn, &mx);
niz[begg]=mn; niz[endd]=mx;
//cout<<mn<<" "<<mx<<endl;
begg++; endd--;
low_bound=mn+1; up_bound=mx-1;
}
ll razlika=0;
for(int i=0; i<N; i++)
{razlika=max(razlika, niz[i+1]-niz[i]);}
return razlika;
}
else
{
MinMax(0, LONG_LONG_MAX, &mn, &mx);
ll prosek=(mx-mn)/(N-1);
ll pocetak=mn, kraj=mx;
while(pocetak<kraj)
{
MinMax(pocetak, pocetak+prosek, &mn, &mx);
if(mn!=-1)niz2.push_back(mn);
if(mx!=-1)niz2.push_back(mx);
pocetak=pocetak+prosek+1;
}
ll razlika=0;
for(int i=0; i<niz2.size()-1; i++)razlika=max(razlika,niz2[i+1]-niz2[i]);
return razlika;
}
}
/*int main()
{
cin>>T>>N;
for(int i=1; i<=N; i++)cin>>A[i];
cout<<findGap(T, N);
}
/*1 2
1 3
4!!!!*/
Compilation message
gap.cpp:82:1: warning: "/*" within comment [-Wcomment]
82 | /*1 2
|
gap.cpp: In function 'll findGap(int, int)':
gap.cpp:71:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for(int i=0; i<niz2.size()-1; i++)razlika=max(razlika,niz2[i+1]-niz2[i]);
| ~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
0 ms |
208 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
9 ms |
600 KB |
Output is correct |
17 |
Correct |
10 ms |
652 KB |
Output is correct |
18 |
Correct |
8 ms |
720 KB |
Output is correct |
19 |
Correct |
8 ms |
640 KB |
Output is correct |
20 |
Correct |
7 ms |
592 KB |
Output is correct |
21 |
Correct |
35 ms |
1820 KB |
Output is correct |
22 |
Correct |
36 ms |
1808 KB |
Output is correct |
23 |
Correct |
34 ms |
1828 KB |
Output is correct |
24 |
Correct |
34 ms |
1752 KB |
Output is correct |
25 |
Correct |
30 ms |
1736 KB |
Output is correct |
26 |
Correct |
34 ms |
1868 KB |
Output is correct |
27 |
Correct |
34 ms |
1856 KB |
Output is correct |
28 |
Correct |
40 ms |
1780 KB |
Output is correct |
29 |
Correct |
35 ms |
1784 KB |
Output is correct |
30 |
Correct |
27 ms |
1800 KB |
Output is correct |
31 |
Correct |
0 ms |
208 KB |
Output is correct |
32 |
Correct |
0 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
0 ms |
208 KB |
Output is correct |
7 |
Correct |
0 ms |
336 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
12 ms |
848 KB |
Output is correct |
17 |
Correct |
13 ms |
848 KB |
Output is correct |
18 |
Correct |
14 ms |
848 KB |
Output is correct |
19 |
Correct |
12 ms |
896 KB |
Output is correct |
20 |
Correct |
7 ms |
464 KB |
Output is correct |
21 |
Correct |
49 ms |
2204 KB |
Output is correct |
22 |
Correct |
54 ms |
2196 KB |
Output is correct |
23 |
Correct |
48 ms |
2192 KB |
Output is correct |
24 |
Correct |
49 ms |
2192 KB |
Output is correct |
25 |
Correct |
47 ms |
3228 KB |
Output is correct |
26 |
Correct |
50 ms |
2208 KB |
Output is correct |
27 |
Correct |
51 ms |
2196 KB |
Output is correct |
28 |
Correct |
54 ms |
2240 KB |
Output is correct |
29 |
Correct |
49 ms |
2196 KB |
Output is correct |
30 |
Correct |
26 ms |
1424 KB |
Output is correct |
31 |
Correct |
0 ms |
208 KB |
Output is correct |
32 |
Correct |
0 ms |
208 KB |
Output is correct |