Advertisement
Guest User

timus1827

a guest
Oct 6th, 2011
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. const int MN = 1000 * 100 + 10;
  7.  
  8. struct block {
  9.     int x, y, d;
  10.     block () {};
  11.     block (int xx, int yy, int dd) {
  12.         x = xx, y = yy, d = dd;
  13.     }
  14.     bool operator<(const block &nw) const {
  15.         return (x < nw.x || (x == nw.x && y < nw.y) || (x == nw.x && y == nw.y && d < nw.d));
  16.     }
  17.     bool operator==(const block &nw) const {
  18.         return (x == nw.x && y == nw.y && d == nw.d);
  19.     }
  20. };
  21.  
  22. int arr[MN], n, m;
  23.  
  24. int cnt[MN];
  25.  
  26. block sp[MN];
  27.  
  28. char str[MN];
  29.  
  30. bool my_bin(int left, int right, block nw) {
  31.     while (left < right) {
  32.         int mid = (left + right) >> 1;
  33.         if (sp[mid] < nw)
  34.             left = mid + 1;
  35.         else right = mid;
  36.     }
  37.     return sp[right] == nw;
  38. }
  39.  
  40. int main() {
  41.     scanf("%d", &n);
  42.     for(int i = 0; i < n; i ++)
  43.         scanf("%d", &arr[i]);
  44.     scanf("%d", &m);
  45.     for(int i = 0; i < m; i ++)
  46.         scanf("%d%d%d", &sp[i].x, &sp[i].y, &sp[i].d);
  47.     sort(sp, sp + m);
  48.     for(int i = 0; i < n; i ++) {
  49.         for(int j = 49; j >= 0; j --) {
  50.             if (i + j >= n)
  51.                 continue;
  52.             block nw(arr[i + j], arr[i], j + 1);
  53.             if (my_bin(0, m - 1, nw)) {
  54.                 cnt[i] ++, cnt[i + j] --;
  55.                 break;
  56.             }
  57.         }
  58.     }
  59.     for(int i = 0, s = 0; i < n; i ++) {
  60.         if (cnt[i] > 0)
  61.             s += cnt[i];
  62.         if (s > 0)
  63.             str[i] = '1';
  64.         else str[i] = '0';
  65.         if (cnt[i] < 0)
  66.             s += cnt[i];
  67.     }
  68.     printf("%s", str);
  69.     return 0;
  70. }
  71.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement