#pragma GCC optimize("Ofast") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; // BEGIN NO SAD #define rep(i, a, b) for(int i = a; i < (b); ++i) #define trav(a, x) for(auto& a : x) #define all(x) x.begin(), x.end() #define sz(x) (int)(x).size() #define mp make_pair #define pb push_back #define eb emplace_back #define lb lower_bound #define ub upper_bound typedef vector vi; #define f first #define s second #define derr if(1) cerr // END NO SAD template class y_combinator_result { Fun fun_; public: template explicit y_combinator_result(T &&fun): fun_(std::forward(fun)) {} template decltype(auto) operator()(Args &&...args) { return fun_(std::ref(*this), std::forward(args)...); } }; template decltype(auto) y_combinator(Fun &&fun) { return y_combinator_result>(std::forward(fun)); } template bool updmin(T& a, T b) { if(b < a) { a = b; return true; } return false; } template bool updmax(T& a, T b) { if(b > a) { a = b; return true; } return false; } typedef int64_t ll; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; int64_t xr; cin >> n >> xr; vector> pts(n); // x, y, v for(int i = 0; i < n; i++) cin >> pts[i][0] >> pts[i][1] >> pts[i][2]; vector ordbyorigin(n); iota(ordbyorigin.begin(), ordbyorigin.end(), 0); sort(ordbyorigin.rbegin(), ordbyorigin.rend(), [&](int a, int b) -> bool { return pts[a][1] * (pts[b][0] - xr) < (pts[a][0] - xr) * pts[b][1]; }); { vector t(n); for(int i = 0; i < n; i++) t[ordbyorigin[i]] = i; ordbyorigin.swap(t); } vector ord(n); iota(ord.begin(), ord.end(), 0); sort(ord.begin(), ord.end(), [&](int a, int b) -> bool { return pts[a][1] * pts[b][0] < pts[a][0] * pts[b][1]; }); vector ret(n); vector included(n); bitset<100005> bs; ll tot = 0; int maxseen = 0; for(auto out: ord) { if(ordbyorigin[out] > maxseen) { ret[out] = tot; maxseen = ordbyorigin[out]; } else { int curr = bs._Find_first(); while(curr < ordbyorigin[out]) { ret[out] += included[curr]; curr = bs._Find_next(curr); } } included[ordbyorigin[out]] = pts[out][2]; tot += pts[out][2]; bs.set(ordbyorigin[out]); } for(auto out: ret) cout << out << "\n"; }