#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 250000 + 7;
const int A = 2500 + 7;
const int INF = (int) 1e9 + 7;
int n;
int posr[N];
int posc[N];
int s[A][A];
int rmin[N];
int cmax[N];
int rmax[N];
int cmin[N];
int getsum(int r1, int c1, int r2, int c2)
{
assert(1 <= r1 && r1 <= r2 && r2 < A);
assert(1 <= c1 && c1 <= c2 && c2 < A);
return s[r2][c2] - s[r1 - 1][c2] - s[r2][c1 - 1] + s[r1 - 1][c1 - 1];
}
pair<int, int> next1(pair<int, int> current)
{
int r = current.first, c = current.second;
int r_new = r, c_new = c;
for (int i = 1; i <= n; i++)
{
if (posc[i] < c)
{
r_new = min(r_new, posr[i]);
}
if (posr[i] > r)
{
c_new = max(c_new, posc[i]);
}
}
assert(r_new == min(r, rmin[c - 1]));
assert(c_new == max(c, cmax[r + 1]));
return {r_new, c_new};
}
pair<int, int> next2(pair<int, int> current)
{
int r = current.first, c = current.second;
int r_new = r, c_new = c;
for (int i = 1; i <= n; i++)
{
if (posc[i] > c)
{
r_new = max(r_new, posr[i]);
}
if (posr[i] < r)
{
c_new = min(c_new, posc[i]);
}
}
assert(r_new == max(r, rmax[c + 1]));
assert(c_new == min(c, cmin[r - 1]));
return {r_new, c_new};
}
int main()
{
#ifdef ONPC
freopen ("input.txt", "r", stdin);
#endif // ONPC
#ifndef ONPC
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#endif // ONPC
for (int i = 0; i < N; i++)
{
rmin[i] = INF;
cmin[i] = INF;
}
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> posr[i] >> posc[i];
s[posr[i]][posc[i]]++;
rmin[posc[i]] = min(rmin[posc[i]], posr[i]);
cmax[posr[i]] = max(cmax[posr[i]], posc[i]);
rmax[posc[i]] = max(rmax[posc[i]], posr[i]);
cmin[posr[i]] = min(cmin[posr[i]], posc[i]);
}
for (int i = 1; i < A; i++)
{
rmin[i] = min(rmin[i - 1], rmin[i]);
cmin[i] = min(cmin[i - 1], cmin[i]);
}
for (int i = A - 2; i >= 0; i--)
{
cmax[i] = max(cmax[i + 1], cmax[i]);
rmax[i] = max(rmax[i + 1], rmax[i]);
}
for (int i = 1; i < A; i++)
{
int c = 0;
for (int j = 1; j < A; j++)
{
c += s[i][j];
s[i][j] = c + s[i - 1][j];
}
}
for (int init = 1; init <= n; init++)
{
ll sum = n - 3;
pair<int, int> current = {posr[init], posc[init]};
int curd = 1;
while (getsum(1, current.second, current.first, A - 1) >= 1)
{
curd++;
sum += getsum(1, current.second, current.first, A - 1);
current = next1(current);
}
curd = 1;
current = {posr[init], posc[init]};
while (getsum(current.first, 1, A - 1, current.second) >= 1)
{
curd++;
sum += getsum(current.first, 1, A - 1, current.second);
current = next2(current);
}
cout << sum << "\n";
}
return 0;
}
/**
**/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
26836 KB |
Output is correct |
2 |
Correct |
19 ms |
26836 KB |
Output is correct |
3 |
Correct |
19 ms |
26892 KB |
Output is correct |
4 |
Correct |
20 ms |
26856 KB |
Output is correct |
5 |
Correct |
23 ms |
26856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
187 ms |
26872 KB |
Output is correct |
2 |
Correct |
43 ms |
26836 KB |
Output is correct |
3 |
Correct |
695 ms |
26932 KB |
Output is correct |
4 |
Correct |
44 ms |
26836 KB |
Output is correct |
5 |
Correct |
82 ms |
26912 KB |
Output is correct |
6 |
Execution timed out |
2082 ms |
26908 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2100 ms |
26936 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2091 ms |
27092 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2081 ms |
28772 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |