#include <bits/stdc++.h>
using namespace std;
const int mxN=2.5e5, mxC=2500;
int n, x[mxN], y[mxN], a[mxC][mxC], pa[mxC+1][mxC+1], uhbx[mxC+1], uhby[mxC+1], lhbx[mxC+1], lhby[mxC+1];
inline int spa(int x1, int y1, int x2, int y2) {
return pa[x2][y2]-pa[x1][y2]-pa[x2][y1]+pa[x1][y1];
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for(int i=0; i<n; ++i) {
cin >> x[i] >> y[i], --x[i], --y[i];
a[x[i]][y[i]]=i+1;
pa[x[i]+1][y[i]+1]=1;
}
for(int i=1; i<=mxC; ++i) {
for(int j=1; j<=mxC; ++j)
pa[i][j]+=pa[i][j-1];
for(int j=1; j<=mxC; ++j)
pa[i][j]+=pa[i-1][j];
uhbx[i]=uhbx[i-1];
for(int j=uhbx[i]?y[uhbx[i]-1]-1:mxC-1; j>=0; --j)
uhbx[i]=a[i-1][j]?a[i-1][j]:uhbx[i];
uhby[i]=uhby[i-1];
for(int j=uhby[i]?x[uhby[i]-1]-1:mxC-1; j>=0; --j)
uhby[i]=a[j][i-1]?a[j][i-1]:uhby[i];
}
for(int i=mxC-1; i>=0; --i) {
lhbx[i]=lhbx[i+1];
for(int j=lhbx[i]?y[lhbx[i]-1]+1:0; j<mxC; ++j)
lhbx[i]=a[i][j]?a[i][j]:lhbx[i];
lhby[i]=lhby[i+1];
for(int j=lhby[i]?x[lhby[i]-1]+1:0; j<mxC; ++j)
lhby[i]=a[j][i]?a[j][i]:lhby[i];
}
for(int i=0; i<n; ++i) {
int a1=pa[x[i]][y[i]], a2=spa(x[i]+1, y[i]+1, mxC, mxC), ans=-a1-a2-2, d=2;
if(a1+a2<n-1) {
int uh1=uhbx[x[i]]-1, uh2=uhby[y[i]]-1, lh1=lhby[y[i]+1]-1, lh2=lhbx[x[i]+1]-1;
if(!a1)
uh1=uh2=i;
if(!a2)
lh1=lh2=i;
while(1) {
++d;
a1=pa[x[lh1]][y[lh2]]+spa(x[uh2]+1, y[uh1]+1, mxC, mxC)-spa(x[uh2]+1, y[uh1]+1, x[lh1], y[lh2]);
ans-=a1;
if(a1>=n)
break;
int nuh1=uhbx[x[lh1]]-1, nuh2=uhby[y[lh2]]-1;
lh1=lhby[y[uh1]+1]-1, lh2=lhbx[x[uh2]+1]-1, uh1=nuh1, uh2=nuh2;
}
}
cout << ans+d*n << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
25336 KB |
Output is correct |
2 |
Correct |
51 ms |
25460 KB |
Output is correct |
3 |
Correct |
70 ms |
25460 KB |
Output is correct |
4 |
Correct |
92 ms |
25460 KB |
Output is correct |
5 |
Correct |
69 ms |
25460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
79 ms |
29684 KB |
Output is correct |
2 |
Correct |
47 ms |
30488 KB |
Output is correct |
3 |
Correct |
82 ms |
30488 KB |
Output is correct |
4 |
Correct |
115 ms |
30488 KB |
Output is correct |
5 |
Correct |
87 ms |
30488 KB |
Output is correct |
6 |
Correct |
106 ms |
30488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
130 ms |
33952 KB |
Output is correct |
2 |
Correct |
69 ms |
39088 KB |
Output is correct |
3 |
Correct |
96 ms |
39088 KB |
Output is correct |
4 |
Correct |
101 ms |
39088 KB |
Output is correct |
5 |
Correct |
85 ms |
39088 KB |
Output is correct |
6 |
Correct |
412 ms |
39088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
807 ms |
39088 KB |
Output is correct |
2 |
Correct |
92 ms |
50540 KB |
Output is correct |
3 |
Correct |
173 ms |
50540 KB |
Output is correct |
4 |
Correct |
100 ms |
50540 KB |
Output is correct |
5 |
Correct |
97 ms |
50540 KB |
Output is correct |
6 |
Correct |
1896 ms |
50540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2050 ms |
50540 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |