这道题目明显和出现4次的数和出现2次的数的个数有关系,只需要在每次更新之后维护这两个信息即可,我们在算出现2次的数的个数时其实会把出现4次的数的个数会把出现2次的数的个数+2,在判断时需要考虑这一点。也就是\(cnt2>=4\&\&cnt4>=1\)时才有解

#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define ls p<<1
#define rs p<<1|1
#define PII pair<int, int>
#define ll long long
#define ull unsigned long long
#define db double
#define endl '\n'
#define debug(a) cout<<#a<<"="<<a<<endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 0x3f3f3f3f
#define x first
#define y second
using namespace std; const int N=1e5+10,mod=1e9+7;
int a[N],cnt[N]; void solve()
{
int n,f=0,t=0;
cin>>n;
rep(i,1,n)
{
cin>>a[i];
cnt[a[i]]++;
if(cnt[a[i]]%4==0) f++;
if(cnt[a[i]]%2==0) t++;
}
int q;cin>>q;
while(q--)
{
char op;int k;cin>>op>>k;
if(op=='+')
{
cnt[k]++;
if(cnt[k]%4==0) f++;
if(cnt[k]%2==0) t++;
}
if(op=='-')
{
if(cnt[k]%4==0) f--;
if(cnt[k]%2==0) t--;
cnt[k]--;
}
if(f>=1&&t>=4) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
} int main()
{
IOS
// freopen("1.in", "r", stdin);
int t;
// cin>>t;
// while(t--)
solve();
return 0;
}

Educational Codeforces Round 65 (Rated for Div. 2)C. News Distribution(模拟,计算的时候去重)的更多相关文章

  1. Educational Codeforces Round 65 (Rated for Div. 2) C. News Distribution

    链接:https://codeforces.com/contest/1167/problem/C 题意: In some social network, there are nn users comm ...

  2. Educational Codeforces Round 65 (Rated for Div. 2)题解

    Educational Codeforces Round 65 (Rated for Div. 2)题解 题目链接 A. Telephone Number 水题,代码如下: Code #include ...

  3. Educational Codeforces Round 65 (Rated for Div. 2) D. Bicolored RBS

    链接:https://codeforces.com/contest/1167/problem/D 题意: A string is called bracket sequence if it does ...

  4. Educational Codeforces Round 65 (Rated for Div. 2) B. Lost Numbers

    链接:https://codeforces.com/contest/1167/problem/B 题意: This is an interactive problem. Remember to flu ...

  5. Educational Codeforces Round 65 (Rated for Div. 2) A. Telephone Number

    链接:https://codeforces.com/contest/1167/problem/A 题意: A telephone number is a sequence of exactly 11  ...

  6. Educational Codeforces Round 65 (Rated for Div. 2)B. Lost Numbers(交互)

    This is an interactive problem. Remember to flush your output while communicating with the testing p ...

  7. [ Educational Codeforces Round 65 (Rated for Div. 2)][二分]

    https://codeforc.es/contest/1167/problem/E E. Range Deleting time limit per test 2 seconds memory li ...

  8. Educational Codeforces Round 65 (Rated for Div. 2)

    A:签到. #include<bits/stdc++.h> using namespace std; #define ll long long #define inf 1000000010 ...

  9. Educational Codeforces Round 65 (Rated for Div. 2) E. Range Deleting(思维+coding)

    传送门 参考资料: [1]:https://blog.csdn.net/weixin_43262291/article/details/90271693 题意: 给你一个包含 n 个数的序列 a,并且 ...

  10. Educational Codeforces Round 65 (Rated for Div. 2)(ACD)B是交互题,不怎么会

    A. Telephone Number A telephone number is a sequence of exactly 11 digits, where the first digit is  ...

随机推荐

  1. 使用emmylua调试slua

    使用emmylua调试slua的方法 在lua的入口中加上emmylua的debug代码 在slua的LuaState.loaderDelegate委托中,添加判断如果是load_file_name= ...

  2. 在mac中双击执行python

    执行python脚本 mac有内置的python,但还是建议你自己安装一个python,如果没有卸载mac自带的python2.7,当你需要使用python3执行脚本时,python命令需要改为pyt ...

  3. win10 局域网共享文件创建方法

    win10 局域网共享文件创建方法 1.先在桌面文件夹,我命名为"xxxx",然后将文件放在该文件里. 2.右击共享文件夹,找到属性选项,点击"属性".再点击& ...

  4. 【1】paddle飞桨框架高层API使用讲解

    1.高层API简介 飞桨框架2.0全新推出高层API,是对飞桨API的进一步封装与升级,提供了更加简洁易用的API,进一步提升了飞桨的易学易用性,并增强飞桨的功能. 飞桨高层API由五个模块组成:数据 ...

  5. Linux的守护进程 [补档-2023-08-10]

    12-1守护进程 12-1-1介绍 ​   Daemom是Linux中的后台服务进程,通常独立于控制终端并且周期性地执行某种任务或者事件.这些进 程一般不直接和用户交互,不受用户的登录,注销等影响.没 ...

  6. 关于 vant 移动端的 rem 适配方案

    一.使用 lib-flexible 动态设置 rem 基准值 (html 标签的字体大小) (1) 安装依赖: npm i amfe-flexible -D (2) 在main.js 中引入 impo ...

  7. 通过Demo学WPF—数据绑定(二)

    准备 今天学习的Demo是Data Binding中的Linq: 创建一个空白解决方案,然后添加现有项目,选择Linq,解决方案如下所示: 查看这个Demo的效果: 开始学习这个Demo xaml部分 ...

  8. 【链表】【python】力扣24. 两两交换链表中的节点【超详细的注释和解释】

    目录 说在前面的话 前言 一.题目(力扣24. 两两交换链表中的节点) 二.题目分析 实现完整代码(Python实现) 总结 说在前面的话 博主也好长一段时间没有更新力扣的刷题系列了,今天给大家带来一 ...

  9. Nginx的反向代理做负载均衡

    对于一个大型网站,随着网站的访问量快速增长,单台服务器很难再支撑起需要,所以我们会购置多个服务器来满足业务量的需求,然后再利用Nginx提供的反向代理功能,来实现多台服务器间的协作功能,提高网站的处理 ...

  10. php+html5使用FormData对象提交表单及上传图片的方法

    php+html5使用FormData对象提交表单及上传图片的方法 本文实例讲述了php+html5使用FormData对象提交表单及上传图片的方法.分享给大家供大家参考.具体分析如下: FormDa ...