Polycarp's New Job (Codeforces 1101E)
Tags: Implement, implementation

Polycarp has recently got himself a new job. He now earns so much that his old wallet can't even store all the money he has.Berland bills somehow come in lots of different sizes. However, all of them are shaped as rectangles (possibly squares). All wallets are also produced in form of rectangles (possibly squares).A bill $$$x \times y$$$ fits into some wallet $$$h \times w$$$ if either $$$x \le h$$$ and $$$y \le w$$$ or $$$y \le h$$$ and $$$x \le w$$$. Bills can overlap with each other in a wallet and an infinite amount of bills can fit into a wallet. That implies that all the bills Polycarp currently have fit into a wallet if every single one of them fits into it independently of the others.Now you are asked to perform the queries of two types:  $$$+~x~y$$$ — Polycarp earns a bill of size $$$x \times y$$$;  $$$?~h~w$$$ — Polycarp wants to check if all the bills he has earned to this moment fit into a wallet of size $$$h \times w$$$. It is guaranteed that there is at least one query of type $$$1$$$ before the first query of type $$$2$$$ and that there is at least one query of type $$$2$$$ in the input data.For each query of type $$$2$$$ print "YES" if all the bills he has earned to this moment fit into a wallet of given size. Print "NO" otherwise.

Input: The first line contains a single integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^5$$$) — the number of queries.Each of the next $$$n$$$ lines contains a query of one of these two types:  $$$+~x~y$$$ ($$$1 \le x, y \le 10^9$$$) — Polycarp earns a bill of size $$$x \times y$$$;  $$$?~h~w$$$ ($$$1 \le h, w \le 10^9$$$) — Polycarp wants to check if all the bills he has earned to this moment fit into a wallet of size $$$h \times w$$$. It is guaranteed that there is at least one query of type $$$1$$$ before the first query of type $$$2$$$ and that there is at least one query of type $$$2$$$ in the input data.

Output: For each query of type $$$2$$$ print "YES" if all the bills he has earned to this moment fit into a wallet of given size. Print "NO" otherwise.

Note: The queries of type $$$2$$$ of the example:  Neither bill fits;  Both bills fit (just checking that you got that bills can overlap);  Both bills fit (both bills are actually the same);  All bills fit (too much of free space in a wallet is not a problem);  Only bill $$$1 \times 5$$$ fit (all the others don't, thus it's "NO"). 

Sample Inputs:
9
+ 3 2
+ 2 3
? 1 20
? 3 3
? 2 3
+ 1 5
? 10 10
? 1 5
+ 1 1

Sample Outputs:
NO
YES
YES
YES
NO

Solution (Python):
import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())

def main():
    query_num = int(input())
    (max_x, max_y) = (0, 0)
    for _ in range(query_num):
        (sym, ca, cb) = input().split()
        if sym == '+':
            (x, y) = (int(ca), int(cb))
            if x > y:
                (x, y) = (y, x)
            max_x = max(x, max_x)
            max_y = max(y, max_y)
        elif sym == '?':
            (h, w) = (int(ca), int(cb))
            if h > w:
                (h, w) = (w, h)
            if h >= max_x and w >= max_y:
                print('YES')
            else:
                print('NO')
if __name__ == '__main__':
    main()

Solution (Python):
import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())

def main():
    query_num = int(input())
    (max_x, max_y) = (0, 0)
    for _ in range(query_num):
        (sym, ca, cb) = input().split()
        if sym == '+':
            (x, y) = (int(ca), int(cb))
            if x > y:
                (x, y) = (y, x)
            max_x = max(x, max_x)
            max_y = max(y, max_y)
        elif sym == '?':
            (h, w) = (int(ca), int(cb))
            if h > w:
                (h, w) = (w, h)
            if h >= max_x and w >= max_y:
                print('YES')
            else:
                print('NO')
if __name__ == '__main__':
    main()

Solution (Python):
(x, y) = (0, 0)
s = []

def solve():
    (c, a, b) = input().split()
    a = int(a)
    b = int(b)
    global x
    global y
    if a > b:
        (a, b) = (b, a)
    if c == '+':
        if x < a:
            x = a
        if y < b:
            y = b
    elif x <= a and y <= b:
        s.append('YES')
    else:
        s.append('NO')
t = int(input())
for i in range(t):
    solve()
print('\n'.join(s))