Advertisement
Guest User

394 Berhatton

a guest
Sep 6th, 2013
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.17 KB | None | 0 0
  1. #define _USE_MATH_DEFINES
  2.  
  3. #include <iostream>
  4. #include <math.h>
  5. #include <string.h>
  6. #include <string>
  7. #include <cmath>
  8. #include <stdio.h>
  9. #include <vector>
  10. #include <map>
  11. #include <list>
  12. #include <queue>
  13. #include <functional>
  14. #include <algorithm>
  15. #include <bitset>
  16. #include <set>
  17. #include <stack>
  18.  
  19. using namespace std;
  20.  
  21. #define REP(i,n) for(long long int i = 0; i < int(n); ++i)
  22. #define REPV(i, n) for (long long int i = (n) - 1; (int)i >= 0; --i)
  23. #define FOR(i, a, b) for(long long int i = (int)(a); i < (int)(b); ++i)
  24.  
  25. #define ALL(v) (v).begin(), (v).end()
  26. #define PF push_front
  27. #define PB push_back
  28. #define MP make_pair
  29. #define F first
  30. #define S second
  31.  
  32. #define lli long long int
  33.  
  34. const int N = 300000;
  35.  
  36. struct Event {
  37.     lli x, y0, y1;
  38.     int type, index;
  39.    
  40.     Event(lli xx, lli yy0, lli yy1, int t, int ind) {
  41.         x = xx;
  42.         y0 = yy0;
  43.         y1 = yy1;
  44.         type = t;
  45.         index = ind;
  46.     }
  47.  
  48.     bool operator<(const Event & that) const {
  49.         return (x == that.x ? type < that.type : x < that.x);
  50.     }
  51.  
  52.     bool operator>(const Event & that) const {
  53.         return (x == that.x ? type > that.type : x > that.x);
  54.     }
  55. };
  56.  
  57. int added[N << 2];
  58.  
  59. void update(int v, int l, int r, int left, int right, int delta) {
  60.     if (l == left && r == right) {        
  61.         added[v] += delta;
  62.         return;
  63.     }
  64.     int mid = (l+r) >> 1;
  65.     if (left <= mid) update(2*v + 1, l, mid, left, min(mid, right), delta);
  66.     if (right > mid) update(2*v + 2, mid + 1, r, max(mid + 1, left), right, delta);    
  67. }
  68.  
  69. int qGet(int v, int l, int r, int pos) {
  70.     if (l == r) {
  71.         return added[v];
  72.     }    
  73.     int m = (l+r) >> 1;
  74.     if (pos <= m) return added[v] + qGet(2*v+1, l, m, pos);
  75.     else return added[v] + qGet(2*v+2, m+1, r, pos);    
  76. }
  77.  
  78. int main()
  79. {
  80. ios_base::sync_with_stdio(0);
  81. #ifdef FILE_IO
  82.     freopen("input.txt", "r", stdin);
  83.     freopen("output.txt", "w", stdout);
  84. #endif 
  85.     int n, k;
  86.     cin >> n >> k;    
  87.     vector<lli> ys(3*n + 1);
  88.     priority_queue<Event, vector<Event>, greater<Event> > q;
  89.     REP(i, n) {
  90.         lli x, y, w;
  91.         cin >> x >> y >> w;
  92.         lli nx = x + y;
  93.         lli ny = x - y;        
  94.         q.push(Event(nx,     ny,     ny,      0, i + 1));
  95.         q.push(Event(nx - w, ny - w, ny + w, -1, i + 1));
  96.         q.push(Event(nx + w, ny - w, ny + w,  1, i + 1));
  97.         ys[3*i] = ny - w;
  98.         ys[3*i + 1] = ny + w;
  99.         ys[3*i + 2] = ny;
  100.     }
  101.     sort(ALL(ys));
  102.     set<int> ans;
  103.     int treeSize = (n * 3) + 1;
  104.     while(!q.empty()) {
  105.         Event e = q.top(); q.pop();
  106.         int y0 = lower_bound(ALL(ys), e.y0) - ys.begin();
  107.         int y1 = lower_bound(ALL(ys), e.y1) - ys.begin();
  108.         if (e.type == -1) {
  109.             update(0, 0, treeSize, y0, y1, 1);
  110.         } else if (e.type == 1) {
  111.             update(0, 0, treeSize, y0, y1, -1);
  112.         } else {
  113.             int count = qGet(0, 0, treeSize, y0);
  114.             if (count > k)
  115.                 ans.insert(e.index);
  116.         }
  117.     }
  118.     cout << ans.size() << endl;
  119.     for(set<int>::iterator i = ans.begin(); i != ans.end(); ++i) {
  120.         cout << (*i) << " ";
  121.     }
  122.     return 0;
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement