Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include<iostream>
- #include<stack>
- #include<vector>
- #include<iterator>
- #include<cstdio>
- #include<algorithm>
- #define ll long long
- #define pb push_back
- #define sc second
- #define fst first
- using namespace std;
- ll poisk, t = 0;
- void binpoisk(ll znach, ll l, ll r, double *vec) {
- ll m;
- if (r - l <= 1) {
- poisk = r;
- /*if (vec[r] == znach || vec[l] == znach || vec[r]>znach) {
- poisk = r+1;
- }*/
- return;
- }
- else {
- m = (l + r) / 2;
- if (znach < vec[m]) {
- binpoisk(znach, l, m, vec);
- }
- else {
- binpoisk(znach, m, r, vec);
- }
- }
- }
- bool ssrt(pair <ll, bool> a, pair<ll, bool>b) {
- //t++;
- //cout << a.first << " " << b.first << endl;
- if (a.first > b.first) {
- return 0;
- }
- else {
- return 1;
- }
- }
- int main() {
- ll a, b, res1 = 0, m, c, n, i, j, k, l;
- //freopen("in.txt", "r", stdin);
- freopen("linear.in", "r", stdin);
- freopen("linear.out", "w", stdout);
- cin >> n;
- stack<ll>plus;
- stack<ll>minus;
- vector<double>res;
- vector<ll>vivod;
- vector< pair< ll, bool > >vec;
- for (i = 0; i < n; ++i) {
- cin >> a >> b;
- if (b == 1) {
- vec.pb(make_pair(a, 1));
- }
- else {
- vec.pb(make_pair(a, 0));
- }
- }
- sort(vec.begin(), vec.end(), ssrt);
- for (i = 0; i < n; ++i) {
- //если электрон
- if (vec[i].sc == 0) {
- if (plus.size() == 0) {
- res1++;
- }
- else {
- res.pb((vec[i].fst - plus.top()));
- res[res.size() - 1] /= 2;
- plus.pop();
- }
- }
- else if (vec[i].sc) {
- plus.push(vec[i].fst);
- }
- }
- sort(res.begin(), res.end());
- res1 += plus.size();
- cin >> m;
- for (i = 0; i < m; ++i) {
- cin >> a;
- if (a == 0) {
- vivod.pb(vec.size());
- }
- else {
- if ((m == 1 && a >= -100 && a <= 100)||(m>1)) {
- poisk = res.size();
- if (res.size() > 0) {
- poisk = -1;
- binpoisk(a, 0, res.size(), res.data());
- //if (poisk < res.size() && res[poisk] > a)poisk -= 1;
- /*for (j = 0; j < res.size(); ++j) {
- if (res[j] > a) {
- poisk = j;
- j = res.size();
- }
- }
- if (poisk == -1)poisk = res.size();
- */
- }
- vivod.pb((res.size() - poisk) * 2 + res1);
- }
- else {
- poisk = -1;
- if (res.size() > 0) {
- poisk = -1;
- //binpoisk(a, -1, res.size() - 1, res.data());
- //if (poisk < res.size() && res[poisk] > a)poisk -= 1;
- for (j = 0; j < res.size(); ++j) {
- if (res[j] > a) {
- poisk = j;
- j = res.size();
- }
- }
- if (poisk == -1)poisk = res.size();
- }
- vivod.pb((res.size() - poisk) * 2 + res1);
- }
- }
- t = 0;
- }
- for (i = 0; i < vivod.size(); ++i) {
- cout << vivod[i] << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement