2025-11-15 NOIP模拟赛总结
前言
炸了。
打的洛谷比赛,【LGR-250】洛谷 NOIP 2025 模拟赛,感觉要掉等级分了呜呜呜,都怪 cutezrr
A
最开始看了好久没发现做法,后来想了一下才发现有单调性。
可以设
不知道为什么,我以为答案不超过
突然感觉
确实寄掉了,long long 去掉后直接 AC,气死我了🤬
::::success[缺零分治 / mexdnc]
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int N = 1e5 + 5;
LL t, n, m, q, a[N], b[N], s[N];
LL C(int i) {
int l = 0, r = n + 1;
for (int o; l + 1 < r;)
b[o = l + r >> 1] >= i ? l = o : r = o;
return 1ll * i * l + s[n] - s[l];
}
int main() {
cin.tie(0)->sync_with_stdio(0);
for (cin >> t; t; t--) {
cin >> n >> q, a[0] = -1, b[0] = 1e9;
for (int i = 1; i <= n; i++) cin >> a[i] >> b[i];
if (a[1]) {
for (LL x; q; q--)
cin >> x, cout << (x ? -1 : 1) << "\n";
} else {
for (int i = 1; i <= n; i++)
a[i] != a[i - 1] + 1 && (b[i] = 0), b[i] = min(b[i - 1], b[i]);
partial_sum(b + 1, b + n + 1, s + 1);
for (m = 1; m < n && a[m + 1] == a[m] + 1; m++);
for (LL x; q; q--) {
cin >> x;
if (!x || x == m) {
cout << (x ? 1 : -1) << "\n";
} else {
int l = 1, r = b[1] + 2;
for (int o; l + 1 < r;)
C(o = l + r >> 1) >= x ? r = o : l = o;
cout << (r != b[1] + 2 ? r : -1) << "\n";
}
}
}
}
return 0;
}
::::
B
没看 老师我错了
C
最开始看题,发现
真正开始写才发现不太对,暴力是
还有
链的写着写着也发现不太好弄,但是
只有
::::success[树上求值 / tree]
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int N = 2e5 + 5;
LL n, _, h, M, a[2][21], c[2 * N], d[N], q[N], fa[N];
bool f[N];
vector<int> e[N];
void D(int u, int p) {
d[u] = d[p] + 1, fa[u] = p;
for (int v : e[u]) v != p && (D(v, u), 1);
}
void S(int u, int fa, int k) {
f[u] && (k = u), q[u] = k;
for (int v : e[u]) v != fa && (S(v, u, k), 1);
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for (int i = 1, u, v; i < n; i++) {
cin >> u >> v;
e[u].push_back(v), e[v].push_back(u);
}
for (cin >> _; _; _--) {
cin >> h >> M;
for (int i = 0; i < 2; i++)
for (int j = 0; j < 21; j++) cin >> a[i][j];
for (int i = 1; i <= 2 * n; i++) {
c[i] = 1;
for (int j = 0; j < 21; j++)
c[i] = c[i] * a[(i >> j) & 1][j] % M;
}
D(h, 0);
LL s = 0;
for (LL i = 1, x; i <= n; i++) {
fill(f + 1, f + n + 1, 0);
for (int x = i; x; x = fa[x]) f[x] = 1;
S(h, 0, 0), x = 0;
for (int j = 1; j <= n; j++) x = (x + c[j + d[q[j]]]) % M;
s ^= i * x;
}
cout << s << "\n";
}
return 0;
}
::::
D
没看
总结
下次不要在一道题上浪费太多时间,要合理安排。该开 long long 的变量开,不该开的地方不开,不然常熟太大直接 T 掉了😱