답안 #203981

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
203981 2020-02-23T09:18:17 Z Segtree Gap (APIO16_gap) C++14
100 / 100
85 ms 3244 KB
#include<iostream>
#include<algorithm>
#include<vector>
#include"gap.h"
using namespace std;
typedef long long ll;
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
/*
ll a[100010],n,m;
void MinMax(ll s,ll t,ll &mn,ll &mx){
	m++;
	ll l,r,mid;
	l=-1,r=n;
	while(l<r-1){
		mid=(l+r)>>1;
		if(a[mid]>=s)r=mid;
		else l=mid;
	}
	mn=a[r];
	l=-1,r=n;
	while(l<r-1){
		mid=(l+r)>>1;
		if(a[mid]<=t)l=mid;
		else r=mid;
	}
	mx=a[l];
}*/

ll findGap(int T,int N){
	if(T==1){
		ll A[100010];
		A[0]=-1,A[N+1]=2e18;
		ll l=0,r=N+1;
		while(l+1<=r-1){
			ll mn,mx;
			MinMax(A[l]+1,A[r]-1,&mn,&mx);
			l++,r--;
			A[l]=mn,A[r]=mx;
		}
		ll ans=0;
		for(int i=1;i<=N-1;i++)ans=max(ans,A[i+1]-A[i]);
		return ans;
	}
	ll mn,mx;
	ll a,b;
	MinMax(0,1e18,&a,&b);
	ll lower=(b-a+N-1-1)/(N-1);
	vector<ll> v;
	v.push_back(a);
	v.push_back(b);
	for(int i=0;i<N;i++){
		MinMax(a+i*lower+1,a+(i+1)*lower,&mn,&mx);
		if(mn>=0)v.push_back(mn);
		if(mx>=0)v.push_back(mx);
	}
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	ll ans=0;
	rep(i,v.size()-1)ans=max(ans,v[i+1]-v[i]);
	return ans;
}
/*
int main(){
	n=100000;
	rep(i,n)a[i]=rand()%mod;
	sort(a,a+n);
	ll ans=0;
	rep(i,n-1)chmax(ans,a[i+1]-a[i]);
	m=0;
	cout<<ans<<endl;
	cout<<findGap(0,n)<<endl;
	cout<<"m="<<m<<endl;
}*/

Compilation message

gap.cpp: In function 'll findGap(int, int)':
gap.cpp:9:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define rep(i,n) for(int i=0;i<n;i++)
gap.cpp:63:6:
  rep(i,v.size()-1)ans=max(ans,v[i+1]-v[i]);
      ~~~~~~~~~~~~              
gap.cpp:63:2: note: in expansion of macro 'rep'
  rep(i,v.size()-1)ans=max(ans,v[i+1]-v[i]);
  ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 248 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 248 KB Output is correct
6 Correct 5 ms 248 KB Output is correct
7 Correct 5 ms 304 KB Output is correct
8 Correct 5 ms 248 KB Output is correct
9 Correct 5 ms 248 KB Output is correct
10 Correct 5 ms 248 KB Output is correct
11 Correct 5 ms 248 KB Output is correct
12 Correct 5 ms 248 KB Output is correct
13 Correct 5 ms 248 KB Output is correct
14 Correct 5 ms 248 KB Output is correct
15 Correct 5 ms 248 KB Output is correct
16 Correct 19 ms 760 KB Output is correct
17 Correct 17 ms 628 KB Output is correct
18 Correct 17 ms 632 KB Output is correct
19 Correct 17 ms 632 KB Output is correct
20 Correct 13 ms 632 KB Output is correct
21 Correct 55 ms 1784 KB Output is correct
22 Correct 62 ms 1856 KB Output is correct
23 Correct 56 ms 1912 KB Output is correct
24 Correct 60 ms 1912 KB Output is correct
25 Correct 48 ms 1976 KB Output is correct
26 Correct 56 ms 1784 KB Output is correct
27 Correct 66 ms 1912 KB Output is correct
28 Correct 57 ms 1912 KB Output is correct
29 Correct 60 ms 1840 KB Output is correct
30 Correct 44 ms 1916 KB Output is correct
31 Correct 5 ms 248 KB Output is correct
32 Correct 5 ms 248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 248 KB Output is correct
2 Correct 5 ms 248 KB Output is correct
3 Correct 5 ms 252 KB Output is correct
4 Correct 5 ms 248 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 248 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 5 ms 248 KB Output is correct
10 Correct 5 ms 248 KB Output is correct
11 Correct 6 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 6 ms 380 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 22 ms 888 KB Output is correct
17 Correct 23 ms 1012 KB Output is correct
18 Correct 24 ms 940 KB Output is correct
19 Correct 22 ms 888 KB Output is correct
20 Correct 12 ms 504 KB Output is correct
21 Correct 78 ms 2288 KB Output is correct
22 Correct 79 ms 2412 KB Output is correct
23 Correct 85 ms 2288 KB Output is correct
24 Correct 75 ms 2288 KB Output is correct
25 Correct 72 ms 3244 KB Output is correct
26 Correct 80 ms 2460 KB Output is correct
27 Correct 77 ms 2212 KB Output is correct
28 Correct 77 ms 2288 KB Output is correct
29 Correct 79 ms 2284 KB Output is correct
30 Correct 42 ms 1528 KB Output is correct
31 Correct 5 ms 248 KB Output is correct
32 Correct 4 ms 248 KB Output is correct