#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 time |
Memory |
Grader output |
1 |
Correct |
74 ms |
73960 KB |
Output is correct |
2 |
Correct |
92 ms |
73912 KB |
Output is correct |
3 |
Correct |
71 ms |
73992 KB |
Output is correct |
4 |
Correct |
78 ms |
73900 KB |
Output is correct |
5 |
Correct |
72 ms |
73880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
77 ms |
73908 KB |
Output is correct |
2 |
Correct |
77 ms |
73928 KB |
Output is correct |
3 |
Correct |
81 ms |
74004 KB |
Output is correct |
4 |
Correct |
74 ms |
73936 KB |
Output is correct |
5 |
Correct |
75 ms |
73936 KB |
Output is correct |
6 |
Correct |
85 ms |
73912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
82 ms |
74012 KB |
Output is correct |
2 |
Correct |
77 ms |
74056 KB |
Output is correct |
3 |
Correct |
97 ms |
74032 KB |
Output is correct |
4 |
Correct |
82 ms |
74044 KB |
Output is correct |
5 |
Correct |
78 ms |
74044 KB |
Output is correct |
6 |
Correct |
116 ms |
74056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
159 ms |
74516 KB |
Output is correct |
2 |
Correct |
116 ms |
74552 KB |
Output is correct |
3 |
Correct |
115 ms |
74476 KB |
Output is correct |
4 |
Correct |
117 ms |
74488 KB |
Output is correct |
5 |
Correct |
111 ms |
74564 KB |
Output is correct |
6 |
Correct |
145 ms |
74484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
519 ms |
80152 KB |
Output is correct |
2 |
Correct |
519 ms |
80004 KB |
Output is correct |
3 |
Correct |
554 ms |
79868 KB |
Output is correct |
4 |
Correct |
491 ms |
79512 KB |
Output is correct |
5 |
Correct |
499 ms |
80096 KB |
Output is correct |
6 |
Correct |
519 ms |
80120 KB |
Output is correct |
7 |
Correct |
529 ms |
80328 KB |
Output is correct |