fork download
  1. #include <iostream>
  2. #include <map>
  3. #include <vector>
  4. #include <queue>
  5. using namespace std;
  6. string fun(string s , int n) {
  7. if (s.size() == 1 && n == 1) {
  8. return s;
  9. }
  10. long long sm = 0;
  11. for (int i = 0; i < s.size(); i++) {
  12. sm += s[i] - '0';
  13. }
  14. sm *= n;
  15. return fun(to_string(sm) , 1);
  16. }
  17. int main() {
  18. ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  19. int n , k , q , l , r;
  20. cin >> n >> k >> q;
  21. vector<int> recp(200005 , 0) , pref(200005 , 0);
  22. for (int i = 0; i < n; i++) {
  23. cin >> l >> r;
  24. recp[l]++;
  25. recp[r+1]--;
  26. }
  27. for (int i = 1; i <= 200005; i++) {
  28. recp[i] += recp[i-1] ;
  29. }
  30. for (int i = 0; i <= 200005; i++) {
  31. if (recp[i] >= k) {
  32. pref[i] = 1;
  33. }
  34. }
  35. for (int i = 1; i <= 200005; i++) {
  36. pref[i] += pref[i-1] ;
  37. }
  38. while (q--) {
  39. cin >> l >> r;
  40. //cout << pref[l] << " " << pref[r] << endl;
  41. cout << pref[r] - pref [l-1] << endl;
  42. }
  43.  
  44.  
  45.  
  46. }
  47.  
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
Standard output is empty