//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 3e5 + 5;
const int BOARD = 3e3 + 5;
const double eps = 1e-9;
int a[BOARD][BOARD];
ll dp1[BOARD][BOARD], dp2[BOARD][BOARD];
int X[MAXN], Y[MAXN], loX[BOARD], loY[BOARD], hiX[BOARD], hiY[BOARD];
ll f(int x1, int y1, int x2, int y2) {
return a[x2][y2] - a[x1-1][y2] - a[x2][y1-1] + a[x1-1][y1-1];
}
int main() {
int n; ni(n);
mem(loX, 0x3f);
mem(loY, 0x3f);
for (int i = 0; i < n; i++) {
ni(X[i]), ni(Y[i]);
a[X[i]][Y[i]]++;
loX[Y[i]] = min(loX[Y[i]], X[i]);
loY[X[i]] = min(loY[X[i]], Y[i]);
hiX[Y[i]] = max(hiX[Y[i]], X[i]);
hiY[X[i]] = max(hiY[X[i]], Y[i]);
}
for (int i = 2; i < BOARD; i++) {
loX[i] = min(loX[i-1], loX[i]);
loY[i] = min(loY[i-1], loY[i]);
hiX[BOARD-i] = max(hiX[BOARD-i], hiX[BOARD-i+1]);
hiY[BOARD-i] = max(hiY[BOARD-i], hiY[BOARD-i+1]);
}
for (int i = 1; i < BOARD; i++)
for (int j = 1; j < BOARD; j++)
a[i][j] += a[i][j-1] + a[i-1][j] - a[i-1][j-1];
for (int i = BOARD-1; i > 0; i--)
for (int j = 1; j < BOARD; j++)
dp1[i][j] = f(i, 1, BOARD-1, j) + dp1[max(i, hiX[j+1])][min(j, loY[i-1])];
for (int i = 1; i < BOARD; i++)
for (int j = BOARD-1; j > 0; j--)
dp2[i][j] = f(1, j, i, BOARD-1) + dp2[min(i, loX[j-1])][max(j, hiY[i+1])];
for (int i = 0; i < n; i++)
prl(n - 3 + dp1[X[i]][Y[i]] + dp2[X[i]][Y[i]]);
return 0;
}
Compilation message
adriatic.cpp: In function 'int main()':
adriatic.cpp:9:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
#define ni(n) scanf("%d", &(n))
~~~~~^~~~~~~~~~~~
adriatic.cpp:47:9: note: in expansion of macro 'ni'
int n; ni(n);
^~
adriatic.cpp:51:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
ni(X[i]), ni(Y[i]);
^
adriatic.cpp:51:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
210 ms |
177056 KB |
Output is correct |
2 |
Correct |
210 ms |
177004 KB |
Output is correct |
3 |
Correct |
209 ms |
177060 KB |
Output is correct |
4 |
Correct |
220 ms |
177156 KB |
Output is correct |
5 |
Correct |
234 ms |
177104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
216 ms |
177096 KB |
Output is correct |
2 |
Correct |
212 ms |
177108 KB |
Output is correct |
3 |
Correct |
214 ms |
177180 KB |
Output is correct |
4 |
Correct |
214 ms |
177144 KB |
Output is correct |
5 |
Correct |
211 ms |
177148 KB |
Output is correct |
6 |
Correct |
220 ms |
177008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
222 ms |
177152 KB |
Output is correct |
2 |
Correct |
213 ms |
177160 KB |
Output is correct |
3 |
Correct |
222 ms |
177352 KB |
Output is correct |
4 |
Correct |
214 ms |
177096 KB |
Output is correct |
5 |
Correct |
213 ms |
177164 KB |
Output is correct |
6 |
Correct |
253 ms |
177176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
257 ms |
177356 KB |
Output is correct |
2 |
Correct |
225 ms |
177656 KB |
Output is correct |
3 |
Correct |
235 ms |
177624 KB |
Output is correct |
4 |
Correct |
224 ms |
177612 KB |
Output is correct |
5 |
Correct |
221 ms |
177732 KB |
Output is correct |
6 |
Correct |
265 ms |
177784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
356 ms |
180996 KB |
Output is correct |
2 |
Correct |
365 ms |
182920 KB |
Output is correct |
3 |
Correct |
374 ms |
183020 KB |
Output is correct |
4 |
Correct |
344 ms |
182788 KB |
Output is correct |
5 |
Correct |
328 ms |
183108 KB |
Output is correct |
6 |
Correct |
362 ms |
183340 KB |
Output is correct |
7 |
Correct |
400 ms |
183508 KB |
Output is correct |