原题:
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×y fits into some wallet h×w if 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 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≤n≤5⋅10^5) — the number of queries.
Each of the next n lines contains a query of one of these two types:
“+ x y” (1≤x,y≤10^9) — Polycarp earns a bill of size x×y;
“? h w” (1≤h,w≤10^9) — 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 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.
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
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×5 fit (all the others don’t, thus it’s “NO”).
中文:
有一个矩形的钱包尺寸为(h,w),然后给你一堆支票,尺寸为(x,y),每次输入"+ x y"表示收到了一张尺寸为(x,y)的支票,输入"? h w"表示查询现在手里的这些支票能否装进尺寸表为(h,w)的钱包。
代码:
#include <bits/stdc++.h>
using namespace std;
const int maxn=50001;
int n,x,y,w,h;
int main()
{
ios::sync_with_stdio(false);
while(cin>>n)
{
char c;
w=h=-1;
for(int i=1;i<=n;i++)
{
cin>>c>>x>>y;
if(x>y)
swap(x,y);
if(c=='+')
{
if(x>w)
w=x;
if(y>h)
h=y;
}
else
{
if(x>=w&&y>=h)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
}
}
return 0;
}
思路:
E题这难度可真是震惊我了,每次保存当前收到的支票的最大尺寸即可。=_=|||