Advertisement blocking software were detected ;( Please add this webpage to whitelist.

NICEDAY - The day of the competitors

The International Olympiad in Informatics is coming and the leaders of the Vietnamese Team have to choose the best contestants all over the country. Fortunately, the leaders could choose the members of the team among N very good contestants, numbered from 1 to N (3 ≤ N ≤ 100000). In order to select the best contestants the leaders organized three competitions. Each of the N contestants took part in all three competitions and there were no two contestants with equal results on any of the competitions. We say that contestant А is better than another contestant В when А is ranked before В in all of the competitions. A contestant A is said to be excellent if no other contestant is better than A. The leaders of the Vietnamese Team would like to know the number of excellent contestants.


First line of the input contains an integer t (1 ≤ t ≤ 10 ), equal to the number of testcases. Then descriptions of t testcases follow. First line of description contains the number of competitors N . Each of the next N lines describes one competitor and contains integer numbers ai, bi, ci (1 ≤ ai, bi , ci ≤ N ) separated by spaces, the order of i-th competitor's ranking in the first competition , the second competition and the third competition.


For each test case in the input your program should output the number of excellent contestants in one line.

Note : Because the input is too large so we have 4 input files and the total time limit is 4s ( not 1s ).


1 2 3
2 3 1
3 1 2


hide comments
(Tjandra Satria Gunawan)(曾毅昆): 2015-08-19 15:01:58

Awesome problem (^_^) think asymmetrically to solve this :)

sai krishna: 2015-03-27 04:02:27

cant understand the qusetion itself
can any one please explain

californiagurl: 2015-01-31 12:44:34

any tricky testcase?

S: 2015-01-26 19:13:55

only BIT .. learnt a lot seriously .. :D

Anowar Hossain Anu: 2014-09-24 10:28:47


Luis Manuel D�az Bar�n: 2014-05-16 21:25:54

the problem statement is awful it should be corrected, I needed to read comments to realize what it really means.

aristofanis: 2013-12-09 20:37:35

Getting 100 in NKTEAM and WA here, whats wrong?

Fahmi: 2012-06-25 00:44:41

Last edit: 2012-11-19 04:09:25
Anand: 2012-05-27 05:11:39

if you think of the last condition, solution is on its way.

つ ◕_◕ ༽つ GIFF AC: 2011-10-30 08:07:49

you're wrong.
A is not excellent constestant if there exists 1 another constestant B score higher than A in ALL 3 competitions.
A=excellent constestant if A!=not excellent constestant.
Read the example again you'll see that the answer is 3.

Added by:Nguyen Minh Hieu
Time limit:0.109s
Source limit:10000B
Memory limit:1536MB
Cluster: Cube (Intel Pentium G860 3GHz)
Languages:All except: ERL JS NODEJS PERL 6
Resource:Base on a problem from BOI