0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 18:28:47 +00:00

3236. [Ahoi2013] 作业

https://hydro.ac/d/bzoj/record/6322f16dbdf9bc31d160a4f9
This commit is contained in:
Baoshuo Ren 2022-09-15 18:23:42 +08:00
parent 882d6e0cd9
commit fefe23f287
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
41 changed files with 208 additions and 0 deletions

88
BZOJ/3236/3236.cpp Normal file
View File

@ -0,0 +1,88 @@
#include <iostream>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1e6 + 5;
int n, m, w[N], c[N], c1[N], c2[N], t;
std::pair<int, int> now, ans[N];
std::vector<std::tuple<int, int, int, int, int>> q;
inline int lowbit(int x) {
return x & -x;
}
void add(int *c, int x, int y) {
for (; x <= n; x += lowbit(x)) c[x] += y;
}
int sum(int *c, int x) {
int res = 0;
for (; x; x -= lowbit(x)) res += c[x];
return res;
}
void add(int x) {
if (!c[x]++) add(c1, x, 1);
add(c2, x, 1);
}
void del(int x) {
if (!--c[x]) add(c1, x, -1);
add(c2, x, -1);
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> w[i];
}
t = sqrt(n);
for (int i = 1, l, r, a, b; i <= m; i++) {
cin >> l >> r >> a >> b;
q.push_back(std::make_tuple(i, l, r, a, b));
}
std::sort(q.begin(), q.end(), [&](auto a, auto b) {
int p = std::get<1>(a) / t,
q = std::get<1>(b) / t;
int x = std::get<2>(a),
y = std::get<2>(b);
return p == q
? p & 1 ? x < y : x > y
: p < q;
});
int i = 0, j = 1;
for (auto &e : q) {
int id, l, r, a, b;
std::tie(id, l, r, a, b) = e;
while (i < r) add(w[++i]);
while (i > r) del(w[i--]);
while (j < l) del(w[j++]);
while (j > l) add(w[--j]);
ans[id] = std::make_pair(sum(c2, b) - sum(c2, a - 1), sum(c1, b) - sum(c1, a - 1));
}
for (int i = 1; i <= m; i++) {
cout << ans[i].first << ' ' << ans[i].second << endl;
}
return 0;
}

BIN
BZOJ/3236/data/1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/11.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/11.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/12.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/12.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/13.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/13.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/14.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/14.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/15.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/15.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/16.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/16.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/17.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/17.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/18.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/18.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/19.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/19.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/20.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/20.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/3236/data/9.out (Stored with Git LFS) Normal file

Binary file not shown.