社区讨论
0pts WA + RE 悬关求调 样例全过的
P1494[国家集训队] 小 Z 的袜子参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @lr2xjzgx
- 此快照首次捕获于
- 2024/01/07 11:24 2 年前
- 此快照最后确认于
- 2024/01/07 14:30 2 年前
CPP
#include<bits/stdc++.h>
#define N 1000005
using namespace std;
int n, m, sn, a[N], f[N], ans = 0, l = 1, r = 0;
struct _1 {
int que_l, que_r, que_id;
}q[N];
struct _2 {
int z, m;
}que_ans[N];
inline int read() {
int x = 0; char ch = getchar();
while (ch >= '0' && ch <= '9') x = (x << 1) + ch - '0', ch = getchar();
return x;
}
inline int gcd(int x, int y) { return !y ? x : gcd(y, x % y); }
inline bool cmp(_1 aa, _1 bb) {
return ((aa.que_l / sn) == (bb.que_l / sn)) ? ((aa.que_l % 2) == 0 ? (aa.que_r > bb.que_r) : (aa.que_r < aa.que_r)) : ((aa.que_l / sn) < (bb.que_l / sn));
}
inline void add(int x) {
ans += 2 * f[a[x]]++;
}
inline void sub(int x) {
ans -= 2 * --f[a[x]];
}
int main() {
n = read(), m = read(), sn = sqrt(n);
for (int i = 1; i <= n; i++) a[i] = read();
for (int i = 1; i <= m; i++) q[i].que_l = read(), q[i].que_r = read(), q[i].que_id = i;
sort(q + 1, q + 1 + m, cmp);
for (int i = 1; i <= m; i++) {
if (q[i].que_l == q[i].que_r) {
que_ans[q[i].que_id] = { 0, 1 };
continue;
}
while (l < q[i].que_l) sub(l++);
while (l > q[i].que_l) add(--l);
while (r < q[i].que_r) add(++r);
while (r > q[i].que_r) sub(r--);
que_ans[q[i].que_id].z = ans;
que_ans[q[i].que_id].m = (q[i].que_r - q[i].que_l + 1) * (q[i].que_r - q[i].que_l);
int _gcd = gcd(que_ans[q[i].que_id].z, que_ans[q[i].que_id].m);
que_ans[q[i].que_id].z /= _gcd;
que_ans[q[i].que_id].m /= _gcd;
}
for (int i = 1; i <= m; i++) {
cout << que_ans[i].z << '/' << que_ans[i].m << '\n';
}
return 0;
}
回复
共 0 条回复,欢迎继续交流。
正在加载回复...