luyencode / comments

Server lưu trữ bình luận trên Luyện Code
https://luyencode.net
6 stars 3 forks source link

https://oj.luyencode.net/problem/OAKS #908

Open utterances-bot opened 1 year ago

utterances-bot commented 1 year ago

Chi tiết bài tập - undefined

https://oj.luyencode.net/problem/OAKS

tuananh99ptit commented 1 year ago

me cha hieu moe gi =))

102210292githug commented 12 months ago

Đây là lời giải của mình đã AC. Thấy có mấy bác AC < 1000ms, chỉ em với code của em gần 2000ms :(

Xem code AC

```cpp #include using namespace std; #define MOD 1000000007 //#define base 31 #define rep(i, n) for(int i = 1; i <= (n); i++) #define fo(i, n) for(int i = 0; i < (n); i++) #define per(i, n) for(int i = (n); i >= 1; i--) #define rfo(i, n) for(int i = (n-1); i >= 0; i--) #define pb push_back #define ff first #define ss second #define vt vector #define all(x) x.begin(),x.end() #define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin()) typedef unsigned long long ull; typedef long long ll; typedef pair pii; typedef pair pli; typedef pair pll; typedef map mii; typedef vt vti; const double Pi = acos(- 1.0); const int N = 1e6+6; const int inf = INT_MAX; templateostream& operator<<(std::ostream& os, const std::vector& vec) {for(T i : vec) os << i << ' '; return os;} void solve(){ int n; cin >> n; vt xy, yx; fo(i, n){ int x, y; cin >> x >> y; xy.pb({x, y}); yx.pb({y, x}); } sort(all(xy)); sort(all(yx)); int q; cin >> q; while(q--){ int x1, x2, y1, y2; cin >> x1 >> y1 >> x2 >> y2; int i1 = lower_bound(all(xy), pii({x1, y1})) - xy.begin(); int i2 = upper_bound(all(xy), pii({x1, y2})) - xy.begin(); int i3 = lower_bound(all(xy), pii({x2, y1})) - xy.begin(); int i4 = upper_bound(all(xy), pii({x2, y2})) - xy.begin(); int j1 = lower_bound(all(yx), pii({y1, x1})) - yx.begin(); int j2 = upper_bound(all(yx), pii({y1, x2})) - yx.begin(); int j3 = lower_bound(all(yx), pii({y2, x1})) - yx.begin(); int j4 = upper_bound(all(yx), pii({y2, x2})) - yx.begin(); int ans = (i2-i1) + (i4-i3) + (j2-j1) + (j4-j3); if(xy[i1] == pii({x1, y1})) ans -= 1; if(xy[i2-1] == pii({x1, y2})) ans -= 1; if(xy[i3] == pii({x2, y1})) ans -= 1; if(xy[i4-1] == pii({x2, y2})) ans -= 1; cout << ans << endl; } } int main(){ std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int t = 1;// cin >> t; while(t--) { solve(); } return 0; } /* Test: */ ```