#P6214. 「SWTR-4」Taking a Walk

    ID: 6916 远端评测题 1000~2500ms 128~256MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>计算几何线段树Special JudgeO2优化可持久化线段树可持久化

「SWTR-4」Taking a Walk

Background

Little A likes taking a walk in the square.

Once, while Little A was walking, he was thinking too deeply and accidentally ran into a utility pole.

So this problem came out (of course, it is fake).

Problem Description

Little A and his friend Little Y are standing on a plane. Their initial coordinates are (Ax0,Ay0)(Ax_0,Ay_0) and (Bx0,By0)(Bx_0,By_0), respectively.

Of course, standing still is too boring, so they will keep moving.

More precisely, Little A makes a total of nn moves, and Little Y makes a total of mm moves.

From time Ati1At_{i-1} to time AtiAt_i, Little A moves from (Axi1,Ayi1)(Ax_{i-1},Ay_{i-1}) to (Axi,Ayi)(Ax_i,Ay_i) with uniform linear motion.

From time Bti1Bt_{i-1} to time BtiBt_i, Little Y moves from (Bxi1,Byi1)(Bx_{i-1},By_{i-1}) to (Bxi,Byi)(Bx_i,By_i) with uniform linear motion.

  • At0=Bt0=0At_0=Bt_0=0.

Little A also has qq queries. Each query gives a floating-point number cc and an integer ff, asking you to find the time when their distance is cc for the ff-th time.

  • Special case: if there are infinitely many times when their distance is cc, output -2.33.

  • Special case: if ff is greater than the number of times their distance is cc, output -4.66.

  • Otherwise, output the time when their distance is cc for the ff-th time.

Input Format

The first line contains three integers n,m,qn,m,q, where nn is the number of moves of Little A, mm is the number of moves of Little Y, and qq is the number of queries.

The second line contains four floating-point numbers with two decimal places Ax0,Ay0,Bx0,By0Ax_0,Ay_0,Bx_0,By_0, representing the initial coordinates of Little A and Little Y.

The next nn lines: the ii-th line contains three floating-point numbers with two decimal places Axi,Ayi,AtiAx_i,Ay_i,At_i, as described above.

The next mm lines: the ii-th line contains three floating-point numbers with two decimal places Bxi,Byi,BtiBx_i,By_i,Bt_i, same as above.

The next qq lines: each line contains a floating-point number with two decimal places cc and an integer ff, describing a query.

Output Format

Output qq floating-point numbers in total, representing the answer to each query.

3 3 10
0.00 0.00 0.00 1.00
-1.00 -1.00 0.20
10.00 10.00 0.41
-4.56 -1.23 1.00
-2.00 -1.00 0.40
-10.00 -10.00 0.41
9.87 6.54 1.00
0.00 1
1.00 1
5.00 1
5.00 3
5.00 4
10.00 2
10.00 6
28.28 1
28.28 2
28.29 1
-4.66
-2.33
0.26970954
0.83836048
-4.66
0.65792852
-4.66
0.40999665
0.41005730
-4.66

Hint

Special Judge

This problem uses Special Judge.

If the relative error or absolute error between your output and the correct answer is at most 10710^{-7}, you will get full score for that test point. Otherwise, you will get no score. It is recommended to output at least 88 digits after the decimal point.

Please do not output any numbers other than what the problem asks for, otherwise you may get UKE.

It is guaranteed that there is no case where the answer is 00.

The SPJ is as follows:

#include "testlib.h"
#define double long double
const double eps=1e-7;
bool Equal(double x,double y){
	return abs(x-y)<=eps||abs((x-y)/y)<=eps;
}
int main(int argc, char* argv[]){
    registerTestlibCmd(argc, argv);
    int n=inf.readInt(),m=inf.readInt(),q=inf.readInt();
    for(int i=1;i<=q;i++){
    	double x=ouf.readDouble(),y=ans.readDouble();
    	if(!Equal(x,y))quitf(_wa,"On line %d the answer is wrong: expected = %.8LF, found = %.8LF",i,y,x);
	}
	quitf(_ok, "The answer is correct."); 
	return 0;
}

Constraints and Notes

This problem uses bundled testdata.

Subtask ID n,mn,m\leq qq\leq Score
11 5×1025\times 10^2 10310^3 1010
22 2×1042\times 10^4 2020
33 4×1044\times 10^4 5×1045\times 10^4 3030
44 8×1048\times 10^4 3×1053\times 10^5 4040

For 100%100\% of the data, 1n,m8×1041\leq n,m\leq 8\times 10^4, 1q3×1051\leq q\leq 3\times 10^5, Atn=Btm6×104At_n=Bt_m\leq 6\times 10^4, 1fm+n1\leq f\leq m+n, 0c3×1040\leq c\leq 3\times 10^4.

To ensure accuracy on extreme testdata, the absolute value of all coordinates is at most 10410^4.

It is guaranteed that Ati<Ati+1At_i<At_{i+1} and Bti<Bti+1Bt_i<Bt_{i+1}. The duration of a single move is at most 6×1026\times 10^2. It is not guaranteed that a move actually changes the position.

Please pay attention to precision errors.

Time & Memory Limits

For Subtask 11, the time limit is 1s\rm{1s}, and for the other subtasks the time limit is 2.5s\rm{2.5s}.

For Subtask 11, the memory limit is 128MB\rm{128MB}, and for the other subtasks the memory limit is 256MB\rm{256MB}.

To eliminate incorrect solutions, the setter shortened the time limit, but it is still more than 22 times that of the std.

The std is slightly tight on constants. Please pay attention to I/O and constant-factor optimizations.

This problem enables automatic O2 optimization.

Source

Sweet Round 04 F.
Idea & std: Alex_Wei

Translated by ChatGPT 5