ccfcsp-202203(1、2)
#include <bits/stdc++.h>
using namespace std;
int main(){
int n, k;
cin >> n >> k;
int res = 0;
unordered_set<int> myset;
while(k--){
int x, y;
cin >> x >> y;
if(y != 0 && myset.find(y) == myset.end()){
res++;
}
myset.insert(x);
}
cout << res;
return 0;
}
差分算法
#include <bits/stdc++.h>
using namespace std;
const int N = 4e5+10;
int main(){
int n,m,k;
cin >> n >> m >> k;
vector<int> ans(N, 0);
for(int i = 0; i < n; i++){
int x,y;
cin >> x >> y;
int r = x - k;//最晚
int l = x - k - y + 1;//最早
if(r >= 0){
ans[max(1, l)]++;
ans[r + 1]--;
}
}
for(int i = 1; i < N; i++){
ans[i] = ans[i - 1] + ans[i];
}
for(int i = 0; i < m; i++){
int q;
cin >> q;
cout << ans[q] << endl;
}
return 0;
}
原文地址:https://blog.csdn.net/weixin_51503393/article/details/142025139
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!