这比赛,一言难进。个人感觉目前水平应该A3题没问题,结果各种脑残bug、写错变量名,溢出导致只A了一题(其实根本原因是菜还不努力,做题太少)。好在区域赛之前cf场次还不少,还有机会上分。
最坑的是,这些脑残bug还特别难debug
B
唉,看这个数据范围本来考虑暴力+sort,结果算了下时间复杂度O(n^2logn)不行,然后又考虑各种高大上数据结构,发现没有能用的(关键还是之前数据结构划水太严重,根本不知道该怎么用,导致瞎猜),好不容易发现模拟就能解决,结果变量写错了,debug没搞定;唉,还莫名其妙过了几组数据
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int num[100005];
vector<int> bigger4;
vector<int> bigger2;
bool ok() {
if (bigger4.size() >= 2) return true;
if (bigger4.size() == 1) {
if (num[bigger4[0]] >= 8) return true;
if (num[bigger4[0]] >= 6 && bigger2.size() >= 2) return true;
if (bigger2.size() >= 3) return true;
}
return false;
}
int main() {
#ifdef LOCAL
freopen("zz_in.txt", "r", stdin);
freopen("zz_op.txt", "w", stdout);
#endif
int t, i, j, k, n, q;
memset(num, 0, sizeof(num));
bigger2.clear();
bigger4.clear();
cin >> n;
int temp;
char flag;
for (i = 0; i < n; i++) {
scanf("%d", &temp);
num[temp]++;
}
for (i = 1; i <= 100000; i++) { //无语(100000写成n)
if (num[i] >= 4) bigger4.push_back(i);
if (num[i] >= 2) bigger2.push_back(i);
}
scanf("%d", &q);
for (i = 0; i < q; i++) {
getchar();
scanf("%c%d", &flag, &temp);
// cout << flag << endl;
if (flag == '+') {
num[temp]++;
if (num[temp] == 2) bigger2.push_back(temp);
if (num[temp] == 4) bigger4.push_back(temp);
if (ok())
cout << "YES" << endl;
else
cout << "NO" << endl;
}
if (flag == '-') {
num[temp]--;
if (num[temp] == 3) {
for (j = 0; j < bigger4.size(); j++) {
if (bigger4[j] == temp) {
swap(bigger4[j], bigger4[bigger4.size() - 1]);
bigger4.pop_back();
break;
}
}
}
if (num[temp] == 1) {
for (j = 0; j < bigger2.size(); j++) { //唉,无语,脑残(bigger2写成bigger4)
if (bigger2[j] == temp) {
swap(bigger2[j], bigger2[bigger2.size() - 1]);
bigger2.pop_back();
break;
}
}
}
if (ok())
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
#ifdef LOCAL
printf("Time used = %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
return 0;
}
C
最先考虑弱智级贪心,最后一组样例卡了
后来考虑数据范围觉得二分可以解决,结果时间不够了
今天补题写出代码,莫名其妙卡样例62,翻了翻测试数据,发现
int乘法溢出了……
以后应注意
唉,划水这么长时间,严格意义上写的第一道二分题目
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int num[100005];
int n;
bool cmp(int a, int b) {
return a > b;
}
int judge(int mid) {
int cnt = 0;
for (int i = 0; i < 100005; i++) {
if (num[i] == num[0])
cnt++;
else
break;
}
if ((long long) (mid + 1) * (long long) (num[0] - 1) + cnt > n) //溢出
return false;
else
return true;
}
int main() {
#ifdef LOCAL
freopen("zz_in.txt", "r", stdin);
freopen("zz_op.txt", "w", stdout);
#endif
int t, i, j, k, ans = 0;
cin >> t;
int l, r;
while (t--) {
ans = 0;
cin >> n;
memset(num, 0, sizeof(num));
l = 0, r = n - 1;
for (i = 0; i < n; i++) {
cin >> k;
num[k]++;
}
sort(num, num + 100005, cmp);
// for (i = 0; i < n; i++)
// cout << num[i] << "\t";
while (l <= r) {
// cout << l << "\t" << r << endl;
int mid = (l + r + 1) / 2;
if (judge(mid)) {
ans = mid;
l = mid + 1;
} else
r = mid - 1;
}
cout << ans << endl;
}
#ifdef LOCAL
printf("Time used = %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
return 0;
}