Codeforces Round #662 (Div. 2) B. Applejack and Storages
程序员文章站
2022-03-03 11:45:54
题目链接:传送门感想:好久不打cf,一打直接被教育,本来想的是用两个整数变量来模拟,但是似乎删除数字时不好处理,然后就凉了。思路:用set来存储所有出现次数大于4的数,变量f2存储所有大于等于2小于4的数(即2和3),然后随着每次操作维护即可。这样似乎比较笨,但是比较好想。代码:#include using namespace std;const int maxn = 1e5 + 5;int a[maxn];map
题目链接:传送门
感想:好久不打cf,一打直接被教育,本来想的是用两个整数变量来模拟,但是似乎删除数字时不好处理,然后就凉了。
思路:用set来存储所有出现次数大于4的数,变量f2存储所有大于等于2小于4的数(即2和3),然后随着每次操作维护即可。这样似乎比较笨,但是比较好想。
代码:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int a[maxn];
map <int , int> mp;
vector <int> v;
int l1;
set <int> st;
int main() {
int n;
ios::sync_with_stdio(0);
cin >> n;
l1 = 0;
for(int i = 0 ; i < n ; i++) {
cin >> a[i];
if(!mp.count(a[i])) {
v.push_back(a[i]);
}
mp[a[i]]++;
}
int f1 = 0 , f2 = 0;
for(int i = 0 ; i < v.size() ; i++) {
int t = mp[v[i]];
if(t >= 4) {
st.insert(v[i]);
}
else if(t >= 2) {
f2 += 1;
}
}
int q;
cin >> q;
while(q--) {
char c;
int x;
cin >> c >> x;
int t;
if(c == '+') {
mp[x]++;
t = mp[x];
if(t == 2) {
f2++;
}
else if(t == 4) {
f2--;
st.insert(x);
}
}
else if(c == '-') {
mp[x]--;
t = mp[x];
if(t == 1) {
f2--;
}
else if(t == 3){
f2++;
st.erase(x);
}
}
auto it = st.begin();
if(st.size() >= 2 || (mp[*(it)] >= 8) || (mp[*(it)] >= 6 && f2 >= 1) || (st.size() >= 1 && f2 >= 2) ) {
cout << "YES\n";
}
else {
cout << "NO\n";
}
}
return 0;
}
本文地址:https://blog.csdn.net/qq_39475280/article/details/107876220
推荐阅读
-
Codeforces Round #649 (Div. 2)-B. Most socially-distanced subsequence(思维)
-
Codeforces Round #461 (Div. 2) B. Magic Forest(异或的性质)
-
Codeforces Round #663 (Div. 2) B. Fix You
-
Codeforces Round #658 (Div. 2) B. Sequential Nim
-
B. Power Sequence(数学+枚举)Codeforces Round #666 (Div. 2)
-
Codeforces Round #666 (Div. 2)B. Power Sequence(等比数列)
-
Codeforces Round #664 (Div. 2) B. Boboniu Plays Chess
-
Codeforces Round #662 (Div. 2) D. Rarity and New Dress
-
D. Rarity and New Dress(思维+动态规划)Codeforces Round #662 (Div. 2)
-
Codeforces Round #272 (Div. 2) B. Dreamoon and WiFi (超几何