#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 25e4;
const int M = 2500;
struct Point { int x, y; };
int N, B[M+10][M+10];
Point A[MAXN+10];
int cnt[M+10][M+10];
int p1[M+10][M+10], q1[M+10][M+10];
int p2[M+10][M+10], q2[M+10][M+10];
int dp1[M+10][M+10], dp2[M+10][M+10];
int numpoint(int yy1, int yy2, int x1, int x2)
{
if(x1>x2) swap(x1, x2);
if(yy1>yy2) swap(yy1, yy2);
return cnt[yy2][x2]-cnt[yy1-1][x2]-cnt[yy2][x1-1]+cnt[yy1-1][x1-1];
}
int xx1(int i, int j) { return min(p2[i][1], p2[M][j]); }
int yy1(int i, int j) { return max(q2[i][1], q2[M][j]); }
int xx2(int i, int j) { return max(p1[i][M], p1[1][j]); }
int yy2(int i, int j) { return min(q1[i][M], q1[1][j]); }
int main()
{
int i, j;
scanf("%d", &N);
for(i=1; i<=N; i++) scanf("%d%d", &A[i].y, &A[i].x), B[A[i].y][A[i].x]++;
for(i=1; i<=M; i++) for(j=1; j<=M; j++) cnt[i][j]=cnt[i-1][j]+cnt[i][j-1]-cnt[i-1][j-1]+B[i][j];
for(i=1; i<=M; i++)
{
q1[M+1][i]=M+1;
q1[i][0]=M+1;
}
q1[M+1][0]=M+1;
for(i=M; i>=0; i--) for(j=1; j<=M+1; j++)
{
p1[i][j]=max(p1[i+1][j], p1[i][j-1]);
if(B[i][j]) p1[i][j]=j;
q1[i][j]=min(q1[i+1][j], q1[i][j-1]);
if(B[i][j]) q1[i][j]=i;
}
for(i=1; i<=M; i++)
{
p2[0][i]=M+1;
p2[i][M+1]=M+1;
}
p2[0][M+1]=M+1;
for(i=1; i<=M+1; i++) for(j=M; j>=0; j--)
{
p2[i][j]=min(p2[i-1][j], p2[i][j+1]);
if(B[i][j]) p2[i][j]=j;
q2[i][j]=max(q2[i-1][j], q2[i][j+1]);
if(B[i][j]) q2[i][j]=i;
}
for(i=M; i>=1; i--) for(j=1; j<=M; j++)
{
dp1[i][j]=dp1[max(i, yy1(i-1, j+1))][min(j, xx1(i-1, j+1))]+numpoint(i, M, 1, j);
}
for(i=1; i<=M; i++) for(j=M; j>=1; j--)
{
dp2[i][j]=dp2[min(i, yy2(i+1, j-1))][max(j, xx2(i+1, j-1))]+numpoint(1, i, j, M);
}
for(i=1; i<=N; i++) printf("%d\n", N+dp1[A[i].y][A[i].x]+dp2[A[i].y][A[i].x]-3);
/* printf("================\n");
for(i=1; i<=M; i++) { for(j=1; j<=M; j++) printf("%d ", dp1[i][j]); printf("\n"); };
printf("================\n");
for(i=1; i<=M; i++) { for(j=1; j<=M; j++) printf("%d ", dp2[i][j]); printf("\n"); }; */
}
Compilation message
adriatic.cpp: In function 'int main()':
adriatic.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &N);
~~~~~^~~~~~~~~~
adriatic.cpp:38:56: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(i=1; i<=N; i++) scanf("%d%d", &A[i].y, &A[i].x), B[A[i].y][A[i].x]++;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
252 ms |
172924 KB |
Output is correct |
2 |
Correct |
252 ms |
172908 KB |
Output is correct |
3 |
Correct |
252 ms |
172760 KB |
Output is correct |
4 |
Correct |
255 ms |
172628 KB |
Output is correct |
5 |
Correct |
254 ms |
172664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
254 ms |
176792 KB |
Output is correct |
2 |
Correct |
255 ms |
177784 KB |
Output is correct |
3 |
Correct |
255 ms |
177016 KB |
Output is correct |
4 |
Correct |
254 ms |
172920 KB |
Output is correct |
5 |
Correct |
251 ms |
173176 KB |
Output is correct |
6 |
Correct |
261 ms |
175096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
263 ms |
180856 KB |
Output is correct |
2 |
Correct |
259 ms |
186104 KB |
Output is correct |
3 |
Correct |
263 ms |
181428 KB |
Output is correct |
4 |
Correct |
258 ms |
173944 KB |
Output is correct |
5 |
Correct |
254 ms |
173792 KB |
Output is correct |
6 |
Correct |
286 ms |
182760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
290 ms |
183440 KB |
Output is correct |
2 |
Correct |
273 ms |
196984 KB |
Output is correct |
3 |
Correct |
275 ms |
183772 KB |
Output is correct |
4 |
Correct |
273 ms |
175992 KB |
Output is correct |
5 |
Correct |
260 ms |
175224 KB |
Output is correct |
6 |
Correct |
291 ms |
183336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
372 ms |
189560 KB |
Output is correct |
2 |
Correct |
404 ms |
202868 KB |
Output is correct |
3 |
Correct |
416 ms |
197340 KB |
Output is correct |
4 |
Correct |
385 ms |
185948 KB |
Output is correct |
5 |
Correct |
348 ms |
183036 KB |
Output is correct |
6 |
Correct |
384 ms |
191124 KB |
Output is correct |
7 |
Correct |
374 ms |
190840 KB |
Output is correct |