0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-19 22:25:27 +00:00
Baoshuo Ren 2022-05-25 14:26:35 +08:00
parent 98a50dc842
commit 8c2a73265d
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68
3 changed files with 117 additions and 0 deletions

111
AcWing/2815/2815.cpp Normal file
View File

@ -0,0 +1,111 @@
#include <algorithm>
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 2e5 + 5;
struct node {
int a, b, c, cnt, res;
node()
: a(0), b(0), c(0), cnt(0), res(0) {}
node(int _a, int _b, int _c)
: a(_a), b(_b), c(_c), cnt(1), res(0) {}
bool operator<(const node& x) const {
return a == x.a ? b == x.b ? c < x.c : b < x.b : a < x.a;
}
bool operator==(const node& x) const {
return a == x.a && b == x.b && c == x.c;
}
} q[N], w[N];
int n, k, ans[N];
int c[N];
inline int lowbit(int x) {
return x & -x;
}
void add(int x, int y) {
for (; x <= 2e5; x += lowbit(x)) c[x] += y;
}
int sum(int x) {
int res = 0;
for (; x; x -= lowbit(x)) res += c[x];
return res;
}
void merge_sort(int l, int r) {
if (l >= r) return;
int mid = l + r >> 1;
merge_sort(l, mid);
merge_sort(mid + 1, r);
int i = l, j = mid + 1, k = 0;
while (i <= mid && j <= r) {
if (q[i].b <= q[j].b) {
add(q[i].c, q[i].cnt);
w[++k] = q[i++];
} else {
q[j].res += sum(q[j].c);
w[++k] = q[j++];
}
}
while (i <= mid) {
add(q[i].c, q[i].cnt);
w[++k] = q[i++];
}
while (j <= r) {
q[j].res += sum(q[j].c);
w[++k] = q[j++];
}
for (int i = l; i <= mid; i++) add(q[i].c, -q[i].cnt);
for (int i = l, j = 1; j <= k; i++, j++) q[i] = w[j];
}
int main() {
std::ios::sync_with_stdio(false);
cin >> n >> k;
for (int i = 1, a, b, c; i <= n; i++) {
cin >> a >> b >> c;
q[i] = node(a, b, c);
}
std::sort(q + 1, q + 1 + n);
int k = 1;
for (int i = 2; i <= n; i++) {
if (q[i] == q[k]) {
q[k].cnt++;
} else {
q[++k] = q[i];
}
}
merge_sort(1, k);
for (int i = 1; i <= k; i++) {
ans[q[i].res + q[i].cnt - 1] += q[i].cnt;
}
for (int i = 0; i < n; i++) {
cout << ans[i] << endl;
}
return 0;
}

BIN
AcWing/2815/data/1.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
AcWing/2815/data/1.in (Stored with Git LFS) Normal file

Binary file not shown.