Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define fi first
- #define se second
- #define pb push_back
- #define pf push_front
- #define popb pop_back
- #define popf pop_front
- #define ins insert
- #define pq priority_queue
- #define minele min_element
- #define maxele max_element
- #define lb lower_bound
- #define ub upper_bound
- #define cnt_bit __builtin_popcount
- #define debug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
- using namespace std;
- typedef long long ll;
- typedef pair<ll, ll> pll;
- typedef pair<int, int> pii;
- int d4x[4] = {1, 0, -1, 0}; int d4y[4] = {0, 1, 0, -1};
- int d8x[8] = {0, 1, 1, 1, 0, -1, -1, -1};
- int d8y[8] = {1, 1, 0, -1, -1, -1, 0, 1};
- const ll oo = 1e18;
- const ll maxN = 5000;
- void maximize(int &a, int b) {
- a = max(a, b);
- }
- void minimize(int &a, int b) {
- a = min(a, b);
- }
- struct P {
- int x, y, z;
- } f[maxN];
- struct F {
- int x, y, id;
- } a[maxN];
- int resL[maxN], resR[maxN];
- bool cmp(F _a, F _b) {
- if(max(_a.x, _a.y) == max(_b.x, _b.y)) {
- return min(_a.x, _a.y) < min(_b.x, _b.y);
- }
- return max(_a.x, _a.y) < max(_b.x, _b.y);
- }
- bool ok(P a, P b) {
- if(a.x < b.x) return true;
- else {
- if(a.x == b.x) {
- if(a.y < b.y) return true;
- else {
- if(a.y == b.y) {
- if(a.z <= b.z) return true;
- else return false;
- } else return false;
- }
- } else return false;
- }
- }
- void merge(P &a) {
- if(a.x < a.y) swap(a.x, a.y);
- if(a.x < a.z) swap(a.x, a.z);
- if(a.y < a.z) swap(a.y, a.z);
- if(a.y == a.z) {
- a.y++; a.z = 0;
- }
- if(a.x == a.y) {
- a.x++; a.y = 0;
- }
- if(a.x < a.y) swap(a.x, a.y);
- if(a.x < a.z) swap(a.x, a.z);
- if(a.y < a.z) swap(a.y, a.z);
- }
- void solve() {
- int n; cin >> n;
- for(int i = 1; i <= n; i++) cin >> a[i].x;
- for(int i = 1; i <= n; i++) cin >> a[i].y;
- for(int i = 1; i <= n; i++) a[i].id = i;
- sort(a + 1, a + 1 + n, cmp);
- // thu hang tot nhat
- for(int i = 1; i <= n; i++) {
- f[i].x = a[i].x, f[i].y = a[i].y, f[i].z = 1;
- merge(f[i]);
- int d = 2, ans = 0;
- for(int j = n; j >= 1; j--) {
- if(d > n) break;
- if(j == i) continue;
- f[j].x = a[j].x, f[j].y = a[j].y, f[j].z = d;
- merge(f[j]);
- while(!ok(f[i], f[j]) && d < n) {
- d++;
- f[j].x = a[j].x; f[j].y = a[j].y; f[j].z = d;
- merge(f[j]);
- }
- d++;
- if(ok(f[i], f[j])) ans++;
- }
- resL[a[i].id] = n - ans;
- }
- for(int i = 1; i <= n; i++) {
- f[i].x = a[i].x, f[i].y = a[i].y, f[i].z = n;
- merge(f[i]);
- int d = n - 1, ans = 0;
- for(int j = 1; j <= n; j++) {
- if(d < 1) break;
- if(j == i) continue;
- f[j].x = a[j].x, f[j].y = a[j].y, f[j].z = d;
- merge(f[j]);
- while(ok(f[i], f[j]) && d > 1) {
- d--;
- f[j].x = a[j].x; f[j].y = a[j].y; f[j].z = d;
- merge(f[j]);
- }
- d--;
- if(!ok(f[i], f[j])) ans++;
- }
- resR[a[i].id] = ans + 1;
- }
- for(int i = 1; i <= n; i++) {
- cout << resL[i] << " " << resR[i] << "\n";
- }
- }
- int main()
- {
- ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #else
- //online
- #endif
- solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement