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

B. Applejack and Storages

原题链接:https://codeforces.com/contest/1393/problem/B

time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard output

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

The third line contains a single integer q q q ( 1 ≤ q ≤ 105 ) : (1≤q≤105): (1q105): 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 x x ( 1 ≤ x ≤ 105 ) (1≤x≤105) (1x105).

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 1,2,1,2 and a square storage using planks with lengths 1 , 1 , 1 , 1 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 2,2,2,2 and a square storage using planks with lengths 1 , 1 , 1 , 1 1, 1, 1, 1 1,1,1,1.

题意及题解:
先把过了的代码贴上来,题解稍后补
(这个代码,太暴力了,噗)

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
typedef long long ll;
using namespace std;
int a[100005];
int main()
{
    int n ,m;
    int res1 = 0, res2 = 0;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        int x;
        cin >> x;
        a[x]++;
        if (a[x] == 2) 
            res2++;
        if (a[x] == 4)
        {
            res2--;
            res1++;
        }
        if (a[x] == 6) 
            res2++;
        if (a[x] == 8) 
            res2++;
    }
    cin >> m;
    for (int i = 1; i <= m; i++)
    {
        char s;
        int x;
        cin >> s >> x;
        if (s == '+')
        {
            a[x]++;
            if (a[x] == 2)
                res2++;
            if (a[x] == 4)
            {
                res2--;
                res1++;
            }
            if (a[x] == 6)
                res2++;
            if (a[x] == 8)
                res2++;
        }
        else
        {
            a[x]--;
            if (a[x] == 3)
            {
                res1--;
                res2++;
            }
            if (a[x] == 1)
                res2--;
            if (a[x] == 5)
                res2--;
            if (a[x] == 7)
                res2--;
        }
        if (res1 >= 2 || (res2 >= 2 && res1))
            printf("YES\n");
        else 
            printf("NO\n");
    }
    return 0;
}
  • 5
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值