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,
Kotlin,
Lisp,
Lisp (SBCL),
Lua,
Objective-C,
OCaml,
Octave,
Pascal,
Perl,
PHP,
Python,
Python 3,
R(RScript),
Racket,
Ruby,
Rust,
Scala,
Swift,
Visual Basic

Initializing Code Editor...

{"4d3dc90": "/pagelets/suggested-problems/algorithm/area-of-union-of-rectangles/", "d1e47fb": "/pagelets/problem-author-tester/algorithm/area-of-union-of-rectangles/", "0bbd4c1": "/pagelets/show-submission/algorithm/area-of-union-of-rectangles/", "52a0445": "/pagelets/recommended-problems/algorithm/area-of-union-of-rectangles/", "d07a61d": "/pagelets/problems-hint/algorithm/area-of-union-of-rectangles/"}

realtime.hackerearth.com

80

11b58564ec5bfc9522cf0149e80dcf083b954da1

58a29e5cae2309f04b28

/realtime/pusher/auth/