mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-24 03:31:59 +00:00
2038. [2009国家集训队]小Z的袜子(hose)
https://hydro.ac/d/bzoj/record/632308cebdf9bc31d160bf7d
This commit is contained in:
parent
546fa22701
commit
efa569b497
77
BZOJ/2038/2038.cpp
Normal file
77
BZOJ/2038/2038.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 50005;
|
||||
|
||||
int n, m, a[N], c[N], t;
|
||||
std::pair<long long, long long> now, ans[N];
|
||||
std::vector<std::tuple<int, int, int>> q;
|
||||
|
||||
void add(int x) {
|
||||
if (++c[x] > 1) {
|
||||
now.first += c[x] * (c[x] - 1) - (c[x] - 1) * (c[x] - 2);
|
||||
}
|
||||
}
|
||||
|
||||
void del(int x) {
|
||||
if (--c[x]) {
|
||||
now.first += c[x] * (c[x] - 1) - (c[x] + 1) * c[x];
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
cin >> n >> m;
|
||||
|
||||
t = sqrt(n);
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cin >> a[i];
|
||||
}
|
||||
|
||||
for (int i = 1, l, r; i <= m; i++) {
|
||||
cin >> l >> r;
|
||||
|
||||
q.push_back(std::make_tuple(i, l, r));
|
||||
}
|
||||
|
||||
std::sort(q.begin(), q.end(), [&](auto a, auto b) {
|
||||
int p = std::get<1>(a) / t,
|
||||
q = std::get<1>(b) / t;
|
||||
|
||||
return p == q ? std::get<2>(a) < std::get<2>(b) : p < q;
|
||||
});
|
||||
|
||||
int i = 0, j = 1, x, l, r;
|
||||
for (auto e : q) {
|
||||
std::tie(x, l, r) = e;
|
||||
|
||||
if (l == r) {
|
||||
ans[x] = std::make_pair(0, 1);
|
||||
} else {
|
||||
while (i < r) add(a[++i]);
|
||||
while (i > r) del(a[i--]);
|
||||
while (j < l) del(a[j++]);
|
||||
while (j > l) add(a[--j]);
|
||||
|
||||
now.second = 1ll * (r - l + 1) * (r - l);
|
||||
int g = std::__gcd(now.first, now.second);
|
||||
ans[x] = std::make_pair(now.first / g, now.second / g);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 1; i <= m; i++) {
|
||||
cout << ans[i].first << '/' << ans[i].second << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
BIN
BZOJ/2038/data/1.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/2038/data/1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2038/data/1.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/2038/data/1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2038/data/10.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/2038/data/10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2038/data/10.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/2038/data/10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2038/data/2.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/2038/data/2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2038/data/2.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/2038/data/2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2038/data/3.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/2038/data/3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2038/data/3.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/2038/data/3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2038/data/4.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/2038/data/4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2038/data/4.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/2038/data/4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2038/data/5.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/2038/data/5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2038/data/5.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/2038/data/5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2038/data/6.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/2038/data/6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2038/data/6.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/2038/data/6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2038/data/7.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/2038/data/7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2038/data/7.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/2038/data/7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2038/data/8.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/2038/data/8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2038/data/8.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/2038/data/8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2038/data/9.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/2038/data/9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2038/data/9.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/2038/data/9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user