SOLVE

LATER

Area of Union of Rectangles

Problem

Editorial

Analytics

Given **N** rectangles in an infinite 2-D plane. Find the area of union of rectangles.

**Input Format**

First line contains an integer **N** denoting number of rectangles. Next **N** line contains four integers separated by a space denoting **X1, Y1, X2 and Y2** respectively where **(X1, Y1)** denotes lower left coordinate of rectangle and **(X2, Y2)** denotes upper right coordinate of rectangle.

**Output Format**

In a single line print area of union of all **N** rectangles.

**Constraints**

1 ≤ **N** ≤ 100

0 ≤ **X1** < **X2** ≤ 1000

0 ≤ **Y1** < **Y2** ≤ 1000

Explanation

Area of 1^{st} rectangle = 2 × 2 = 4

Area of 2^{nd} rectangle = 2 × 3 = 6

Area of 3^{rd} rectangle = 1 × 1 = 1

Area of intersection of 1^{st} and 2^{nd} rectangle = 1 × 1 = 1

Area of union of rectangles = Summation of area of all 3 rectangles - Area of intersection of rectangles

Area of union of rectangles = 4 + 6 + 1 - 1 = 10

Time Limit:
1.0 sec(s)
for each input file.

Memory Limit:
256 MB

Source Limit:
1024 KB

Marking Scheme:
Marks are awarded when all the testcases pass.

Allowed Languages:
C,
C++,
C++14,
Clojure,
C#,
D,
Erlang,
F#,
Go,
Groovy,
Haskell,
Java,
Java 8,
JavaScript(Rhino),
JavaScript(Node.js),
Julia,
Lisp,
Lisp (SBCL),
Lua,
Objective-C,
OCaml,
Octave,
Pascal,
Perl,
PHP,
Python,
Python 3,
R(RScript),
Racket,
Ruby,
Rust,
Scala,
Swift,
Visual Basic,
Kotlin

Initializing Code Editor...

{"7a76ddc": "/pagelets/suggested-problems/algorithm/area-of-union-of-rectangles/", "7a76df3": "/pagelets/problem-author-tester/algorithm/area-of-union-of-rectangles/", "7a76e1e": "/pagelets/recommended-problems/algorithm/area-of-union-of-rectangles/", "7a76e09": "/pagelets/problems-hint/algorithm/area-of-union-of-rectangles/", "7a76dbc": "/pagelets/show-submission/algorithm/area-of-union-of-rectangles/"}

{}

realtime.hackerearth.com

80

11b58564ec5bfc9522cf0149e80dcf083b954da1

58a29e5cae2309f04b28

/realtime/pusher/auth/