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
#include "cstdio"
#include "vector"
#include "algorithm"
#define xmin first.first
#define xmax first.second
#define ymin second.first
#define ymax second.second
#define gc getchar_unlocked
void scanint(long long &x)
{
    register long long c = gc();
    x = 0;
    unsigned long long neg = 0;
    for(;((c<48 || c>57) && c != '-');c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}
using namespace std;
long long n,x1,x2,yy1,y2,w,k,x,y;
pair <pair<long long,long long>,pair<long long,long long> > tab[100005],wyn[100005];
bool czyzby[100005],ok;
int main()
{
	scanint (n);
	for (int i=0; i<n; i++)
	{
		scanint (x1);
		scanint (x2);
		scanint (yy1);
		scanint (y2);
		tab[i].xmin=min(x1,x2);
		tab[i].xmax=max(x1,x2);
		tab[i].ymin=min(yy1,y2);
		tab[i].ymax=max(yy1,y2);
	}
	
	while (1)
	{
		ok=false;
		for (int i=0; i<n; i++)
		{
			for (int j=0; j<n; j++)
			{
				if (i!=j && !czyzby[i] && !czyzby[j])
				{
					x=min(tab[i].xmax,tab[j].xmax)-max(tab[i].xmin,tab[j].xmin);
					y=min(tab[i].ymax,tab[j].ymax)-max(tab[i].ymin,tab[j].ymin);
					
					if (x>0 && y>0)
					{
						tab[i].xmin=min(tab[i].xmin,tab[j].xmin);
						tab[i].xmax=max(tab[i].xmax,tab[j].xmax);
						tab[i].ymin=min(tab[i].ymin,tab[j].ymin);
						tab[i].ymax=max(tab[i].ymax,tab[j].ymax);
						czyzby[j]=true;
						ok=true;
					}
				}
			}
		}
		
		if (!ok) break;
	}
	
	for (int i=0; i<n; i++)
	{
		if (!czyzby[i]) 
		{
			wyn[k].xmin=tab[i].xmin;
			wyn[k].xmax=tab[i].xmax;
			wyn[k].ymin=tab[i].ymin;
			wyn[k].ymax=tab[i].ymax;
			k++;
		}
	}
	sort (wyn, wyn+k);
	printf ("%lld\n", k);
	for (int i=0; i<k; i++) printf ("%lld %lld %lld %lld\n", wyn[i].xmin, wyn[i].xmax, wyn[i].ymin, wyn[i].ymax);
	
	return 0;
}