zoukankan      html  css  js  c++  java
  • Codeforces Round #662 (Div. 2) 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 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≤105): the lengths of the planks.

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

    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
    inputCopy
    6
    1 1 1 2 1 1
    6

    • 2
    • 1
    • 1
    • 2
    • 1
    • 2
      outputCopy
      NO
      YES
      NO
      NO
      NO
      YES

    思路

    emmm,看样子我们需要统计当前集合里面的每个木板的数目,首先1e5的数量每次询问都扫一次数组显然不现实,那么我们需要的是存下2,4,6这三个数字的个数(不同长度),每次询问对数字进行操作然后判断就可以了。

    代码实现

    #include<cstdio>
    #include<algorithm>
    #include<vector>
    #include<queue>
    #include<map>
    #include<iostream>
    #include<cstring>
    #include<cmath>
    using namespace std;
    #define rep(i,f_start,f_end) for (int i=f_start;i<=f_end;++i)
    #define per(i,n,a) for (int i=n;i>=a;i--)
    #define MT(x,i) memset(x,i,sizeof(x) )
    #define rev(i,start,end) for (int i=0;i<end;i++)
    #define inf 0x3f3f3f3f
    #define mp(x,y) make_pair(x,y)
    #define lowbit(x) (x&-x)
    #define MOD 1000000007
    #define exp 1e-8
    #define N 1000005 
    #define fi first 
    #define se second
    #define pb push_back
    typedef long long ll;
    typedef pair<int ,int> PII;
    ll gcd (ll a,ll b) {return b?gcd (b,a%b):a; }
    inline int read() {
        char ch=getchar(); int x=0, f=1;
        while(ch<'0'||ch>'9') {
            if(ch=='-') f = -1;
            ch=getchar();
        } 
        while('0'<=ch&&ch<='9') {
            x=x*10+ch-'0';
            ch=getchar();
        }   return x*f;
    }
    
    const int maxn=1e5+10;
    int n;
    int a[maxn];
    map <int ,int> b;
    
    int main () {
    //    freopen ("data.in","r",stdin);
       cin>>n;
       int four=0,two=0,six=0;
       rep (i,1,n) {
           cin>>a[i];
       }
       rep (i,1,n) {
           b[a[i]]++;
           if (b[a[i]]%6==2) two++;
           else if (b[a[i]]%6==4) {two--,four++;}
           else if (b[a[i]]%6==0) {four--,six++;}
       }
       int q,x;
       char y;
       cin>>q;
       while (q--) {
           cin>>y>>x;
           if (y=='+') {
               b[x]++;
               if (b[x]%6==2) two++;
               else if (b[x]%6==4) {two--,four++;}
               else if (b[x]%6==0) {four--,six++;}
           }
           else {
               b[x]--;
               if (b[x]%6==5) {four++,six--;}
               else if (b[x]%6==3) {two++,four--;}
               else if (b[x]%6==1) {two--;}
           }
           if ((four&&two>1)||(four>1)||(six>1)||(six&&two)||(six&&four)) cout<<"YES"<<endl;
           else cout<<"NO"<<endl; 
       }
    //    fclose (stdin);
       return 0;
    }
    
    
  • 相关阅读:
    自定义view代码
    省份封装代码
    监听锁屏广播,开启1个像素的Activity
    双进程守护
    新增,查询,删除,修改下方即可
    #Android笔记#解决textview使用SpannableString实现图文混排并设置了行高时,图片与文字显示混乱
    显示地图
    局部页面传值Model
    JS的跳转
    helper实现隐藏前台特效
  • 原文地址:https://www.cnblogs.com/hhlya/p/13457637.html
Copyright © 2011-2022 走看看