Codeforces Round #662 (Div. 2) B. Applejack and Storages

题目链接
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 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: the storehouse received a plank with length x
  • − x: one plank with length x was removed from the storehouse (it is guaranteed that the storehouse had some planks with length 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≤105): the initial amount of planks at the company’s storehouse, the second line contains n integers a1,a2,…,an (1≤ai≤1e5): the lengths of the planks.

The third line contains a single integer q (1≤q≤1e5): the number of events in the company. Each of the next 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≤1e5).

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

这题我考虑的好像有点复杂了,记录了四个变量,分别是:

  1. n u m ≥ 8 num \geq8 num≥8
  2. n u m ≥ 6 num \geq6 num≥6
  3. n u m ≥ 4 num \geq4 num≥4
  4. n u m ≥ 2 num \geq2 num≥2

每次加减都变化一下即可,设多的坏处就是输出时要考虑很多,因为这个WA了两发/(ㄒoㄒ)/~~,AC代码如下:

#include<bits/stdc++.h>
using namespace std;
int main()
{char c;int n,q,x,cnt2=0,cnt4=0,cnt6=0,cnt8=0;cin>>n;map<int,int>m;while(n--){cin>>x,m[x]++;}cin>>q;for(auto i:m){if(i.second>=8) cnt8++;else if(i.second>=6) cnt6++;else if(i.second>=4) cnt4++;else if(i.second>=2) cnt2++;}while(q--){cin>>c>>x;if(c=='-'){if(m[x]==8) cnt8--,cnt6++;else if(m[x]==6) cnt6--,cnt4++;else if(m[x]==4) cnt4--,cnt2++;else if(m[x]==2) cnt2--;m[x]--;}else{if(m[x]==7) cnt8++,cnt6--;else if(m[x]==5) cnt6++,cnt4--;else if(m[x]==3) cnt4++,cnt2--;else if(m[x]==1) cnt2++;m[x]++;}if(((cnt2>1||cnt6||cnt8)&&cnt4>0)||(cnt6>0&&cnt2>0)||(cnt4>1)||(cnt8>0)||(cnt6>1)) printf("YES\n");else printf("NO\n");}return 0;
}

Codeforces Round #662 (Div. 2) B. Applejack and Storages相关推荐

  1. Codeforces Round #662 (Div. 2)

    就写了两个题,以为要掉分,结果早上起来发现还上分了(说明wtcl A - Rainbow Dash, Fluttershy and Chess Coloring 无论边长是奇数还是偶数,考虑每次操作最 ...

  2. B. Applejack and Storages(数学+STL的使用) Codeforces Round #662 (Div. 2)

    原题链接:https://codeforces.com/contest/1393/problem/B 题意:仓库中原有n块给定长度的木板,我想通过这些木板来形成一个正方形,或者一个矩形(正方形也是矩形 ...

  3. A. Rainbow Dash, Fluttershy and Chess Coloring(思维) Codeforces Round #662 (Div. 2)

    原题链接:https://codeforces.com/contest/1393/problem/A 题意:给定一个正方形区域上色,要求上色的块相邻之间不能相同,也就是我们会在每回合上不同的颜色,要求 ...

  4. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  5. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

  6. 构造 Codeforces Round #302 (Div. 2) B Sea and Islands

    题目传送门 1 /* 2 题意:在n^n的海洋里是否有k块陆地 3 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 4 输出完k个L后,之后全部输出S:) 5 5 10 的例子可以 ...

  7. Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解 比赛链接:h ...

  8. Codeforces Round #712 Div.2(A ~ F) 超高质量题解(每日训练 Day.15 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #712 Div.2(A ~ F) 题解 比赛链接:https:// ...

  9. Codeforces Round #701 (Div. 2) A ~ F ,6题全,超高质量良心题解【每日亿题】2021/2/13

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A - Add and Divide B - Replace and Keep Sorted C ...

最新文章

  1. 隐含马尔可夫模型在语言处理中的应用(Z)
  2. Spring Caching抽象和Google Guava Cache
  3. php boolean 全大写还是全小写,【PHP培训】PHP为什么大小写规则是如此不规则?
  4. 《WinForm开发系列之控件篇》Item3 BindingSource (暂无)
  5. HashMap中的hash算法的几个思考
  6. Scrapy:爬取豆瓣图书
  7. 1、NESSUS安装
  8. redis读中文 | fastjson 的 map、string、json 三者互转
  9. python24点游戏
  10. Microsoft SQL Server 2000 Service Pack 3a
  11. 银河麒麟系统安装失败
  12. java表白程序玫瑰花_Java版给爱人表白的玫瑰花程序代码
  13. 基于百度云通过Python实现简单的营业执照识别
  14. npm报错stack Error: EACCES: permission denied, mkdir
  15. 大学计算机基础实验指导第一章答案,(教材)大学计算机基础实验指导与习题解答...
  16. Mybatis Smart Code Help插件使用介绍
  17. Angular2 之 单元测试
  18. 响应式设计布局要不要了解一下?
  19. 手把手教你如何搭建一个网红教师的网络教学环境
  20. MATLAB中mean()的用法、含义、意思

热门文章

  1. 【笔记】Spring MVC拦截入参、出参实现入参解密,出参加密统一管理
  2. 笔记本测试软件汇总-转
  3. Parse入门教程-服务的搭建及使用
  4. 区块链python还是c_区块链要学什么编程语言?
  5. python numpy for循环矩阵乘法
  6. 用笔记本改装智能家居服务器,让智能家居真正融入生活
  7. SpringBoot2.x+Redis+token实现鉴权功能
  8. MobSF源码分析——静态分析部分
  9. NOIP 提高组 复赛 历年 试题
  10. 《Java1996》03:啥是面向对象?