제출 #638417

#제출 시각아이디문제언어결과실행 시간메모리
638417LeticiaFCSWish (LMIO19_noras)C++17
100 / 100
165 ms14888 KiB
#include "bits/stdc++.h"
#define st first
#define nd second
using lint = int64_t;
constexpr int MOD = int(1e9) + 7;
constexpr int INF = 0x3f3f3f3f;
constexpr int NINF = 0xcfcfcfcf;
constexpr lint LINF = 0x3f3f3f3f3f3f3f3f;
const long double PI = acosl(-1.0);
// Returns -1 if a < b, 0 if a = b and 1 if a > b.
int cmp_double(double a, double b = 0, double eps = 1e-9) {
	return a + eps > b ? b + eps > a ? 0 : 1 : -1;
}
using namespace std;


using ld = double;



bool inCircle(ld x, ld y, ld dx, ld dy, ld r, ld t){
	return ( (x + dx*t)*(x + dx*t) + (y + dy*t)*(y + dy*t) ) <= r*r; 
}
pair<bool, lint> firstInCircle(ld x, ld y, ld dx, ld dy, ld r, ld dbt){	
	lint s = ld(dbt) - 2;
	lint e = s + 4;
	for(ld t = s; t<=e; t++)
		if(inCircle(x,y,dx,dy,r, t)) return {true,t};
	return {false, -1};
} 
pair<bool, lint> lastInCircle(ld x, ld y, ld dx, ld dy, ld r, ld dbt){	
	lint s = ld(dbt) + 2;
	lint e = s - 4;
	for(ld t = s; t>=e; t--)
		if(inCircle(x,y,dx,dy,r, t)) return {true,t};
	return {false, -1};
}


vector<lint> intersection(ld x, ld y, ld dx, ld dy, ld r){
	vector<lint> answer;
	
	ld a = (dx*dx + dy*dy);
	ld b = (2ll*x*dx + 2ll*y*dy);
	ld c = -(r*r - x*x - y*y);
	ld delta = b*b - 4ll*a*c;
	
	if(delta < 0) return answer;
	if(delta == 0){
		ld t = ld(-b) / ld(2*a);
		auto left = firstInCircle(x,y,dx,dy,r,t);
		if(!left.first) return {};
		auto right = lastInCircle(x,y,dx,dy,r,t);
		if(!right.first) return {};
		answer = {left.second, right.second};
	}else{
		auto left = firstInCircle(x,y,dx,dy,r, ( ld(-b) - sqrtl((ld)delta))/ ld(2*a) );
		if(!left.first) return {};
		auto right = lastInCircle(x,y,dx,dy,r, (ld(-b) + sqrtl((ld)delta))/ ld(2*a) );
		if(!right.first) return {};		
		answer = {left.second, right.second};
	}
	if(answer[0] < 0) answer[0] = 0;
	if(answer[0] > answer[1]) answer = {};
	else if(answer.back() < 0) answer = {};
	
	return answer;
}

vector<ld> comprTime;

int main() {
	cin.tie(nullptr)->sync_with_stdio(false);
	comprTime = {-1};
	int n;
	lint r; cin>>n>>r;
	vector<vector<lint>> stars;
	for(int i=0; i<n; i++){
		lint x1, y1, x2, y2;
		cin>>x1>>y1>>x2>>y2;
		auto v = intersection(x1, y1, x2-x1, y2-y1, r);
		if(!v.empty()){
			stars.push_back(v);
			comprTime.push_back(v[0]);
			comprTime.push_back(v[1]);
		}
	}
	sort(comprTime.begin(), comprTime.end());
	comprTime.resize(distance(
		comprTime.begin(),
		unique(comprTime.begin(), comprTime.end())	
	));
	comprTime.push_back(comprTime.back()+1);
	
	vector<int> pref(comprTime.size());
	for(auto star : stars){
		int l = lower_bound(comprTime.begin(),comprTime.end(), star[0]) - comprTime.begin();
		int r = upper_bound(comprTime.begin(),comprTime.end(), star[1]) - comprTime.begin();
		pref[l]++;
		pref[r]--;
	}
	for(int i=1; i<int(comprTime.size()); i++)
		pref[i] += pref[i-1];
	cout<<*max_element(pref.begin(), pref.end())<<"\n";
	

	return 0;
}
/*
[  ]Leu o problema certo???
[  ]Ver se precisa de long long
[  ]Viu o limite dos fors (é n? é m?)
[  ]Tamanho do vetor, será que é 2e5 em vez de 1e5??
[  ]Testar sample
[  ]Testar casos de  borda
[  ]1LL no 1LL << i
[  ]Testar mod (é 1e9+7, mesmo?, será que o mod não ficou negativo?)
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...