forked from pranavanurag/SPOJSolutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPOSTERS.cpp
More file actions
74 lines (67 loc) · 1.05 KB
/
Copy pathPOSTERS.cpp
File metadata and controls
74 lines (67 loc) · 1.05 KB
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
#include <iostream>
#include <set>
using namespace std;
int Lazy[40000001];
void Refresh()
{
for (int i = 0; i <= 40000000; i++)
Lazy[i] = 0;
}
void Update(int i, int STx1, int STx2, int x1, int x2, int V)
{
if (Lazy[i])
{
if (STx1 != STx2)
{
Lazy[2*i] = Lazy[2*i + 1] = Lazy[i];
Lazy[i] = 0;
}
}
if (STx1 > STx2 || x1 > x2 || STx1 > x2 || STx2 < x1)
return;
if (STx1 >= x1 && STx2 <= x2)
Lazy[i] = V;
else
{
int STxm = (STx1 + STx2)/2;
Update(2*i, STx1, STxm, x1, x2, V);
Update(2*i + 1, STxm + 1, STx2, x1, x2, V);
}
}
set <int> S;
void Count(int i, int STx1, int STx2)
{
if (Lazy[i])
{
S.insert(Lazy[i]);
return;
}
if (STx1 >= STx2)
return;
else
{
int STxm = (STx1 + STx2)/2;
Count(2*i, STx1, STxm);
Count(2*i + 1, STxm + 1, STx2);
}
}
int main()
{
ios::sync_with_stdio(false);
int T, N, L, R;
cin>>T;
while (T--)
{
cin>>N;
Refresh();
for (int i = 1; i <= N; i++)
{
cin>>L>>R;
Update(1, 1, 10000000, L, R, i);
}
S.clear();
Count(1, 1, 10000000);
cout<<S.size()<<endl;
}
return 0;
}