Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<algorithm>
- using namespace std;
- //coordinate compression function
- struct elem{
- int val;
- int idx;
- char stats;
- };
- bool mycmp(elem a , elem b){
- return (a.val < b.val);
- }
- struct compa{
- int l;
- int r;
- };
- int const N = 2e5+10;
- int seg[4*N]; //store max of subtree
- int sn;
- int max(int a,int b){
- return (a > b ? a : b);
- }
- int lazy[4*N]; //store vaL to adding at seg[p]
- void change(int &curstats,int newvalue){
- curstats += newvalue;
- }
- void push(int p,int b,int e){
- if(lazy[p] == 0)return; //off symbol
- seg[p] += lazy[p];
- if(b != e){
- change(lazy[p*2] , lazy[p]);
- change(lazy[p*2+1] , lazy[p]);
- }
- lazy[p] = 0;
- }
- int query(int l,int r,int p = 1 , int b = 0 , int e = sn - 1){
- push(p,b,e);
- if(b > r || e < l)return -1e9;
- if(l <= b && e <= r)return seg[p];
- int m = (b+e)/2;
- return max(query(l,r,p*2,b,m) , query(l,r,p*2+1,m+1,e));
- }
- void update(int l,int r,/*int k,*/int p = 1 , int b = 0 , int e = sn - 1){
- push(p,b,e);
- if(b > r || e < l)return;
- if(l <= b && e <= r){
- change(lazy[p],1);
- push(p,b,e);
- return;
- }
- int m = (b+e)/2;
- update(l,r,p*2,b,m);
- update(l,r,p*2 + 1,m+1,e);
- seg[p] = max(seg[p*2],seg[p*2 + 1]);
- }
- int main()
- {
- int n, k;
- scanf("%d %d",&n,&k);
- sn = n*2;
- elem willsort[2*n];
- for(int i = 0 ; i < n ; i ++){
- scanf("%d %d",&willsort[i].val,&willsort[i+n].val);
- willsort[i].idx = i;
- willsort[i].stats = 'L';
- willsort[i+n].idx = i;
- willsort[i+n].stats = 'R';
- }
- sort(willsort,willsort+(2*n),mycmp);
- compa allcompa[n];
- int compressed = -1;
- int prev = -1;
- for(int i = 0 ; i < 2*n ; i ++){
- if(willsort[i].val != prev){
- compressed++;
- }
- if(willsort[i].stats == 'L'){
- allcompa[willsort[i].idx].l = compressed;
- }
- else if(willsort[i].stats == 'R'){
- allcompa[willsort[i].idx].r = compressed;
- }
- prev = willsort[i].val;
- }
- for(int i = 0 ; i < n ; i ++){
- int L = allcompa[i].l;
- int R = allcompa[i].r;
- // printf("Test compa #%d: (%d,%d) -> ",i,L,R);
- //to do segment tree lazy propagation
- if(query(L,R) < k){
- printf("yes\n");
- update(L,R);
- }
- else{
- printf("no\n");
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement