#include
using namespace std;
#define int long long
using ll = long long;
using ull = unsigned long long;
#define vi vector<int>
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define inf 1ll << 62
#define ar(k) array<int, k>
#define db double
#define endl "\n"
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define de_bug(x) cerr << #x << "=" << x << endl
#define all(a) a.begin(), a.end()
#define IOS \
std::ios::sync_with_stdio(false); \
std::cin.tie(0); \
std::cout.tie(0);
#define fer(i, a, b) for (int i = a; i <= b; i++)
#define der(i, a, b) for (int i = a; i >= b; i--)
const int mod = 998244353;
const int N = 1e6 + 10;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int n, m, k;
struct node {
int a, b, c, cnt, num;
} e[N], d[N];
int ans[N];
int c[N];
bool cmp1(node x, node y) {
return x.a < y.a || (x.a == y.a && x.b < y.b) ||
(x.a == y.a && x.b == y.b && x.c < y.c);
}
bool cmp2(node x, node y) { return x.b < y.b || (x.b == y.b && x.c < y.c); }
void add(int a, int b) {
for (a; a <= k; a += (a & (-a))) c[a] += b;
}
int query(int a) {
int ans = 0;
for (; a; a -= (a & (-a))) {
ans += c[a];
}
return ans;
}
void cdq(int l, int r) {
if (l == r) return;
int mid = (l + r) >> 1;
//cout<
cdq(l, mid);
cdq(mid + 1, r);
int len1 = mid - l + 1;
int len2 = r - (mid + 1) +1;
sort(d + l, d + len1 + l, cmp2);
sort(d + mid + 1, d + mid + 1 + len2, cmp2);
vector<int> x;
for (int i = l, j = mid + 1; j <= r; j++) {
while (i <= mid && d[i].b <= d[j].b) {
add(d[i].c, d[i].num);
x.push_back(i);
i++;
}
d[j].cnt += query(d[j].c);
}
for (auto &it : x) {
add(d[it].c, -d[it].num);
}
}
void solve() {
cin >> n >> k;
fer(i, 1, n) {
int a, b, c;
cin >> a >> b >> c;
e[i] = {a, b, c, 0, 0};
}
sort(e + 1, e + 1 + n, cmp1);
int tt = 0;
int tot = 0;
for (int i = 1; i <= n; i++) {
tt++;
if (e[i].a != e[i + 1].a || e[i].b != e[i + 1].b || e[i].c != e[i + 1].c) {
d[++tot].a = e[i].a;
d[tot].b = e[i].b;
d[tot].c = e[i].c;
d[tot].num = tt;
tt = 0;
}
}
// cout<
cdq(1, tot);
for (int i = 1; i <= tot; i++) ans[d[i].cnt + d[i].num - 1] += d[i].num;
for (int i = 0; i < n; i++) {
cout << ans[i] << endl;
}
}
signed main() {
// freopen("../a.txt", "r", stdin);
// freopen("../b.txt", "w", stdout);
IOS;
int _ = 1;
// cin>>_;
while (_--) solve();
return 0;
}
二维数点
#include
using namespace std;
#define int long long
using ll = long long;
using ull = unsigned long long;
#define vi vector<int>
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define inf 1ll << 62
#define ar(k) array<int, k>
#define db double
#define endl "\n"
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define de_bug(x) cerr << #x << "=" << x << endl
#define all(a) a.begin(), a.end()
#define IOS \
std::ios::sync_with_stdio(false); \
std::cin.tie(0); \
std::cout.tie(0);
#define fer(i, a, b) for (int i = a; i <= b; i++)
#define der(i, a, b) for (int i = a; i >= b; i--)
const int mod = 998244353;
const int N = 2e6 + 10;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int n, m, k;
struct node {
int op,x,y,val,id;
} d[N];
int ans[N];
int c[N];
int w;
void add(int a, int b) {
for (a; a <= w; a += (a & (-a))) c[a] += b;
}
int query(int a) {
int ans = 0;
for (; a; a -= (a & (-a))) {
ans += c[a];
}
return ans;
}
bool cmp(node a,node b) {
return a.x<b.x;
}
void cdq(int l, int r) {
if (l == r) return;
int mid = (l + r) >> 1;
cdq(l, mid);
cdq(mid + 1, r);
sort(d+l,d+mid+1,cmp);
sort(d+mid+1,d+r+1,cmp);
vector<int> x;
for (int i = l, j = mid + 1; j <= r; j++) {
while (i <= mid && d[i].x <= d[j].x) {
if(d[i].op==1) {
add(d[i].y,d[i].val);
x.push_back(i);
}
i++;
}
// de_bug(d[j].id);
// de_bug(query(d[j].y));
if(d[j].op==2) ans[d[j].id]+=d[j].val*(query(d[j].y));
}
for (auto &it : x) {
add(d[it].y, -d[it].val);
}
}
void solve() {
int s;
cin>>s>>w;
int cnt=0;
int idx=0;
int op,x,y,x1,x2,y1,y2;
int v;
while(cin>>op&&op!=3) {
if(op==1) {
cin>>x>>y>>v;
d[++cnt]=(node) {
1,x,y,v,0
};
} else {
++idx;
cin>>x1>>y1>>x2>>y2;
d[++cnt]=(node) {
2,x2,y2,1,idx
};
d[++cnt]=(node) {
2,x1-1,y1-1,1,idx
};
d[++cnt]=(node) {
2,x1-1,y2,-1,idx
};
d[++cnt]=(node ) {
2,x2,y1-1,-1,idx
};
}
}
cdq(1,cnt);
//cout<
fer(i,1,idx) {
cout<<ans[i]<<endl;
}
}
signed main() {
// freopen("../a.txt", "r", stdin);
// freopen("../b.txt", "w", stdout);
IOS;
int _ = 1;
// cin>>_;
while (_--) solve();
return 0;
}
/*
5
1 2 3
1 2 2
1 3 4
2 1 1 5 5
2 2 2 2 2
*/