Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <set>
- #include <vector>
- #include <cstdio>
- #include <algorithm>
- #include <stack>
- #include <math.h>
- using namespace std;
- int main() {
- freopen("input.txt", "r", stdin);
- int n, m;
- cin >> n;
- vector<pair<int, int>> a;
- for (int i = 0; i < n; ++i) {
- int x, y;
- cin >> x >> y;
- a.push_back({x, y});
- }
- sort(a.begin(), a.end());
- stack<pair<int, int>> st;
- vector<long long> ans;
- int b = 0;
- int cnt = 0;
- for (int i = 0; i < n; ++i) {
- if (a[i].second == -1) {
- b--;
- } else {
- b++;
- }
- if (b < 0) {
- b = 0;
- cnt++;
- } else {
- if (a[i].second == -1) {
- ans.push_back(ceil((a[i].first - st.top().first) / 2.0));
- st.pop();
- } else {
- st.push({a[i].first, i});
- }
- }
- }
- cnt += st.size();
- cin >> m;
- for (int i = 0; i < m; ++i) {
- int x;
- cin >> x;
- if (upper_bound(ans.begin(), ans.end(), x) == ans.end()) {
- cout << cnt << "\n";
- } else {
- cout << cnt + (ans.size() - (upper_bound(ans.begin(), ans.end(), x) - ans.begin())) * 2 << "\n";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement