题解:P11511 [ROIR 2017 Day 2] 大型线性对撞机
我们把
#include <bits/stdc++.h>
using namespace std;
namespace z {
#define int long long
const int N = 5e5 + 5;
#define x first
#define v second
pair<int, int> a[N];
stack<int> s;
int t[N];
void main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int n; cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i].x >> a[i].v;
memset(t, 0x3f, sizeof(t));
for(int i = 1; i <= n; i++) {
if(a[i].v == 1) s.push(i);
else {
if(s.empty()) continue;
int j = s.top(); s.pop();
t[i] = t[j] = (a[i].x - a[j].x + 1) / 2;
}
}
sort(t + 1, t + n + 1);
int j = 0, m, ans = n; cin >> m;
while(m--) {
int tt;
cin >> tt;
while(j < n && t[j + 1] <= tt) j++, ans--;
cout << ans << '\n';
}
}
#undef int
}
int main()
{
z::main();
return 0;
}