0915cch模拟赛总结
100 + 100 + 100 + 50 = 350
不仅没有挂分,甚至还比估分多了30:)
cch果然比dmy是人:):):):):)
但是!2h没写出T4qwqwqwqwqwqwqwq
我太菜了qwq
我太菜了qwq
我太菜了qwq
我太菜了qwq
我太菜了qwq
我太菜了qwq
我太菜了qwq
我太菜了qwq
我太菜了qwq
我太菜了qwq
我太菜了qwq
A - 公平合影
跟dmy对比直接飞起来:)
很快就有了思路:首先都是
然后剩下的可以搞一个前缀和,
然后一段
所以记录一下每个和第一次出现是哪里,然后枚举右端点就可以愉快的
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int N = 1e5 + 5;
int n, f[N * 2], s[2], ans;
struct aa {
int x, f;
} a[N];
bool cmp (aa x, aa y) {
return x.x < y.x;
}
int main () {
freopen("fairphoto.in", "r", stdin);
freopen("fairphoto.out", "w", stdout);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i].x;
char c;
cin >> c;
a[i].f = c == 'G';
}
sort(a + 1, a + n + 1, cmp);
int tmp = 0;
a[0].x = -1;
fill(f, f + n * 2 + 1, 1e9);
a[n + 1].x = 1e9;
f[n] = 0;
for (int i = 1; i <= n; i++) {
s[a[i].f]++;
if (a[i].f != a[i - 1].f) {
tmp = i;
}
// cout << tmp << ' ' << s[0] - s[1] + n << '\n';
f[s[0] - s[1] + n] = min(f[s[0] - s[1] + n], i);
ans = max({ans, a[i].x - a[tmp].x, a[i].x - a[f[s[0] - s[1] + n] + 1].x});
}
cout << ans;
return 0;
}
B - 暗号解码
这个题,花了我
至少没有像去年那样T2保龄qwq
看数据范围,发现
思考
然后又感觉像是预处理,然后复杂度带个
再烧烤
决定手玩一下,发现了一个非常非常关键的东西:
当把字母子集中任意
所以可以想到枚举
查询的时候再枚举子集里面的每
但是这样是
所以又烧烤了
(其实这只是感性的一种感觉,也没想过正着搞行不行)
预处理基本上还是那样处理,但是变成了:对于每个字母,处理出跟它是
查询就是把字母子集状压一下(假设压成了
这样(
然后就平平安安的
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int K = 30;
int f[K], n, m, q;
string s, t;
int main () {
freopen("cipher.in", "r", stdin);
freopen("cipher.out", "w", stdout);
ios::sync_with_stdio(0), cin.tie(0);
cin >> s >> t;
n = s.size(), m = t.size();
s = ' ' + s + ' '; t = ' ' + t + ' ';
for (int i = 0; i < 26; i++) {
for (int j = i; j < 26; j++) {
for (int k1 = 1, k2 = 1; k1 <= n || k2 <= m;) {
for (; s[k1] != (char)('a' + i) && s[k1] != (char)('a' + j) && k1 < n; k1++);
for (; t[k2] != (char)('a' + i) && t[k2] != (char)('a' + j) && k2 < m; k2++);
if (s[k1] != (char)('a' + i) && s[k1] != (char)('a' + j) && t[k2] != (char)('a' + i) && t[k2] != (char)('a' + j)) {
break;
}
if (s[k1] != t[k2]) {
f[i] |= 1 << j;
// cout << (char)('a' + i) << ' ' << (char)('a' + j) << '\n';
break;
}
k1++;
k2++;
}
}
}
cin >> q;
for (string tmp; q--;) {
cin >> tmp;
int ttmp = 0;
for (int i = 0; i < tmp.size(); i++) {
ttmp |= 1 << (tmp[i] - 'a');
}
int ans = 1;
for (int i = 0; i < tmp.size(); i++) {
if (f[tmp[i] - 'a'] & ttmp) {
ans = 0;
break;
}
}
if (ans) {
cout << 'Y';
} else {
cout << 'N';
}
}
return 0;
}
C - 分组
由于已经
赶紧去趟厕所调整心态:)
看完题感觉特别像出题大赛
我记得那个是二分 +
然后发现
看了眼数据范围,发现分数和分数线都只有
虚空烧烤
然后就看到了:“特殊性质A:输入序列整体单调(递增或递减)”
又顺着这个虚空烧烤
决定研究一下关于中位数的东西。因为它只要中位数
然后因为刚刚T1的经验(也不能说是经验,就是对这种处理方法的印象),想到把
然后就变成了二维偏序的板题,用树状数组就能
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int N = 1e5 + 5;
LL n, x, a[N], tree[N * 2], ans;
int lb (int x) {
return x & -x;
}
void add (int x, LL y) {
for (; x <= n * 2; x += lb(x)) {
tree[x] += y;
}
}
LL query (int x) {
LL ret = 0;
for (; x; x -= lb(x)) {
ret += tree[x];
}
return ret;
}
int main () {
freopen("grouping.in", "r", stdin);
freopen("grouping.out", "w", stdout);
cin >> n >> x;
int s = 0;
add(n, 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
s += a[i] >= x ? 1 : -1;
ans += query(s + n);
add(s + n, 1);
}
cout << ans;
return 0;
}
D - 平衡小径
时间还剩下
先想到枚举休息站,然后用树形
暴力的话,枚举路径的端点,
大路径的和可以用差分来做,树剖第一遍
因为前面想了很久的树剖,所以有了对树剖莫名的执着,用树剖求了
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int N = 1e5 + 5;
int n, fa[N][2], d[N], sz[N], son[N], top[N], ans, s[N];
struct edge {
int x, f;
};
vector <edge> v[N];
void dfs1 (int x, int f) {
fa[x][0] = f;
d[x] = d[f] + 1;
sz[x] = 1;
for (edge i : v[x]) {
if (i.x == f) continue;
s[i.x] = s[x] + i.f;
dfs1(i.x, x);
sz[x] += sz[i.x];
fa[i.x][1] = i.f;
if (sz[i.x] > sz[son[x]]) {
son[x] = i.x;
}
}
}
void dfs2 (int x, int t) {
top[x] = t;
if (son[x]) {
dfs2(son[x], t);
}
for (edge i : v[x]) {
if (i.x == fa[x][0] || i.x == son[x]) continue;
dfs2(i.x, i.x);
}
}
int LCA (int x, int y) {
while (top[x] != top[y]) {
if (d[top[x]] < d[top[y]]) swap(x, y);
x = fa[top[x]][0];
}
if (d[x] < d[y]) {
return x;
} else {
return y;
}
}
int check (int x, int y, int l) {
int s = 0, xx = x;
for (; x != l; x = fa[x][0]) {
s += fa[x][1];
if (fa[x][0] != y && !s) return 1;
}
s = 0;
for (; y != l; y = fa[y][0]) {
s += fa[y][1];
if (fa[y][0] != x && !s) return 1;
}
return 0;
}
int main () {
freopen("balance.in", "r", stdin);
freopen("balance.out", "w", stdout);
ios::sync_with_stdio(0), cin.tie(0);
cin >> n;
for (int i = 1, x, y, t; i < n; i++) {
cin >> x >> y >> t;
if (t == 0) t--;
v[x].emplace_back((edge){y, t});
v[y].emplace_back((edge){x, t});
}
dfs1(1, 1);
dfs2(1, 1);
// for (int i = 1; i <= n; i++) {
// cout << s[i] << '\n';
// }
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
int lca = LCA(i, j);
// cout << i << ' ' << j << ' ' << lca << ' ' << s[i] << ' ' << s[j] << ' ' << s[lca] << '\n';
if (s[i] - s[lca] + s[j] - s[lca]) {
continue;
}
// cout << i << ' ' << j << '\n';
ans += check(i, j, lca);
}
}
cout << ans;
return 0;
}