Submission #1369447

#TimeUsernameProblemLanguageResultExecution timeMemory
1369447otariusAdriatic (CEOI13_adriatic)C++20
100 / 100
190 ms179096 KiB
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;

// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define ull unsigned long long
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rngl(chrono::steady_clock::now().time_since_epoch().count());

// #define int long long
// #define int unsigned long long

// #define ordered_set(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
// #define ordered_multiset(T) tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>

const ll mod = 1e9 + 7;
// const ll mod = 998244353;

const ll inf = 1e9;
const ll biginf = 1e18;
const int maxN = 25 * 1e4 + 15;
const int maxV = 2550;

int n, x[maxN], y[maxN], cnt[maxV][maxV], mnx[maxV][maxV], mxx[maxV][maxV], mny[maxV][maxV], mxy[maxV][maxV], tr[maxV][maxV], bl[maxV][maxV];
int calc_tr(int x, int y) {
    if (tr[x][y] != -1) return tr[x][y];
    if (cnt[x][2500] - cnt[x][y - 1] == 0) return tr[x][y] = 0;
    return tr[x][y] = cnt[x][2500] - cnt[x][y - 1] + calc_tr(min(x, mnx[x][y - 1]), max(y, mxy[x + 1][y]));
}
int calc_bl(int x, int y) {
    if (bl[x][y] != -1) return bl[x][y];
    if (cnt[2500][y] - cnt[x - 1][y] == 0) return bl[x][y] = 0;
    return bl[x][y] = cnt[2500][y] - cnt[x - 1][y] + calc_bl(max(x, mxx[x][y + 1]), min(y, mny[x - 1][y]));
}
void solve() {
    cin >> n;

    for (int i = 0; i <= 2500; i++) {
        for (int j = 0; j <= 2500; j++) {
            tr[i][j] = bl[i][j] = -1;
            mnx[i][j] = mny[i][j] = inf;
            mxx[i][j] = mxy[i][j] = 0;
        }
    }
    
    for (int i = 1; i <= n; i++) {
        cin >> x[i] >> y[i];
        cnt[x[i]][y[i]] = 1;
        mnx[x[i]][y[i]] = mxx[x[i]][y[i]] = x[i];
        mny[x[i]][y[i]] = mxy[x[i]][y[i]] = y[i];
    }

    for (int i = 1; i <= 2500; i++) {
        for (int j = 1; j <= 2500; j++) {
            cnt[i][j] = cnt[i][j] + cnt[i - 1][j] + cnt[i][j - 1] - cnt[i - 1][j - 1];
            mnx[i][j] = min({mnx[i][j], mnx[i - 1][j], mnx[i][j - 1]});
            mny[i][j] = min({mny[i][j], mny[i - 1][j], mny[i][j - 1]});
        }
    }

    for (int i = 2500; i >= 1; i--) {
        for (int j = 2500; j >= 1; j--) {
            mxx[i][j] = max({mxx[i][j], mxx[i + 1][j], mxx[i][j + 1]});
            mxy[i][j] = max({mxy[i][j], mxy[i + 1][j], mxy[i][j + 1]});
        }
    }

    for (int i = 1; i <= n; i++)
        cout << n - 3 + calc_tr(x[i], y[i]) + calc_bl(x[i], y[i]) << '\n';
}
int32_t main() { 
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
        cout << '\n';
    }
    return 0;
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...