# Poj Solution 2528

```http://poj.org/problem?id=2528

//* @author: <strong>Yeming&nbsp;Hu</strong>&quot;cslittleye@gmail.com&quot;
import java.util.*;
import java.io.*;

public class Main
{
public static int N = 10000;

public static void main(String[] args)
{
Scanner sc = new Scanner(new BufferedInputStream(System.in));
Set< Integer> endpoints = new TreeSet< Integer>();
Segment[] segments = new Segment[N];
int t = sc.nextInt();
while(t-- > 0)
{
int n = sc.nextInt();
for(int i = 0; i < n; i++)
{
int s = sc.nextInt();
int e = sc.nextInt();
segments[i] = new Segment(s,e);
}
for(Integer endpoint : endpoints)
{
}
int result = 0;
for(int i = n-1; i >= 0; i--)
{
Segment seg = segments[i];
int left = seg.start;
int right = seg.end;
{
result++;
}
}
System.out.println(result);
}
}

public static boolean updateSegmentTree(int left, int right, Node current)
{
boolean result;
if(current.isCovered)
{
result = false;
}else
{
if(left == current.left && right == current.right)
{
current.isCovered = true;
result = true;
}else
{
int leftEnd = current.leftEnd;
int rightStart = current.rightStart;
if(right <= leftEnd)
{
}else if(left >= rightStart)
{
}else
{
result = (r1 || r2);
}
current.isCovered = (current.leftChild.isCovered && current.rightChild.isCovered);
}
}
return result;
}

public static Node buildSegmentTree(LinkedList< Node> current)
{
while(current.size() >= 2)
{
Node leftChild = current.removeFirst();
Node rightChild = current.removeFirst();
Node parent = new Node(leftChild.left,rightChild.right,leftChild.right,rightChild.left);
parent.leftChild = leftChild;
parent.rightChild = rightChild;
}
if(current.size() > 0)
{
}
if(next.size() >= 2)
{
return buildSegmentTree(next);
}else // it's the root left
{
return next.removeFirst();
}
}
}

class Node
{
int left;
int right;
int leftEnd;
int rightStart;
int mid;
Node parent;
Node leftChild;
Node rightChild;
boolean isCovered;

Node(int left, int right, int leftEnd, int rightStart)
{
this.left = left;
this.right = right;
this.leftEnd = leftEnd;
this.rightStart = rightStart;
this.parent = null;
this.leftChild = null;
this.rightChild = null;
this.isCovered = false;
}

}

class Segment
{
int start;
int end;

Segment(int s, int e)
{
this.start = s;
this.end = e;
}
}
```
This entry was posted in poj. Bookmark the permalink.