#include <bits/stdc++.h>
using namespace std;
#define MAXN 100001
#define MAXM 200001
int n, k, cnt(1);
int ans[MAXN];
int uread(){
int x(0);
char ch;
while ((ch = getchar()) < 48);
do{
x = (x << 1) + (x << 3) + (ch ^ 48);
}while ((ch = getchar()) > 47);
return x;
}
struct Val{
int a, b, c;
bool operator<(Val x)const{
if (a == x.a){
if (b == x.b) return c < x.c;
return b < x.b;
}
return a < x.a;
}
bool operator==(Val x){
return a == x.a && b == x.b && c == x.c;
}
}a[MAXN];
struct Node{
int val;
Node *ls, *rs;
Node(){
val = 0;
ls = rs = nullptr;
}
};
struct Seg{
Node *rt;
Seg(){
rt = nullptr;
}
void modify(Node *&now, int l, int r, int x, int k){
if (now == nullptr) now = new Node;
if (l == r){
now->val += k;
return;
}
int mid((l+r)>>1);
if (x <= mid) modify(now->ls, l, mid, x, k);
else modify(now->rs, mid+1, r, x, k);
now->val = (now->ls == nullptr ? 0 : now->ls->val) + (now->rs == nullptr ? 0 : now->rs->val);
}
int query(Node *now, int l, int r, int x){
if (now == nullptr) return 0;
if (r <= x) return now->val;
int mid((l+r)>>1), res(query(now->ls, l, mid, x));
if (r > x) res += query(now->rs, mid+1, r, x);
return res;
}
}tr[MAXM];
struct BIT{
#define lowbit(x) (x & -x)
int c[MAXM];
void add(int x, int y, int g){
while (x <= k){
tr[x].modify(tr[x].rt, 1, k, y, g);
x += lowbit(x);
}
}
int query(int x, int y){
int res(0);
while (x){
res += tr[x].query(tr[x].rt, 1, k, y);
x -= lowbit(x);
}
return res;
}
}tr2;
signed main(){
// freopen("P3810_4.in", "r", stdin);
// freopen("P3810_4.ans", "w", stdout);
n = uread();
k = uread();
for (int i(1); i<=n; ++i) a[i] = {uread(), uread(), uread()};
sort(a+1, a+n+1);
for (int i(1); i<=n; ++i){
if (a[i+1] == a[i]){
++cnt;
continue;
}
tr2.add(a[i].b, a[i].c, cnt);
ans[tr2.query(a[i].b, a[i].c)] += cnt;
cnt = 1;
}
for (int i(1); i<=n; ++i) printf("%d\n", ans[i]);
return 0;
}
发现 #4 需要 2 秒,应该是被卡常了吧。