Thursday, May 18, 2023

Competive Programming ||

 #include <iostream>

#include "bits/stdc++.h"

using namespace std;


typedef unsigned long long ull;


int main()

{

ull n,k,q;

cin >> n >> k >> q;

vector<ull> temp(200001, 0);

vector<ull> bt(200001, 0);


for (int i = 0; i < n-1; ++i)

{

ull x,y;

cin >> x >> y;

temp[x]++;

temp[y+1]--;

}


ull sum = 0;

for(int i =0; i < 200001; i++)

{

sum += temp[i];

bt[i] = sum;

if(bt[i] >= k){

bt[i] = 1;

}

else

{

bt[i] = 0;

}

}


// final loop

for(int i = 1; i < 200001; i++)

{

bt[i] += bt[i- 1];

}


while(q--)

{

ull x,y;

cin >> x >> y;

ull ans = bt[y];

if(x - 1 >= 0){

ans -= bt[x - 1];

}

cout << ans << endl;

}


    return 0;

}


No comments:

Post a Comment