Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Task : _example
- Author : Phumipat C. [MAGCARI]
- Language: C++
- Created : 18 December 2022 [08:12]
- */
- #include<bits/stdc++.h>
- using namespace std;
- int main(){
- cin.tie(0)->sync_with_stdio(0);
- cin.exceptions(cin.failbit);
- int n,m,q;
- vector<pair<int ,int> > v;
- vector<int > firstMagnet;
- cin >> n >> m >> q;
- for(int i=1;i<=m;i++){
- int a,k;
- cin >> a >> k;
- v.push_back({a,1});
- v.push_back({a+k,-1});
- }
- sort(v.begin(),v.end());
- int last = 0,cnt = 0,j;
- firstMagnet.push_back(1);
- for(int i=0;i<v.size();i=j){
- for(j=i;j < v.size() && v[i].first == v[j].first;j++)
- cnt+=v[j].second;
- if(cnt%2 != last){
- firstMagnet.push_back(v[i].first);
- last = 1-last;
- }
- }
- firstMagnet.push_back(n+1);
- while(q--){
- int num;
- cin >> num;
- int idx = upper_bound(firstMagnet.begin(),firstMagnet.end(),num)-firstMagnet.begin();
- cout << firstMagnet[idx]-firstMagnet[idx-1] << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment