Raslboyy

1361

Dec 26th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <string>
  5. #include <math.h>
  6. #include <climits>
  7.  
  8. //#pragma GCC optimize("O3, unroll-loops");
  9.  
  10. #include <list>
  11. #include <map>
  12. #include <set>
  13. #include <queue>
  14. #include <unordered_map>
  15. #include <unordered_set>
  16.  
  17. //#include <chrono>
  18. //#include <fstream>
  19. //#include <bits/stdc++.h>
  20.  
  21. #define mp make_pair
  22. #define pb push_back
  23. #define eb emplace_back
  24. #define x first
  25. #define y second
  26. #define sz(x) (int)x.size()
  27. #define all(x) begin(x), end(x)
  28. #define rall(x) rbegin(x), rend(x)
  29. #define FOR(i,a,b) for (int i = (a); i < (b); i++)
  30. #define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
  31.  
  32. using namespace std;
  33.  
  34. typedef unsigned long long ull;
  35. typedef long long ll;
  36. typedef long double ld;
  37. typedef pair<int, int> pi;
  38. typedef pair<ll, ll> pl;
  39. typedef vector<int> veci;
  40. typedef vector<bool> vecb;
  41. typedef vector<vector<int>> vvi;
  42. typedef vector<vector<bool>> vvb;
  43.  
  44. const int INF_I = 1e9;
  45. const ll INF_LL = 1e18;
  46.  
  47. int n;
  48. veci t;
  49. veci mod;
  50.  
  51. void relax(int c, int tl, int tr) {
  52.     if (mod[c] != 0 && (c << 1) + 1 < (n << 2)) {
  53.         mod[c << 1] += mod[c];
  54.         mod[(c << 1) + 1] += mod[c];
  55.         t[c] += mod[c];
  56.         mod[c] = 0;
  57.     }
  58. }
  59.  
  60. void update(int l, int r, int add, int c = 1, int tl = 0, int tr = n - 1) {
  61.     if (l > r)
  62.         return;
  63.     if (l == tl && r == tr) {
  64.         /*t[c] += add;*/
  65.         mod[c] += add;
  66.     }
  67.     else {
  68.         int tm = (tl + tr) >> 1;
  69.         relax(c, tl, tr);
  70.         update(l, min(tm, r), add, c << 1, tl, tm);
  71.         update(max(l, tm + 1), r, add, (c << 1) + 1, tm + 1, tr);
  72.         t[c] = max(t[c << 1] + mod[c<<1], t[(c << 1) + 1] + mod[(c << 1)+1]);
  73.     }
  74. }
  75.  
  76. int get_max(int l, int r, int c = 1, int tl = 0, int tr = n - 1) {
  77.     if (l > r)
  78.         return 0;
  79.     if (l == tl && r == tr)
  80.         return t[c] + mod[c];
  81.     int tm = (tl + tr) >> 1;
  82.     relax(c, tl, tr);
  83.     return max(
  84.         get_max(l, min(tm, r), c<<1, tl, tm),
  85.         get_max(max(l, tm+1), r, (c<<1)+1, tm+1, tr)
  86.     );
  87. }
  88.  
  89. int main() {
  90.     /*ifstream cin("in.txt");
  91.     ofstream cout("out.txt");
  92.     auto start_time = chrono::high_resolution_clock::now();*/
  93.  
  94.     ios::sync_with_stdio(false);
  95.     cin.tie(0);
  96.     cout.tie(0);
  97.  
  98.    
  99.     int k, m;
  100.     cin >> n >> k >> m;
  101.     n++;
  102.     t.assign(n << 2, 0);
  103.     mod.assign(n << 2, 0);
  104.  
  105.     for (int i = 0; i < m; i++) {
  106.         int l, r;
  107.         cin >> l >> r;
  108.         l++, r--;
  109.         if (get_max(l, r) < k) {
  110.             cout << "1\n";
  111.             update(l, r, 1);
  112.         }
  113.         else
  114.             cout << "0\n";
  115.     }
  116.    
  117.     /*auto end_time = chrono::high_resolution_clock::now();
  118.     chrono::duration<double> duration = end_time - start_time;
  119.     cout << duration.count() << "\n";
  120.     cin.close();
  121.     cout.close();*/
  122.     return 0;
  123. }
Advertisement
Add Comment
Please, Sign In to add comment