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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#include<iostream>
#include<vector>
using namespace std;
int main()
{
    uint64_t n,X,Y;
    cin>>n>>X>>Y;

    uint64_t x1[n],y1[n],x2[n],y2[n];
    double x_sr=0,y_sr=0;
    for(uint64_t i=0;i<n;i++)
    {
        cin>>x1[i]>>y1[i]>>x2[i]>>y2[i];
        x_sr+=x1[i]; x_sr+=x2[i];
        y_sr+=y1[i]; y_sr+=y2[i];
    }
    x_sr/=(2*n); y_sr/=(2*n);
    //cout<<"x_sr: "<<x_sr<<endl;
    //cout<<"y_sr: "<<y_sr<<endl;

    //int64_t wartosc_pola[X][Y];
    vector< vector<int> > wartosc_pola;
    for(uint64_t i=0;i<X;i++)
    {
        wartosc_pola.push_back(vector<int>());
        for(uint64_t j=0;j<Y;j++)
        {
            wartosc_pola[i].push_back(0);
        }
    }

    vector<int> indeks_srodka;
    int64_t ile_max = 0;
    for(uint64_t i=0;i<n;i++)
    {
        int64_t x_max = max(x1[i],x2[i]);
        int64_t y_max = max(y1[i],y2[i]);
        int64_t x_min = min(x1[i],x2[i]);
        int64_t y_min = min(y1[i],y2[i]);
        //cout<<"cwelus nr: "<<i<<" otrzymuje: ";
        if(x_sr>=x_min && x_sr<=x_max &&
           y_sr>=y_min && y_sr<=y_max) ///wewnatrz prostokata
        {
            indeks_srodka.push_back(i);
            continue;
        }
        else if(x_sr>=x_min && x_sr<=x_max) ///pasek wertykalny
        {
            //cout<<"pasek wertykalny"<<endl;
            for(int64_t i=x_min;i<x_max;i++)
            {
                for(int64_t j=y_max;j<Y;j++)
                {
                    //cout<<"dodaje do pola:["<<i<<"]["<<j<<"]"<<endl;
                    wartosc_pola[i][j]++;
                }
            }
            for(int64_t i=x_min;i<x_max;i++)
            {
                for(int64_t j=0;j<y_min;j++)
                {
                    //cout<<"dodaje do pola:["<<i<<"]["<<j<<"]"<<endl;
                    wartosc_pola[i][j]++;
                }
            }
        }
        else if(y_sr>=y_min && y_sr<=y_max) ///pasek horyzontalny
        {
            //cout<<"pasek horyzontalny"<<endl;
            for(int64_t i=x_max;i<X;i++)
            {
                for(int64_t j=y_min;j<y_max;j++)
                {
                    //cout<<"dodaje do pola:["<<i<<"]["<<j<<"]"<<endl;
                    wartosc_pola[i][j]++;
                }
            }
            for(int64_t i=0;i<x_min;i++)
            {
                for(int64_t j=y_min;j<y_max;j++)
                {
                    //cout<<"dodaje do pola:["<<i<<"]["<<j<<"]"<<endl;
                    wartosc_pola[i][j]++;
                }
            }
        }
        else ///zewnatrz prostokata
        {
            //cout<<"zewnatrz"<<endl;
            for(int64_t i=0;i<X;i++)
            {
                for(int64_t j=0;j<Y;j++)
                {
                    if((i>=x_max&&j>=y_max)||(i>=x_max&&j<=y_min) ||
                       (i<=x_min&&j>=y_max)||(i<=x_min&&j<=y_min))
                    {
                        //cout<<"dodaje do pola:["<<i<<"]["<<j<<"]"<<endl;
                        wartosc_pola[i][j]++;
                    }
                }
            }
        }
        ile_max++;
        //cout<<endl;
    }
    //cout<<endl;

    for(uint64_t h=0; h<indeks_srodka.size(); h++)
    {
        int64_t x_max = max(x1[indeks_srodka[h]],x2[indeks_srodka[h]]);
        int64_t y_max = max(y1[indeks_srodka[h]],y2[indeks_srodka[h]]);
        int64_t x_min = min(x1[indeks_srodka[h]],x2[indeks_srodka[h]]);
        int64_t y_min = min(y1[indeks_srodka[h]],y2[indeks_srodka[h]]);
        int64_t pola_max_wew=0,pola_max_zew=0;
        for(int64_t i=x_min; i<x_max; i++)
        {
            for(int64_t j=y_min; j<y_max; j++)
            {
                if(wartosc_pola[i][j]==ile_max)
                {
                    pola_max_wew++;
                }
            }
        }
        for(int64_t i=0; i<X; i++)
        {
            for(int64_t j=0; j<Y; j++)
            {
                if((i>=x_max&&j>=y_max)||(i>=x_max&&j<y_min) ||
                        (i<x_min&&j>=y_max)||(i<x_min&&j<y_min))
                {
                    if(wartosc_pola[i][j]==ile_max)
                    {
                        pola_max_zew++;
                    }
                }
            }
        }
        if(pola_max_wew>pola_max_zew)
        {
            for(int64_t i=x_min; i<x_max; i++)
            {
                for(int64_t j=y_min; j<y_max; j++)
                {
                    wartosc_pola[i][j]++;
                }
            }
        }
        else
        {
            for(int64_t i=0; i<X; i++)
            {
                for(int64_t j=0; j<Y; j++)
                {
                    if((i>=x_max&&j>=y_max)||(i>=x_max&&j<y_min) ||
                            (i<x_min&&j>=y_max)||(i<x_min&&j<y_min))
                    {
                        wartosc_pola[i][j]++;
                    }
                }
            }
        }
    }

    uint64_t ans = 0;
    for(uint64_t i=0;i<X;i++)
    {
        for(uint64_t j=0;j<Y;j++)
        {
            if(wartosc_pola[i][j]==n)
            {
                //cout<<"zgadza sie pole["<<i<<"]["<<j<<"]"<<endl;
                ans++;
            }
        }
    }
    cout<<ans;

    return 0;
}