forked from Shubham28/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNICEDAY.cpp
124 lines (102 loc) · 1.87 KB
/
NICEDAY.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include <vector>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <set>
#include <numeric>
#define FOR(A,B,C) for(int A=B;A<C;A++)
#define EFOR(A,B,C) for(int A=B;A<=C;A++)
#define RFOR(A,B,C) for(int A=B;A>=C;A--)
#define MEM(A,B) memset(A,B,sizeof(A))
#define PB(A,B) A.push_back(B);
#define SZ(A) int(A.size())
using namespace std;
#define MAXX 11000000
char *ipos, *opos, InpFile[MAXX], OutFile[100], DIP[30];
inline int InpInt(int flag=0)
{
while(*ipos<=32) ++ipos;
if (flag) return (*ipos++ - '0');
int x=0,neg=0;
char c;
while(true){
c=*ipos++;
if(c=='-') neg=1;
else {
if(c<=32) return (neg?-x:x);
x=(x<<1)+(x<<3)+(c-'0');
}
}
}
inline void Outp(int x)
{
int y;
int dig=0;
while(x || !dig){
y=x/10;
DIP[dig++]=x-((y<<3)+(y<<1))+'0';
x=y;
}
while(dig--) *opos++=DIP[dig];
}
inline void InitFASTIO()
{
ipos=InpFile; opos=OutFile;
fread(InpFile,MAXX,1,stdin);
}
inline void FlushFASTIO()
{
fwrite(OutFile,opos-OutFile,1,stdout);
}
struct cord{
int x,y,z;
bool operator< (const cord& tmp) const
{ return x<tmp.x; }
};
cord plr[100001];
int N;
bool cmpz(const cord &fr,const cord &sc)
{ return fr.z<sc.z; }
int main()
{
InitFASTIO();
int T;
set<cord>bndr;
set<cord>::iterator it;
T=InpInt();
while(T--){
N=InpInt();
FOR(i,0,N)
plr[i].x=InpInt(),plr[i].y=InpInt(),plr[i].z=InpInt();
sort(plr,plr+N,cmpz);
int ans=1;
bndr.clear();
bndr.insert(plr[0]);
FOR(ck,1,N){
it=bndr.lower_bound(plr[ck]);
if(it!=bndr.begin()){
it--;
if((*it).y<plr[ck].y)
continue;
it++;
}
ans++;
vector< set<cord>::iterator >rem;
for(;it!=bndr.end();it++){
if((*it).y>plr[ck].y){
PB(rem,it);
} else
break;
}
FOR(dl,0,SZ(rem))
bndr.erase(rem[dl]);
bndr.insert(plr[ck]);
}
Outp(ans);
*opos++='\n';
}
FlushFASTIO();
return 0;
}