Advertisement
Guest User

IOI 2014 - Wall

a guest
Aug 22nd, 2014
1,654
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.81 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. typedef long long ll;
  4. using namespace std;
  5.  
  6. #define all(x) x.begin(), x.end()
  7. #define f(i,a,b) for(int i = (a); i <= (b); i++)
  8. #define fd(i,a,b) for(int i = (a); i >= (b); i--)
  9. #define mp make_pair
  10. #define faster_io() ios_base::sync_with_stdio(false)
  11. #define pb push_back
  12. #define pii pair<int,int>
  13. #define SZ(x) ((int)x.size())
  14. #define TRACE(x) cout << #x << " = " << x << "\n";
  15. #define vii vector<pair<int,int>>
  16.  
  17. const ll INFLL = 100000000000000000;
  18.  
  19. // --------------------------------------------------------------------------
  20.  
  21. const int RIGHT = (1<<21);
  22. const int SIZE = (1<<22)+5;
  23.  
  24. int D[SIZE], U[SIZE];
  25. int N, K;
  26.  
  27. void combine(int n, int d, int u)
  28. {
  29.     D[n] = min(D[n], d);
  30.     D[n] = max(D[n], u);
  31.     U[n] = max(U[n], u);
  32.     U[n] = min(U[n], d);
  33. }
  34.  
  35. void process(int n, char t, int h)
  36. {
  37.     if(t == 'd')
  38.     {
  39.         D[n] = min(D[n], h);
  40.         U[n] = min(U[n], h);
  41.     }
  42.     if(t == 'u')
  43.     {
  44.         D[n] = max(D[n], h);
  45.         U[n] = max(U[n], h);
  46.     }
  47. }
  48.  
  49. void update(int l, int r, char t, int h, int n, int a, int b)
  50. {
  51.     if(a > r || b < l) return;
  52.     if(a >= l && b <= r)
  53.     {
  54.         process(n,t,h);
  55.         return;
  56.     }
  57.  
  58.     combine(2*n, D[n], U[n]);
  59.     combine(2*n+1, D[n], U[n]);
  60.     D[n] = SIZE, U[n] = 0;
  61.  
  62.     int mid = (a+b) / 2;
  63.     update(l,r,t,h,2*n,a,mid);
  64.     update(l,r,t,h,2*n+1,mid+1,b);
  65. }
  66.  
  67. void complete()
  68. {
  69.     f(i,1,RIGHT-1)
  70.     {
  71.         combine(2*i, D[i], U[i]);
  72.         combine(2*i+1, D[i], U[i]);
  73.     }
  74. }
  75.  
  76. int main()
  77. {
  78.     scanf("%d%d", &N, &K);
  79.  
  80.     f(i,1,K)
  81.     {
  82.         int id, l, r, h;
  83.         scanf("%d%d%d%d", &id, &l, &r, &h);
  84.         char t = id==1 ? 'u' : 'd';
  85.         update(l+1,r+1,t,h,1,1,RIGHT);
  86.     }
  87.  
  88.     complete();
  89.     f(i,RIGHT,RIGHT+N-1) printf("%d\n", min(D[i],U[i]));
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement