ccfcsp-202203(1、2)
202203-1 未初始化警告
#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;
}
202203-2 出行计划
差分算法
#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;
}