提交时间:2024-11-14 16:02:14

运行 ID: 34790

#include <bits/stdc++.h> #define int long long const int mod = 998244353; using namespace std; int n, T; struct node { int x, i; const bool operator < (const node y) const { return x < y.x; } } a[300005], b[300005]; int pos[300005], g[300005]; // inline int lb(int x) // { // return x & (-x); // } // inline void upd(int x, int y) // { // for (; x <= n; x += lb(x)) // { // // cerr << x << endl; // c[x] += y; // } // } // inline int qry(int x) // { // int res = 0; // for (; x >= 1; x -= lb(x)) // res += c[x]; // return res; // } signed main() { // freopen("sequence.in", "r", stdin); // freopen("sequence.out", "w", stdout); scanf("%lld %lld", &n, &T); for (int i = 1; i <= n; i++) { scanf("%lld", &a[i].x); a[i].i = i; } for (int i = 1; i <= n; i++) { scanf("%lld", &b[i].x); b[i].i = i; g[i] = i; } sort(a + 1, a + n + 1); sort(b + 1, b + n + 1); int ans = 0; for (int i = 1; i <= n; i++) { pos[a[i].i] = b[i].i; g[b[i].i] = a[i].i; ans += (a[i].x - b[i].x) % mod * ((a[i].x - b[i].x) % mod) % mod; ans %= mod; } printf("%lld ", ans); if (T == 0) return 0; ans = 0; for (int i = 1; i <= n; i++) { if (i != g[i]) { ans++; // printf("i:%lld %lld\n", i, pos[i]); swap(g[i], g[pos[i]]); swap(pos[g[i]], pos[g[pos[i]]]); // swap(pos[x[i]], pos[x[pos[i]]]); } // for (int j = 1; j <= n; j++) // printf("%lld ", x[j]); // puts(""); } // cout << endl; printf("%lld", ans); return 0; }