E. Polycarp’s New Job
time limit per test3 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
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×yfits into some wallet h×wif either x≤h and y≤w or y≤h and x≤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×y;
? h w— Polycarp wants to check if all the bills he has earned to this moment fit into a wallet of size h×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 2in the input data.
For each query of type 2print “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≤n≤5⋅105) — the number of queries.
Each of the next nlines contains a query of one of these two types:+ x y
(1≤x,y≤109) — Polycarp earns a bill of size x×y; ? h w(1≤h,w≤109) — Polycarp wants to check if all the bills he has earned to this moment fit into a wallet of size h×w.
It is guaranteed that there is at least one query of type 1before the first query of type 2and that there is at least one query of type 2in the input data.
Output
For each query of type 2print “YES” if all the bills he has earned to this moment fit into a wallet of given size. Print “NO” otherwise.
Example
Input
9
+3 2
+2 3
? 1 20
? 3 3
? 2 3
+1 5
? 10 10
? 1 5
+1 1
Output
NO
YES
YES
YES
NO
#include<stdio.h>
#include<algorithm>
#include<iostream>
using namespace std;
#define N 500010
int main(){
long long n,i,j,x[N]={0},y[N]={0},a,b;
char ch[N]={0};
scanf("%lld",&n);
getchar();
long long max1=0,max2=0;
for(i=0;i<n;i++){
scanf("%c %lld %lld",&ch[i],&x[i],&y[i]);
getchar();
if(ch[i]=='+'){
a=min(x[i],y[i]);
b=max(x[i],y[i]);
if(a>max1) max1=a;
if(b>max2) max2=b;
}
if(ch[i]=='?'){
if((x[i]>=max1&&y[i]>=max2)||(x[i]>=max2&&y[i]>=max1))
printf("YES\n");
else printf("NO\n");
}
}
return 0;
}