#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 250101
#define MAXS 20
#define INF 1000000000000000001
#define bb ' '
#define ln '\n'
#define Ln '\n'
#define MX 2520
typedef pair<short, short> pss;
int sum[MX][MX];
pss arr[MAX];
short u[MX][MX];
short d[MX][MX];
short l[MX][MX];
short r[MX][MX];
int X = 2510;
inline int get(int r1, int c1, int r2, int c2) { return sum[r2][c2] - sum[r1 - 1][c2] - sum[r2][c1 - 1] + sum[r1 - 1][c1 - 1]; }
inline int get(pss p1, pss p2) { if (p1.first > p2.first) swap(p1.first, p2.first); if (p1.second > p2.second) swap(p1.second, p2.second); return get(p1.first, p1.second, p2.first, p2.second); }
pss unxt[MX][MX];
pss dnxt[MX][MX];
ll udp[MX][MX];
ll ddp[MX][MX];
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
int N;
cin >> N;
short i, j;
for (i = 1; i <= N; i++) cin >> arr[i].first >> arr[i].second, sum[arr[i].first][arr[i].second]++;
for (i = 0; i <= X + 1; i++) for (j = 0; j <= X + 1; j++) l[i][j] = u[i][j] = 10101010;
for (i = 1; i <= X; i++) for (j = 1; j <= X; j++) {
if (sum[i][j]) {
u[i][j] = d[i][j] = i;
l[i][j] = r[i][j] = j;
}
sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
}
for (i = 1; i <= X; i++) for (j = 1; j <= X; j++) {
u[i][j] = min(u[i][j], min(u[i - 1][j], u[i][j - 1]));
l[i][j] = min(l[i][j], min(l[i - 1][j], l[i][j - 1]));
}
for (i = X; i >= 1; i--) for (j = X; j >= 0; j--) {
d[i][j] = max(d[i][j], max(d[i + 1][j], d[i][j + 1]));
r[i][j] = max(r[i][j], max(r[i + 1][j], r[i][j + 1]));
}
for (i = 1; i <= X; i++) for (j = 1; j <= X; j++) {
unxt[i][j] = pss(min(i, u[i - 1][j - 1]), max(j, r[i + 1][j + 1]));
dnxt[i][j] = pss(max(i, d[i + 1][j + 1]), min(j, l[i - 1][j - 1]));
}
for (i = 1; i <= X; i++) for (j = X; j >= 1; j--) udp[i][j] = get(pss(1, X), pss(i, j)) + udp[unxt[i][j].first][unxt[i][j].second];
for (i = X; i >= 1; i--) for (j = 1; j <= X; j++) ddp[i][j] = get(pss(X, 1), pss(i, j)) + ddp[dnxt[i][j].first][dnxt[i][j].second];
for (i = 1; i <= N; i++) cout << N - 3 + udp[arr[i].first][arr[i].second] + ddp[arr[i].first][arr[i].second] << ln;
}
Compilation message
adriatic.cpp: In function 'int main()':
adriatic.cpp:37:80: warning: overflow in conversion from 'int' to 'short int' changes value from '10101010' to '8466' [-Woverflow]
37 | for (i = 0; i <= X + 1; i++) for (j = 0; j <= X + 1; j++) l[i][j] = u[i][j] = 10101010;
| ^~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
190 ms |
223100 KB |
Output is correct |
2 |
Correct |
212 ms |
223172 KB |
Output is correct |
3 |
Correct |
188 ms |
223052 KB |
Output is correct |
4 |
Correct |
191 ms |
223164 KB |
Output is correct |
5 |
Correct |
187 ms |
223180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
185 ms |
223112 KB |
Output is correct |
2 |
Correct |
191 ms |
223112 KB |
Output is correct |
3 |
Correct |
186 ms |
223164 KB |
Output is correct |
4 |
Correct |
187 ms |
223156 KB |
Output is correct |
5 |
Correct |
195 ms |
223260 KB |
Output is correct |
6 |
Correct |
186 ms |
223184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
185 ms |
223212 KB |
Output is correct |
2 |
Correct |
184 ms |
223180 KB |
Output is correct |
3 |
Correct |
189 ms |
223280 KB |
Output is correct |
4 |
Correct |
187 ms |
223180 KB |
Output is correct |
5 |
Correct |
187 ms |
223280 KB |
Output is correct |
6 |
Correct |
201 ms |
223332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
204 ms |
223648 KB |
Output is correct |
2 |
Correct |
190 ms |
223584 KB |
Output is correct |
3 |
Correct |
192 ms |
223680 KB |
Output is correct |
4 |
Correct |
193 ms |
223564 KB |
Output is correct |
5 |
Correct |
190 ms |
223616 KB |
Output is correct |
6 |
Correct |
201 ms |
223692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2076 ms |
13832 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |