//#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("%I64d\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 = 1; j < BOARD; 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:14:37: warning: format '%d' expects argument of type 'int', but argument 2 has type 'll {aka long long int}' [-Wformat=]
#define prl(n) printf("%I64d\n", (n))
~~~^
adriatic.cpp:74:3: note: in expansion of macro 'prl'
prl(n - 3 + dp1[X[i]][Y[i]] + dp2[X[i]][Y[i]]);
^~~
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 |
Incorrect |
216 ms |
177272 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
220 ms |
177132 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
247 ms |
177532 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
271 ms |
179172 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
459 ms |
197608 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |