题解:P16663 [CSPro 25] 出行计划
题解
对于第
即:
解得:
合并:
记
因为核酸只能在正整时刻做,那么如果
于是问题转化为:
有
::::success[AC]
#include<bits/stdc++.h>
using namespace std;
const int M = 200005;
int cf[M];
int n, m, k;
int main(){
cin.tie(0) -> sync_with_stdio(0);
cin >> n >> m >> k;
for(int i = 0; i < n; i ++){
int t, c;
cin >> t >> c;
int r = t - k;
int l = r < c ? 1 : r - c + 1;
if(l <= r){
cf[l] ++;
cf[r + 1] --;
}
}
for(int i = 1; i < M; i ++) cf[i] += cf[i - 1];
for(int i = 0; i < m; i ++){
int x;
cin >> x;
cout << cf[x] << '\n';
}
return 0;
}
::::