2025 CCH非专业级软件能力认证 CSP-J/S 2025 第二轮认证 提高级
CuteGirlGC · · 个人记录
预计:100+100+100+RAND 实际:100+0+60+10
T1T2挂了140pts/ll
T1
把 H 当作 G 当作
#include <algorithm>
#include <iostream>
#include <unordered_map>
using namespace std;
const int kMaxN = 2e5 + 1;
int n;
struct C {
int x, d;
friend bool operator<(C a, C b) {
return a.x < b.x;
}
} a[kMaxN];
unordered_map<int, int> mp;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
char c;
cin >> a[i].x >> c;
a[i].d = (c == 'G' ? 1 : -1);
}
sort(a + 1, a + n + 1);
int ans = 0, lst = a[1].x, s = a[1].d;
mp[s] = 1;
for (int i = 2; i <= n; i++) {
if (a[i].d != a[i - 1].d) {
ans = max(ans, a[i - 1].x - lst);
lst = a[i].x;
}
s += a[i].d;
if (s == 0) {
ans = max(ans, a[i].x - a[1].x);
} else if (!mp[s]) {
mp[s] = i;
} else {
ans = max(ans, a[i].x - a[mp[s] + 1].x);
}
}
cout << ans << '\n';
return 0;
}
T2
有一个
容易发现,当字符集中任意两个字符拿出来之后都是成立的话,那么整个字符串也成立。于是做到
当然,我们充分发挥人类智慧,发现当 N,于是直接枚举,如果不是就退出,在最劣点也拿到了 234ms 的好成绩,即使在USACO上总时间也仅仅只有660ms。
文件名打错挂了100。。。
#include <iostream>
using namespace std;
using ll = long long;
const ll kMaxN = 2e5 + 1;
string s, t;
ll q, c[kMaxN], cnts[kMaxN], cntt[kMaxN];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> s >> t >> q;
for (char i : s) {
cnts[i]++;
}
for (char i : t) {
cntt[i]++;
}
if (q <= 3000) {
for (string k; q; q--) {
for (ll i = 'a'; i <= 'z'; i++) {
c[i] = 0;
}
cin >> k;
ll cs = 0, ct = 0;
for (char i : k) {
c[i] = 1;
cs += cnts[i], ct += cntt[i];
}
if (cs != ct) {
cout << "N";
continue;
}
string a, b;
for (char i : s) {
if (c[i]) {
a += i;
}
}
for (char i : t) {
if (c[i]) {
b += i;
}
}
cout << (a == b ? "Y" : "N");
}
} else {
for (string k; q; q--) {
cin >> k;
if (k.size() == 1) {
cout << (cnts[k[0]] == cntt[k[0]] ? "Y" : "N");
} else {
for (ll i = 'a'; i <= 'z'; i++) {
c[i] = 0;
}
for (char i : k) {
c[i] = 1;
}
ll a = 0, b = 0, f = 1;
while (f) {
while (a < s.size() && !c[s[a]]) {
a++;
}
while (b < t.size() && !c[t[b]]) {
b++;
}
if (a == s.size()) {
f = b == t.size();
break;
} else if (b == t.size()) {
f = 0;
} else {
f = s[a] == t[b];
a++, b++;
}
}
cout << (f ? "Y" : "N");
}
}
}
return 0;
}
T3
奶龙题,不开 long long 见祖宗。
怎么别人都拿的树状数组。。。就只有我和 @haokee 和 @DFbd (我不会线段树) 用的线段树。。。
就是如果大于等于
#include <iostream>
using namespace std;
using ll = long long;
const ll kMaxN = 2e5 + 1;
ll n, x, a[kMaxN], t[kMaxN << 2];
void M(ll x, ll l, ll r, ll a, ll d) {
if (l > a || r < a) {
return;
}
if (l == r) {
t[x] += d;
return;
}
ll m = l + (r - l >> 1);
M(x << 1, l, m, a, d), M(x << 1 | 1, m + 1, r, a, d);
t[x] = t[x << 1] + t[x << 1 | 1];
}
ll Q(ll x, ll l, ll r, ll a, ll b) {
if (l > b || r < a) {
return 0;
}
if (a <= l && r <= b) {
return t[x];
}
ll m = l + (r - l >> 1);
return Q(x << 1, l, m, a, b) + Q(x << 1 | 1, m + 1, r, a, b);
}
int main() {
cin >> n >> x;
for (ll i = 1; i <= n; i++) {
cin >> a[i];
a[i] = (a[i] >= x ? 1 : -1);
}
M(1, -n, n, 0, 1);
ll ans = 0;
for (ll i = 1; i <= n; i++) {
a[i] += a[i - 1];
ans += Q(1, -n, n, -n, a[i]);
M(1, -n, n, a[i], 1);
}
cout << ans << '\n';
return 0;
}
T4
点分治,但是不会,遗憾离场
总结
nmd怎么挂怎么多分/jk