제출 #497841

#제출 시각아이디문제언어결과실행 시간메모리
497841SirCovidThe19th섬 항해 (CEOI13_adriatic)C++17
100 / 100
554 ms80328 KiB
#include <bits/stdc++.h>
using namespace std; 

#define FOR(i, x, y) for (int i = x; i < y; i++)

const int mx = 2505; 

int n, pre[mx][mx], largeR[mx], smallC[mx], largeC[mx], smallR[mx], dp1[mx][mx], dp2[mx][mx];

int main(){
    cin >> n; pair<int, int> pts[n];
    FOR(i, 0, mx) 
        smallR[i] = smallC[i] = 1e9;
    for (auto &[x, y] : pts){
        cin >> x >> y;
        pre[x][y]++;

        largeR[y] = max(largeR[y], x);
        smallC[x] = min(smallC[x], y);

        smallR[y] = min(smallR[y], x);
        largeC[x] = max(largeC[x], y);
    }
    FOR(i, 1, mx) FOR(j, 1, mx) 
        pre[i][j] += pre[i - 1][j] + pre[i][j - 1] - pre[i - 1][j - 1];
    FOR(i, 1, mx){
        smallR[i] = min(smallR[i], smallR[i - 1]); //smallest row to the left or at col i
        smallC[i] = min(smallC[i], smallC[i - 1]); //smallest col above or at row i
    }
    for (int i = mx - 1; i; i--){
        largeR[i] = max(largeR[i], largeR[i + 1]); //largest row to the right or at col i
        largeC[i] = max(largeC[i], largeC[i + 1]); //large col below or at row i
    }
    for (int i = mx - 1; i; i--) FOR(j, 1, mx){
        int r = max(i, largeR[j + 1]), c = min(j, smallC[i - 1]);
        dp1[i][j] = dp1[r][c] + pre[mx - 1][j] - pre[i - 1][j];
    }
    FOR(i, 1, mx) for (int j = mx - 1; j; j--){
        int r = min(i, smallR[j - 1]), c = max(j, largeC[i + 1]);
        dp2[i][j] = dp2[r][c] + pre[i][mx - 1] - pre[i][j - 1];
    }
    for (auto [x, y] : pts) cout<<dp1[x][y] + dp2[x][y] + n - 3<<endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...