147352025-01-30 11:48:49GervidForma-1cpp17Hibás válasz 0/100688ms94352 KiB
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <limits.h>
#include <algorithm>
#include <math.h>
#include <array>

using ll = long long;
using namespace std;

struct OT
{
	double t;
	ll slow, fast;

	const bool operator<(const OT other) const
	{
		if (t != other.t) return t < other.t;
		else if (slow != other.slow) return slow > other.slow;
		else return fast < other.fast;
	}
};

vector<double> roots(array<ll, 3> coeffs, ll i = -1, ll j = -1) //the real ones
{
	ll d = coeffs[1] * coeffs[1] - 4 * coeffs[0] * coeffs[2];
	if (d < 0) return {};
	double sqd = sqrt(d);
	double plusd = (-static_cast<double>(coeffs[1]) + sqd) / static_cast<double>(2 * coeffs[0]);
	if (d == 0) return { (-static_cast<double>(coeffs[1]) + sqd) / static_cast<double>(2 * coeffs[0]) };

	double minusd = (-static_cast<double>(coeffs[1]) - sqd) / static_cast<double>(2 * coeffs[0]);
	return { (-static_cast<double>(coeffs[1]) + sqd) / static_cast<double>(2 * coeffs[0]),
		(-static_cast<double>(coeffs[1]) - sqd) / static_cast<double>(2 * coeffs[0]) };
}


vector<array<ll, 3>> queries;
vector<OT> overtakes; //on which T, slower car, faster car, late
vector<ll> order;
vector<ll> carsbyid;
int nextovertakeidx = 0;

void ff(int t)
{
	while (nextovertakeidx < overtakes.size() && overtakes[nextovertakeidx].t < t) //update order up until t
	{
		if (carsbyid[overtakes[nextovertakeidx].slow] < carsbyid[overtakes[nextovertakeidx].fast])
		{
			swap(order[carsbyid[overtakes[nextovertakeidx].slow]], order[carsbyid[overtakes[nextovertakeidx].fast]]);
			swap(carsbyid[overtakes[nextovertakeidx].slow], carsbyid[overtakes[nextovertakeidx].fast]);
		}
		nextovertakeidx++;
	}
	int sortid = nextovertakeidx;
	while (sortid < overtakes.size() && overtakes[sortid].t == t) //sort overtakes on t by id
	{
		if (carsbyid[min(overtakes[sortid].slow, overtakes[sortid].fast)] > carsbyid[max(overtakes[sortid].slow, overtakes[sortid].fast)])
		{
			swap(order[carsbyid[overtakes[sortid].slow]], order[carsbyid[overtakes[sortid].fast]]);
			swap(carsbyid[overtakes[sortid].slow], carsbyid[overtakes[sortid].fast]);
		}
		sortid++;
	}
}

int main()
{
	iostream::sync_with_stdio(0);
	cin.tie(0);

	int n, i, j, q;
	cin >> n;

	vector<array<ll, 3>> cars(n);
	for (array<ll, 3>& in : cars) cin >> in[0] >> in[1] >> in[2];

	cin >> q;

	overtakes.reserve(n / 2 * n);

	for (i = 0; i < n; i++)
	{
		for (j = i+1; j < n; j++)
		{
			vector<double> rv = roots({ cars[i][0] - cars[j][0], cars[i][1] - cars[j][1], cars[i][2] - cars[j][2] });
			for (double r : rv)
			{
				if (0 < r && r <= 1e6)
				{
					if (r*cars[i][0]*2+cars[i][1] < r*cars[j][0]*2+cars[j][1])
						overtakes.push_back({ r, i, j });
					else
						overtakes.push_back({ r, j, i });
				}
				if (r == 0) //no derivative here
				{
					if (1e-7*cars[i][0]*2+cars[i][1] < 1e-7*cars[j][0]*2+cars[j][1])
						overtakes.push_back({ r, i, j });
					else
						overtakes.push_back({ r, j, i });
				}
			}
		}
	}

	sort(overtakes.begin(), overtakes.end());

	order.resize(n);
	vector<array<ll, 2>> cs(n);
	for (i = 0; i < n; i++) cs[i] = { cars[i][2], -i };
	sort(cs.begin(), cs.end());

	carsbyid.resize(n);
	for (i = 0; i < n; i++) order[i] = -cs[n-i-1][1], carsbyid[order[i]] = i;

	queries.resize(q); // time, place, idx
	for (i = 0; i < q; i++)
	{
		queries[i][2] = i,
		cin >> queries[i][1] >> queries[i][0];
		queries[i][1]--;
	}
	sort(queries.begin(), queries.end());

	vector<int> out(q);
	for (i = 0; i < q; i++)
	{
		ff(queries[i][0]);
		out[queries[i][2]] = order[queries[i][1]];
	}

	for (i = 0; i < q; i++) cout << out[i] + 1 << '\n';
}

//3
//2 3 1
//2 3 1
//2 3 1
//5
//1 0      
//2 0
//1 10
//3 500000
//2 999999
RészfeladatÖsszpontTesztVerdiktIdőMemória
subtask10/0
1Elfogadva1ms316 KiB
subtask20/20
2Hibás válasz81ms6196 KiB
3Hibás válasz82ms6156 KiB
4Hibás válasz81ms6196 KiB
5Hibás válasz79ms6100 KiB
6Elfogadva82ms6152 KiB
7Elfogadva81ms6164 KiB
8Elfogadva79ms6196 KiB
9Elfogadva79ms6164 KiB
subtask30/30
10Hibás válasz412ms29748 KiB
11Hibás válasz435ms32308 KiB
12Hibás válasz342ms23420 KiB
13Hibás válasz495ms36444 KiB
14Hibás válasz492ms39476 KiB
15Hibás válasz518ms41508 KiB
16Hibás válasz533ms42660 KiB
17Hibás válasz547ms43824 KiB
18Elfogadva573ms48560 KiB
subtask40/50
19Hibás válasz504ms36404 KiB
20Hibás válasz527ms37940 KiB
21Hibás válasz407ms28468 KiB
22Hibás válasz561ms41524 KiB
23Hibás válasz560ms44084 KiB
24Hibás válasz586ms45920 KiB
25Hibás válasz600ms47316 KiB
26Hibás válasz601ms48436 KiB
27Hibás válasz688ms94352 KiB
28Elfogadva654ms53276 KiB
29Elfogadva629ms51252 KiB
30Elfogadva554ms46132 KiB