Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main(){
- #ifdef ERFANUL007
- clock_t tStart = clock();
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- int t, cs = 0;
- scanf("%d", &t);
- while(t--){
- int n, q;
- scanf("%d %d", &n, &q);
- vector< pair< int, int> > shuru, sesh;
- for(int i=0; i<n; i++){
- int x, y;
- scanf("%d %d", &x, &y);
- shuru.push_back(make_pair(x, i));
- sesh.push_back(make_pair(y, i));
- }
- sort(shuru.begin(), shuru.end());
- sort(sesh.begin(), sesh.end());
- vector< pair< int, int > > v;
- for(int i=0; i<q; i++){
- int x;
- scanf("%d", &x);
- v.push_back(make_pair(x, i));
- }
- sort(v.begin(), v.end());
- set< int > s;
- int j=0, k=0, ans[q];
- for(int i=0; i < q; i++){
- while(j < (int)shuru.size() && shuru[j].first <= v[i].first){
- s.insert(shuru[j++].second);
- }
- while(k < (int)sesh.size() && sesh[k].first < v[i].first){
- s.erase(s.find(sesh[k++].second));
- }
- ans[v[i].second] = s.size();
- }
- printf("Case %d:\n", ++cs);
- for(int i=0; i<q; i++){
- printf("%d\n", ans[i]);
- }
- }
- #ifdef ERFANUL007
- fprintf(stderr, ">>> Runtime : %.9f\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
- #endif
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement