F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

InkBall FX

Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 74    Accepted Submission(s): 0


Problem Description
Recently, Jonathan is addicted to a game called InkBall FX.

The game goes on a plane coordinate system. On the first quadrant, there are some segments. The segments are all parallel to x-axis and they are pairwise disjoint. Two segments are disjoint if and only if they don’t have mutual point, including the end points. Therefore, we can use ($L_i,R_i,Y_i$) to note the $i^{th}$ segment, which means the segment starts from the position ($L_i,Y_i$) and ends in the position ($R_i,Y_i$).

There is an extremely small ball on the position (0,0). At the beginning, the speed of the ball in the horizontal direction is 1 per second, and that in the vertical direction is also 1 per second. If the ball is now at the position (x,y), then it will move to the position (x + t,y + t) after t seconds, if it does not touch the segment during this process.

When the ball hits any segment, a completely elastic collision occurs, which means the speed in vertical direction will be reversed and that in the horizontal direction will remain the same, since the segments are parallel to x-axis. After the collision, the segment will disappear, which means it cannot be collided twice.

If the ball hits the ends of the segment, the collision still occurs like what’s mentioned before.

Jonathan is curious about how many segments the ball could hit, but the ball moves too slow. Please write a program to help him to get the answer quickly.
 

Input
The first line contains one integer T (1 ≤ T ≤ 10) denoting the count of testcase.

For each testcase,

The first line contains one integer n (1 ≤ n ≤ $10^5$), representing the number of segments.

Then n lines follow. The i-th line contains three integers $L_i,R_i,Y_i$ (1 ≤ $L_i,R_i,Y_i$ ≤ $10^9,L_i < R_i$), representing the i-th segment.
 

Output
For each testcase, one line with an integer x - times that collision occurred.
 

Sample Input
2 3 4 6 1 2 4 3 5 6 3 2 3 4 1 1 2 2
 

Sample Output
2 2
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2025 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.001001(s) query 1, Server time : 2025-02-17 17:45:37, Gzip enabled