Advertisement
Guest User

Untitled

a guest
May 16th, 2017
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef struct lol {
  5.   int x, y, z;
  6. } troll;
  7.  
  8. int a[3505], i, j, rs, t, n, arb[3505][3505];
  9. troll c[3505];
  10.  
  11. bool cmp(const troll & a, const troll & b) {
  12.   return a.z < b.z;
  13. }
  14.  
  15. int query(int x, int y) {
  16.   int rs = 0;
  17.   for (int i = x; i >= 1; i -= -i & i)
  18.     for (int j = y; j >= 1; j -= -j & j)
  19.       rs = max(rs, arb[i][j]);
  20.   return rs;
  21. }
  22.  
  23. void update(int x, int y, int z) {
  24.   for (int i = x; i <= n; i += -i & i)
  25.     for (int j = y; j <= n; j += -j & j)
  26.       if (z > arb[i][j]) arb[i][j] = z;
  27. }
  28.  
  29. int main() {
  30.   cin >> n;
  31.   for(t = 1; t > 0; --t) {
  32.     for (i = 1; i <= n; ++i)
  33.       cin >> c[i].x >> c[i].y >> c[i].z;
  34.  
  35.     sort(c + 1, c + n + 1, cmp);
  36.  
  37.     for (rs = 1, i = 1; i <= n; ++i)
  38.       a[i] = query(c[i].x, c[i].y) + 1,
  39.       update(c[i].x, c[i].y, a[i]), rs = max(rs, a[i]);
  40.  
  41.     cout << rs << '\n';
  42.   }
  43.  
  44.   return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement