当前位置: 代码迷 >> 综合 >> 1393/B Applejack and Storages
  详细解决方案

1393/B Applejack and Storages

热度:86   发布时间:2024-02-10 07:38:11.0

Applejack and Storages

http://codeforces.com/contest/1393/problem/B

题面:

This year in Equestria was a year of plenty, so Applejack has decided to build some new apple storages. According to the advice of the farm designers, she chose to build two storages with non-zero area: one in the shape of a square and another one in the shape of a rectangle (which possibly can be a square as well).

Applejack will build the storages using planks, she is going to spend exactly one plank on each side of the storage. She can get planks from her friend’s company. Initially, the company storehouse has n n planks, Applejack knows their lengths. The company keeps working so it receives orders and orders the planks itself. Applejack’s friend can provide her with information about each operation. For convenience, he will give her information according to the following format:

  • + x x : the storehouse received a plank with length x x
  • - x x : one plank with length x x was removed from the storehouse (it is guaranteed that the storehouse had some planks with length x x ).

Applejack is still unsure about when she is going to order the planks so she wants to know if she can order the planks to build rectangular and square storages out of them after every event at the storehouse. Applejack is busy collecting apples and she has completely no time to do the calculations so she asked you for help!

We remind you that all four sides of a square are equal, and a rectangle has two pairs of equal sides.

Input

The first line contains a single integer n ( 1 n 1 0 5 ) : n (1 \le n \le 10^5): the initial amount of planks at the company’s storehouse, the second line contains n integers a 1 , a 2 , , a n ( 1 a i 1 0 5 ) : a_1, a_2, \ldots, a_n (1 \le a_i \le 10^5): the lengths of the planks.

The third line contains a single integer q ( 1 q 1 0 5 ) : q (1 \le q \le 10^5): the number of events in the company. Each of the next q q lines contains a description of the events in a given format: the type of the event (a symbol + + or ? - ) is given first, then goes the integer x ( 1 x 1 0 5 ) . x (1 \le x \le 10^5).

Output

After every event in the company, print “YES” if two storages of the required shape can be built from the planks of that company’s set, and print “NO” otherwise. You can print each letter in any case (upper or lower).

Example

input

6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2

output

NO
YES
NO
NO
NO
YES

Note

After the second event Applejack can build a rectangular storage using planks with lengths 1 , 2 , 1 , 2 1, 2, 1, 2 and a square storage using planks with lengths 1 , 1 , 1 , 1. 1, 1, 1, 1.

After the sixth event Applejack can build a rectangular storage using planks with lengths 2 , 2 , 2 , 2 2, 2, 2, 2 and a square storage using planks with lengths 1 , 1 , 1 , 1. 1, 1, 1, 1.

翻译:

这年在E是丰收penty的一年,所以A决定建立一些新的 apple 储存storages。根据建议从农产设计师designers,她选择建立两个 apple 储存 不为零,其中一个形状是正方形square ,另一个是形状是矩形rectangle 。(可能是正方形)

A将建立储存使用木板planks,她将花费 恰好的木板在每一个侧面side 对于这个储存。他能得到木板从他的朋友的公司。最初,这个公司的仓库storehouse 有N 块木板,A知道他们的长度。公司一直在工作,所以他收到receives 订单 orders 和 订购木板自己。为了方便convenience,他将给他信息根据一下的格式format,

  • + x x :厂库接收到木板 长度为 x
  • - x x : 一个木板 长度为 x 被搬走了从仓库(保证guaranteed 仓库有一些木板 长度为 x)

A一直不确定什么时候她将订购木板,所以她想知道 是否她能订购木板去建立矩形和正方形的储存设备 在之面 他们每一次事件对于仓库。A急于收集 apple并且她完全completely 没有时间去做计算calculations ,所以向你寻求帮助。

我们提醒你,所有的四条边对于正方型是相等的equal,一个矩形有两个对pairs of 是相等的边

题意:

给你一组数,然后求里面是否存在两组四个相等或者一组四个相等一组两两相等。

题解:

用map存个数,如果是2就记录一次,如果是4就记录下来。然后看比例。

代码:

#include <bits/stdc++.h>
using namespace std;map<int, int>mm;int main (void)
{   int n;cin>>n;int cnt_2 = 0, cnt_4 = 0;for(int i=0; i<n; i++){int t;cin>>t;mm[t]++;if(mm[t]%4 == 2) cnt_2++;if(mm[t]%4 == 0) cnt_4++, cnt_2--;}int q;cin>>q;while(q--){string x;int y;cin>>x>>y;if(x == "+"){mm[y]++;if(mm[y]%4 == 2) cnt_2++;if(mm[y]%4 == 0) cnt_4++, cnt_2--;}else{mm[y]--;if(mm[y]%4 == 3) cnt_4--, cnt_2++;if(mm[y]%4 == 1) cnt_2--;}if(cnt_4 >= 2 || (cnt_4 == 1 && cnt_2 >= 2))cout<<"YES"<<endl;elsecout<<"NO"<<endl;}return 0;
}