147222025-01-29 21:46:55GervidForma-1cpp17Hibás válasz 0/100677ms94260 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';
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
subtask10/0
1Elfogadva1ms316 KiB
subtask20/20
2Hibás válasz78ms6156 KiB
3Hibás válasz81ms6156 KiB
4Hibás válasz79ms6152 KiB
5Hibás válasz78ms6156 KiB
6Elfogadva81ms6208 KiB
7Elfogadva79ms6156 KiB
8Elfogadva79ms6160 KiB
9Elfogadva79ms6156 KiB
subtask30/30
10Hibás válasz381ms29748 KiB
11Hibás válasz430ms32312 KiB
12Hibás válasz337ms23348 KiB
13Hibás válasz497ms36404 KiB
14Hibás válasz485ms39476 KiB
15Hibás válasz501ms41524 KiB
16Hibás válasz523ms42804 KiB
17Hibás válasz537ms43828 KiB
18Elfogadva560ms48436 KiB
subtask40/50
19Hibás válasz470ms36404 KiB
20Hibás válasz519ms37940 KiB
21Hibás válasz402ms28468 KiB
22Hibás válasz565ms41524 KiB
23Hibás válasz554ms44084 KiB
24Hibás válasz564ms45880 KiB
25Hibás válasz591ms47156 KiB
26Hibás válasz603ms48436 KiB
27Hibás válasz677ms94260 KiB
28Elfogadva629ms53188 KiB
29Elfogadva620ms51336 KiB
30Elfogadva559ms46132 KiB