题解 P7099 【[yLOI2020] 灼】
F
Algorithm 1
对于虫洞间距离不超过
Algorithm 2
考虑推一推式子。设
这个式子的意思是分别有
边界条件是在虫洞结点上
对于子任务
Algorithm 3
用高斯消元求解算法二中的式子,时间复杂度
Algorithm 4
验题人拉瓦手算带入消元得到了一个递推式,可以矩阵加速,时间复杂度
Algorithm 5
考虑把算法二中的式子乘二然后整理,可以得到
这就是说,
我们考虑正着推式子:对于
因此
因此
#include <cstdio>
#include <cctype>
#include <iostream>
#include <algorithm>
template <typename T>
inline void qr(T &x) {
char ch = getchar(); x = 0;
while (!isdigit(ch)) ch = getchar();
while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
}
const int maxn = 100005;
const int mod = 998244353;
int n, q;
int ans, answ, answe = -1, answer = mod + 1;
int a[maxn];
int main() {
qr(n); qr(n); qr(q);
for (int i = 1; i <= n; ++i) {
qr(a[i]);
}
std::sort(a + 1, a + 1 + n);
for (int x, p = 1; q; --q) {
qr(x);
while ((p < n) && (a[p] <= x)) ++p;
int y = 1ll * (x - a[p - 1]) * (a[p] - x) % mod;
ans ^= y;
if (y & 1) ++answ;
answe = std::max(answe, y);
answer = std::min(answer, y);
}
std::cout << ans << std::endl << answ << std::endl << answe << std::endl << answer << std::endl;
}