Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <string>
- #include <math.h>
- #include <climits>
- //#pragma GCC optimize("O3, unroll-loops");
- #include <list>
- #include <map>
- #include <set>
- #include <queue>
- #include <unordered_map>
- #include <unordered_set>
- //#include <chrono>
- //#include <fstream>
- //#include <bits/stdc++.h>
- #define mp make_pair
- #define pb push_back
- #define eb emplace_back
- #define x first
- #define y second
- #define sz(x) (int)x.size()
- #define all(x) begin(x), end(x)
- #define rall(x) rbegin(x), rend(x)
- #define FOR(i,a,b) for (int i = (a); i < (b); i++)
- #define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
- using namespace std;
- typedef unsigned long long ull;
- typedef long long ll;
- typedef long double ld;
- typedef pair<int, int> pi;
- typedef pair<ll, ll> pl;
- typedef vector<int> veci;
- typedef vector<bool> vecb;
- typedef vector<vector<int>> vvi;
- typedef vector<vector<bool>> vvb;
- const int INF_I = 1e9;
- const ll INF_LL = 1e18;
- int n;
- veci t;
- veci mod;
- void relax(int c, int tl, int tr) {
- if (mod[c] != 0 && (c << 1) + 1 < (n << 2)) {
- mod[c << 1] += mod[c];
- mod[(c << 1) + 1] += mod[c];
- t[c] += mod[c];
- mod[c] = 0;
- }
- }
- void update(int l, int r, int add, int c = 1, int tl = 0, int tr = n - 1) {
- if (l > r)
- return;
- if (l == tl && r == tr) {
- /*t[c] += add;*/
- mod[c] += add;
- }
- else {
- int tm = (tl + tr) >> 1;
- relax(c, tl, tr);
- update(l, min(tm, r), add, c << 1, tl, tm);
- update(max(l, tm + 1), r, add, (c << 1) + 1, tm + 1, tr);
- t[c] = max(t[c << 1] + mod[c<<1], t[(c << 1) + 1] + mod[(c << 1)+1]);
- }
- }
- int get_max(int l, int r, int c = 1, int tl = 0, int tr = n - 1) {
- if (l > r)
- return 0;
- if (l == tl && r == tr)
- return t[c] + mod[c];
- int tm = (tl + tr) >> 1;
- relax(c, tl, tr);
- return max(
- get_max(l, min(tm, r), c<<1, tl, tm),
- get_max(max(l, tm+1), r, (c<<1)+1, tm+1, tr)
- );
- }
- int main() {
- /*ifstream cin("in.txt");
- ofstream cout("out.txt");
- auto start_time = chrono::high_resolution_clock::now();*/
- ios::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- int k, m;
- cin >> n >> k >> m;
- n++;
- t.assign(n << 2, 0);
- mod.assign(n << 2, 0);
- for (int i = 0; i < m; i++) {
- int l, r;
- cin >> l >> r;
- l++, r--;
- if (get_max(l, r) < k) {
- cout << "1\n";
- update(l, r, 1);
- }
- else
- cout << "0\n";
- }
- /*auto end_time = chrono::high_resolution_clock::now();
- chrono::duration<double> duration = end_time - start_time;
- cout << duration.count() << "\n";
- cin.close();
- cout.close();*/
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment