1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
| #include <cstdio> #include <cctype> #include <cstring> #include <algorithm> using namespace std; typedef long long LL; const int Mn(100500),Mk(200500);
template<typename T> void qrd(T& x) { x = 0; char c = getchar(); while(!isdigit(c)) { c = getchar(); } while(isdigit(c)) { x = x*10 + c-'0'; c = getchar(); } }
inline int lb(int x) { return x&-x; }
int n,k;
struct trip { int x,y,z,w,ans; bool operator < (const trip& rhs) const { if(x==rhs.x) { if(y==rhs.y) { return z<rhs.z; } return y<rhs.y; } return x<rhs.x; } bool operator == (const trip& rhs) const { return x==rhs.x && y==rhs.y && z==rhs.z; } bool operator != (const trip& rhs) const { return !(*this == rhs); } }atr[Mn],tmp[Mn];
int ans[Mn],c[Mk]; void mdf(int mx,int mk) { while(mx<=k) { c[mx] += mk; mx += lb(mx); } } int qry(int qx) { int ret(0); while(qx) { ret += c[qx]; qx -= lb(qx); } return ret; }
void cdq(int l,int r) { if(l==r) { return; } int mid((l+r)/2); cdq(l,mid), cdq(mid+1,r); memset(c+1,0,sizeof(int) * k); int pl(l),pr(mid+1); int ctmp(l-1); for(;pr<=r;++pr) { trip& rt(atr[pr]); while(pl<=mid && atr[pl].y<=rt.y) { mdf(atr[pl].z,atr[pl].w); tmp[++ctmp] = atr[pl++]; } rt.ans += qry(rt.z); tmp[++ctmp] = atr[pr]; } while(pl<=mid) { tmp[++ctmp] = atr[pl++]; } memcpy(atr+l,tmp+l,sizeof(trip)*(r-l+1)); }
int main() { qrd(n), qrd(k); for(int i(1);i<=n;++i) { trip& nt(atr[i]); qrd(nt.x), qrd(nt.y), qrd(nt.z); nt.w = 1; nt.ans = 0; } sort(atr+1,atr+n+1); int cnt(1); for(int i(2);i<=n;++i) { trip& nt(atr[i]); if(nt==atr[cnt]) { ++atr[cnt].w; } else { atr[++cnt] = nt; } } cdq(1,cnt); for(int i(1);i<=cnt;++i) { trip& nt(atr[i]); ans[nt.ans+nt.w-1] += nt.w; } for(int i(0);i<n;++i) { printf("%d\n",ans[i]); } return 0; }
|