forked from Anmol2307/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNICEDAY.cpp
63 lines (54 loc) · 1.17 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
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
struct Triple {
int a;
int b;
int c;
Triple () :
a(0),
b(0),
c(0) {
}
};
bool comparator (Triple x, Triple y) {
return x.a > y.a;
}
const int maxN = 100000 + 7;
int n;
int tree[maxN];
Triple results[maxN];
#define max(a, b) (a > b ? a : b)
void update (int pos, int delta) {
for( ; pos < n; ++pos)
tree[pos] = max(tree[pos], delta);
}
int query (int pos) {
int ans = -1;
for( ; pos >= 0; pos = (pos & (pos + 1)) - 1)
ans = max(tree[pos], ans);
return ans;
}
int main () {
int test_case;
scanf("%d", &test_case);
while(test_case--) {
scanf("%d", &n);
for(int i = 0; i < n; ++i) {
scanf("%d%d%d", &results[i].a, &results[i].b, &results[i].c);
--results[i].a; --results[i].b; --results[i].c;
results[i].b = n - results[i].b - 1;
}
std::memset(tree, -1, sizeof(tree));
std::sort(results, results + n, comparator);
int answer = 0;
for(int i = 0; i < n; ++i) {
if(query(results[i].b - 1) > results[i].c)
++answer;
update(results[i].b, results[i].c);
}
printf("%d\n", n - answer);
}
return 0;
}