#include<bits/stdc++.h>
#include<stdint.h>
using namespace std;
#define IOS {cin.tie(0);ios_base::sync_with_stdio(false);}
#define N 300006
//vector<int> vv;
//void MinMax(long long s, long long t, long long* mn, long long* mx){
// cout << "ASKed " << s << ' ' << t << '\n';
// auto imn = lower_bound(vv.begin(),vv.end(),s);
// auto imx = upper_bound(vv.begin(),vv.end(),t);
// if(imn == vv.end() || imx == vv.begin() || *imn > *--imx) {
// cout << "return (-1,-1)" << '\n';
// return *mn = *mx = -1ll, void();
// }
// *mn = *imn;
// *mx = *imx;
// cout << "return " << complex<int>(*mn,*mx) << '\n';
//}
#include "gap.h"
typedef long long ll;
ll nowmx;
vector<ll> v;
void qur(ll l,ll r){
if(l > r || r-l <= nowmx) return;
ll mn,mx;
if(l+1 == r){
MinMax(l,r,&mn,&mx);
nowmx = max(nowmx,mn-mx);
if(mn == -1) return;
v.push_back(mn);
if(mn != mx) v.push_back(mx);
return;
}
ll m = l+r>>1;
MinMax(m+1,r,&mn,&mx);
if(mn != -1) {
v.push_back(mn);
if(mn != mx) v.push_back(mx);
qur(mn+1,mx-1);
}else nowmx = max(nowmx,m-l);
MinMax(l,m,&mn,&mx);
if(mn != -1) {
v.push_back(mn);
if(mn != mx) v.push_back(mx);
qur(mn+1,mx-1);
}
else nowmx = max(nowmx,m-l);
}
ll findGap(int T,int n){
if(T==1){
vector<ll> v1,v2;
ll ans = 0;
ll s = 0, t = 1000000000000000000ll,mn,mx;
for(int i=1,j=n;i<=j;i++,j--){
MinMax(s,t,&mn,&mx);
v1.push_back(mn);
if(i != j) v2.push_back(mx);
s = mn+1; t=mx-1;
}
reverse(v2.begin(),v2.end());
for(ll i : v2) v1.push_back(i);
for(int i=0;i<v1.size()-1;i++) ans = max(ans,v1[i+1]-v1[i]);
return ans;
}
else{
ll ans = 0;
ll s = 0, t = 1000000000000000000ll,mn,mx;
qur(s,t);
sort(v.begin(),v.end());
//for(int i : v) cout << i << ' '; cout << '\n';
for(int i=0;i<v.size()-1;i++) ans = max(ans,v[i+1]-v[i]);
return ans;
}
}
Compilation message
gap.cpp: In function 'void qur(ll, ll)':
gap.cpp:37:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
ll m = l+r>>1;
~^~
gap.cpp: In function 'll findGap(int, int)':
gap.cpp:66:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v1.size()-1;i++) ans = max(ans,v1[i+1]-v1[i]);
~^~~~~~~~~~~~
gap.cpp:75:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v.size()-1;i++) ans = max(ans,v[i+1]-v[i]);
~^~~~~~~~~~~
gap.cpp:71:39: warning: unused variable 'mn' [-Wunused-variable]
ll s = 0, t = 1000000000000000000ll,mn,mx;
^~
gap.cpp:71:42: warning: unused variable 'mx' [-Wunused-variable]
ll s = 0, t = 1000000000000000000ll,mn,mx;
^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
16 ms |
1152 KB |
Output is correct |
17 |
Correct |
14 ms |
1068 KB |
Output is correct |
18 |
Correct |
14 ms |
1152 KB |
Output is correct |
19 |
Correct |
16 ms |
1092 KB |
Output is correct |
20 |
Correct |
14 ms |
1152 KB |
Output is correct |
21 |
Correct |
53 ms |
2716 KB |
Output is correct |
22 |
Correct |
49 ms |
2864 KB |
Output is correct |
23 |
Correct |
52 ms |
2728 KB |
Output is correct |
24 |
Correct |
54 ms |
2800 KB |
Output is correct |
25 |
Correct |
44 ms |
2844 KB |
Output is correct |
26 |
Correct |
56 ms |
2844 KB |
Output is correct |
27 |
Correct |
54 ms |
2716 KB |
Output is correct |
28 |
Correct |
58 ms |
2844 KB |
Output is correct |
29 |
Correct |
66 ms |
2840 KB |
Output is correct |
30 |
Correct |
41 ms |
2748 KB |
Output is correct |
31 |
Correct |
2 ms |
384 KB |
Output is correct |
32 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Incorrect |
2 ms |
380 KB |
Output isn't correct |
6 |
Partially correct |
3 ms |
384 KB |
Partially correct |
7 |
Partially correct |
2 ms |
384 KB |
Partially correct |
8 |
Partially correct |
3 ms |
384 KB |
Partially correct |
9 |
Partially correct |
2 ms |
384 KB |
Partially correct |
10 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
11 |
Partially correct |
3 ms |
384 KB |
Partially correct |
12 |
Partially correct |
4 ms |
384 KB |
Partially correct |
13 |
Partially correct |
2 ms |
384 KB |
Partially correct |
14 |
Partially correct |
4 ms |
384 KB |
Partially correct |
15 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
16 |
Partially correct |
15 ms |
896 KB |
Partially correct |
17 |
Partially correct |
17 ms |
896 KB |
Partially correct |
18 |
Partially correct |
12 ms |
896 KB |
Partially correct |
19 |
Partially correct |
14 ms |
888 KB |
Partially correct |
20 |
Incorrect |
7 ms |
640 KB |
Output isn't correct |
21 |
Partially correct |
46 ms |
1908 KB |
Partially correct |
22 |
Partially correct |
48 ms |
1780 KB |
Partially correct |
23 |
Partially correct |
51 ms |
1908 KB |
Partially correct |
24 |
Partially correct |
51 ms |
1908 KB |
Partially correct |
25 |
Incorrect |
24 ms |
1148 KB |
Output isn't correct |
26 |
Partially correct |
53 ms |
1804 KB |
Partially correct |
27 |
Partially correct |
51 ms |
1780 KB |
Partially correct |
28 |
Partially correct |
50 ms |
1836 KB |
Partially correct |
29 |
Partially correct |
48 ms |
1780 KB |
Partially correct |
30 |
Incorrect |
20 ms |
1276 KB |
Output isn't correct |
31 |
Partially correct |
3 ms |
384 KB |
Partially correct |
32 |
Partially correct |
2 ms |
384 KB |
Partially correct |