Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _USE_MATH_DEFINES
- #include <iostream>
- #include <math.h>
- #include <string.h>
- #include <string>
- #include <cmath>
- #include <stdio.h>
- #include <vector>
- #include <map>
- #include <list>
- #include <queue>
- #include <functional>
- #include <algorithm>
- #include <bitset>
- #include <set>
- #include <stack>
- using namespace std;
- #define REP(i,n) for(long long int i = 0; i < int(n); ++i)
- #define REPV(i, n) for (long long int i = (n) - 1; (int)i >= 0; --i)
- #define FOR(i, a, b) for(long long int i = (int)(a); i < (int)(b); ++i)
- #define ALL(v) (v).begin(), (v).end()
- #define PF push_front
- #define PB push_back
- #define MP make_pair
- #define F first
- #define S second
- #define lli long long int
- const int N = 300000;
- struct Event {
- lli x, y0, y1;
- int type, index;
- Event(lli xx, lli yy0, lli yy1, int t, int ind) {
- x = xx;
- y0 = yy0;
- y1 = yy1;
- type = t;
- index = ind;
- }
- bool operator<(const Event & that) const {
- return (x == that.x ? type < that.type : x < that.x);
- }
- bool operator>(const Event & that) const {
- return (x == that.x ? type > that.type : x > that.x);
- }
- };
- int added[N << 2];
- void update(int v, int l, int r, int left, int right, int delta) {
- if (l == left && r == right) {
- added[v] += delta;
- return;
- }
- int mid = (l+r) >> 1;
- if (left <= mid) update(2*v + 1, l, mid, left, min(mid, right), delta);
- if (right > mid) update(2*v + 2, mid + 1, r, max(mid + 1, left), right, delta);
- }
- int qGet(int v, int l, int r, int pos) {
- if (l == r) {
- return added[v];
- }
- int m = (l+r) >> 1;
- if (pos <= m) return added[v] + qGet(2*v+1, l, m, pos);
- else return added[v] + qGet(2*v+2, m+1, r, pos);
- }
- int main()
- {
- ios_base::sync_with_stdio(0);
- #ifdef FILE_IO
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- int n, k;
- cin >> n >> k;
- vector<lli> ys(3*n + 1);
- priority_queue<Event, vector<Event>, greater<Event> > q;
- REP(i, n) {
- lli x, y, w;
- cin >> x >> y >> w;
- lli nx = x + y;
- lli ny = x - y;
- q.push(Event(nx, ny, ny, 0, i + 1));
- q.push(Event(nx - w, ny - w, ny + w, -1, i + 1));
- q.push(Event(nx + w, ny - w, ny + w, 1, i + 1));
- ys[3*i] = ny - w;
- ys[3*i + 1] = ny + w;
- ys[3*i + 2] = ny;
- }
- sort(ALL(ys));
- set<int> ans;
- int treeSize = (n * 3) + 1;
- while(!q.empty()) {
- Event e = q.top(); q.pop();
- int y0 = lower_bound(ALL(ys), e.y0) - ys.begin();
- int y1 = lower_bound(ALL(ys), e.y1) - ys.begin();
- if (e.type == -1) {
- update(0, 0, treeSize, y0, y1, 1);
- } else if (e.type == 1) {
- update(0, 0, treeSize, y0, y1, -1);
- } else {
- int count = qGet(0, 0, treeSize, y0);
- if (count > k)
- ans.insert(e.index);
- }
- }
- cout << ans.size() << endl;
- for(set<int>::iterator i = ans.begin(); i != ans.end(); ++i) {
- cout << (*i) << " ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement