Advertisement
SuitNdtie

Convention

May 27th, 2019
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.17 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<algorithm>
  3. using namespace std;
  4.  
  5. //coordinate compression function
  6. struct elem{
  7.     int val;
  8.     int idx;
  9.     char stats;
  10. };
  11. bool mycmp(elem a , elem b){
  12.     return (a.val < b.val);
  13. }
  14. struct compa{
  15.     int l;
  16.     int r;
  17. };
  18.  
  19.  
  20. int const N = 2e5+10;
  21. int seg[4*N]; //store max of subtree
  22. int sn;
  23.  
  24. int max(int a,int b){
  25.     return (a > b ? a : b);
  26. }
  27.  
  28. int lazy[4*N]; //store vaL to adding at seg[p]
  29.  
  30. void change(int &curstats,int newvalue){
  31.     curstats += newvalue;
  32. }
  33.  
  34. void push(int p,int b,int e){
  35.     if(lazy[p] == 0)return; //off symbol
  36.     seg[p] += lazy[p];
  37.     if(b != e){
  38.         change(lazy[p*2] , lazy[p]);
  39.         change(lazy[p*2+1] , lazy[p]);
  40.     }
  41.     lazy[p] = 0;
  42. }
  43.  
  44. int query(int l,int r,int p = 1 , int b = 0 , int e = sn - 1){
  45.     push(p,b,e);
  46.     if(b > r || e < l)return -1e9;
  47.     if(l <= b && e <= r)return seg[p];
  48.     int m = (b+e)/2;
  49.     return max(query(l,r,p*2,b,m) , query(l,r,p*2+1,m+1,e));
  50. }
  51.  
  52. void update(int l,int r,/*int k,*/int p = 1 , int b = 0 , int e = sn - 1){
  53.     push(p,b,e);
  54.     if(b > r || e < l)return;
  55.     if(l <= b && e <= r){
  56.         change(lazy[p],1);
  57.         push(p,b,e);
  58.         return;
  59.     }
  60.     int m = (b+e)/2;
  61.     update(l,r,p*2,b,m);
  62.     update(l,r,p*2 + 1,m+1,e);
  63.     seg[p] = max(seg[p*2],seg[p*2 + 1]);
  64. }
  65. int main()
  66. {
  67.     int n, k;
  68.     scanf("%d %d",&n,&k);
  69.     sn = n*2;
  70.     elem willsort[2*n];
  71.     for(int i = 0 ; i < n ; i ++){
  72.         scanf("%d %d",&willsort[i].val,&willsort[i+n].val);
  73.         willsort[i].idx = i;
  74.         willsort[i].stats = 'L';
  75.         willsort[i+n].idx = i;
  76.         willsort[i+n].stats = 'R';
  77.     }
  78.     sort(willsort,willsort+(2*n),mycmp);
  79.    
  80.     compa allcompa[n];
  81.    
  82.     int compressed = -1;
  83.     int prev = -1;
  84.     for(int i = 0 ; i < 2*n ; i ++){
  85.         if(willsort[i].val != prev){
  86.             compressed++;
  87.         }
  88.         if(willsort[i].stats == 'L'){
  89.             allcompa[willsort[i].idx].l = compressed;
  90.         }
  91.         else if(willsort[i].stats == 'R'){
  92.             allcompa[willsort[i].idx].r = compressed;
  93.         }
  94.  
  95.         prev = willsort[i].val;
  96.     }
  97.    
  98.    
  99.     for(int i = 0 ; i < n ; i ++){
  100.         int L = allcompa[i].l;
  101.         int R = allcompa[i].r;
  102.     //  printf("Test compa #%d: (%d,%d) -> ",i,L,R);
  103.         //to do segment tree lazy propagation
  104.         if(query(L,R) < k){
  105.             printf("yes\n");
  106.             update(L,R);
  107.         }
  108.         else{
  109.             printf("no\n");
  110.         }
  111.     }
  112.     return 0;
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement