Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <set>
- #include <algorithm>
- using namespace std;
- /*
- Note for reading ugly variable names more easily:
- kx stands for "small x" i.e. the left side,
- nx stands for "large x" i.e. the right side
- and ky and ny are similarly the bottom and top.
- (Abbreviated in Hungarian, my native language...)
- */
- int N;
- vector<int> X;
- vector<int> Y;
- struct Rect
- {
- int kx, ky, nx, ny;
- };
- Rect R[1000];
- int main()
- {
- ios::sync_with_stdio(false);
- cin >> N;
- set<int> sx;
- set<int> sy;
- for (int i = 0; i < N; i++)
- {
- cin >> R[i].kx >> R[i].ny >> R[i].nx >> R[i].ky;
- sx.insert(R[i].kx); sx.insert(R[i].nx);
- sy.insert(R[i].ky); sy.insert(R[i].ny);
- }
- for (int x : sx)
- {
- X.push_back(x);
- }
- for (int y : sy)
- {
- Y.push_back(y);
- }
- bool M[X.size()-1][Y.size()-1];
- for (int i = 0; i < X.size()-1; i++)
- for (int j = 0; j < Y.size()-1; j++)
- M[i][j] = false;
- long long S = 0;
- for (Rect r : R)
- {
- int ki = (lower_bound(X.begin(), X.end(), r.kx) - X.begin());
- int ni = (lower_bound(X.begin(), X.end(), r.nx) - X.begin());
- int kj = (lower_bound(Y.begin(), Y.end(), r.ky) - Y.begin());
- int nj = (lower_bound(Y.begin(), Y.end(), r.ny) - Y.begin());
- for (int i = ki; i < ni; i++)
- {
- for (int j = kj; j < nj; j++)
- {
- if (!M[i][j])
- {
- M[i][j] = true;
- S += ((long long)(X[i+1]-X[i]))*(Y[j+1]-Y[j]);
- }
- }
- }
- }
- cout << S << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement