Advertisement
Helicator

caysoi.cpp

Dec 12th, 2021
469
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5. #define vi vector<int>
  6. #define ii pair<int,int>
  7. #define fi first
  8. #define sc second
  9. #define pb push_back
  10. #define stoi stoll
  11. #define popcnt __builtin_popcount
  12. #define getbit(x, k) ((x >> k) & 1)
  13. #define all(x) (x).begin(),(x).end()
  14. #define FOR(i,j,k) for(int i=j; i<k; i++)
  15. #define look(a) cerr <<#a<<": "<<a<<endl;
  16. #define look2(a,b) cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<< endl;
  17.  
  18. map<int,vi> listx,listy;
  19.  
  20. void solve()
  21. {
  22.     int n;
  23.     cin >> n;
  24.     FOR(i,0,n){
  25.         int x,y;
  26.         cin >> x;
  27.         cin >> y;
  28.         listx[x].pb(y);
  29.         listy[y].pb(x);
  30.     }
  31.     for (auto&itr:listx) sort(all(itr.sc));
  32.     for (auto&itr:listy) sort(all(itr.sc));
  33.     int p;
  34.     cin >> p;
  35.     FOR(i,0,p){
  36.         int x1,y1,x2,y2;
  37.         cin >> x1 >> y1 >> x2 >> y2;
  38.         int ans = 0;
  39.         ans += upper_bound(all(listx[x1]),y2-1) - lower_bound(all(listx[x1]),y1);
  40.         ans += upper_bound(all(listx[x2]),y2) - lower_bound(all(listx[x2]),y1+1);
  41.         ans += upper_bound(all(listy[y1]),x2) - lower_bound(all(listy[y1]),x1+1);
  42.         ans += upper_bound(all(listy[y2]),x2-1) - lower_bound(all(listy[y2]),x1);
  43.         cout << ans << '\n';
  44.     }
  45. }
  46.  
  47. signed main()
  48. {
  49.     cin.tie(0)->sync_with_stdio(0);
  50.     freopen("in", "r", stdin);
  51.     freopen("out", "w", stdout);
  52.     int T = 1;
  53.     // cin >> T;
  54.     while (T--) {
  55.         solve();
  56.         cout << '\n';
  57.     }
  58.     cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement