#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<(x.F)<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
#define int ll
const int N=2525,m=2505;
int n,t,a[N],b[N],id[N][N],cnt[N][N],dp[N][N],pd[N][N];
pair<int,int> A[N*N];
int get(int sx,int sy,int tx,int ty){
sx--,sy--;
return cnt[tx][ty]-cnt[sx][ty]-cnt[tx][sy]+cnt[sx][sy];
}
void build(){
f(i,1,m+1){
f(j,1,m+1){
cnt[i][j]+=cnt[i-1][j]+cnt[i][j-1]-cnt[i-1][j-1];
}
}
}
void solvedp(){
a[0]=N;
f(i,1,m+1){
a[i]=a[i-1];
f(j,1,m+1){
if(id[i][j]){
minm(a[i],j);
}
}
}
b[m+1]=0;
f_(i,m,1){
b[i]=b[i+1];
f(j,1,m+1){
if(id[j][i]){
maxm(b[i],j);
}
}
}
f_(i,m,1){
f(j,1,m+1){
int x=max(i,b[j+1]),y=min(j,a[i-1]);
dp[i][j]=get(i,1,m,j)+dp[x][y];
}
}
}
void solvepd(){
a[m+1]=0;
f_(i,m,1){
a[i]=a[i+1];
f(j,1,m+1){
if(id[i][j]){
maxm(a[i],j);
}
}
}
b[0]=m+1;
f(i,1,m+1){
b[i]=b[i-1];
f(j,1,m+1){
if(id[j][i]){
minm(b[i],j);
}
}
}
f(i,1,m+1){
f_(j,m,1){
int x=min(i,b[j-1]),y=max(j,a[i+1]);
//cout<<i<<" "<<j<<" "<<x<<" "<<y<<endl;
pd[i][j]=get(1,j,i,m)+pd[x][y];
}
}
//eror(pd[6][1]);
}
main(){
ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin>>n;
f(i,1,n+1){
int x,y;
cin>>x>>y;
A[i]={x,y};
id[x][y]=i;
cnt[x][y]++;
}
build();
solvedp();
solvepd();
f(i,1,n+1){
int x=A[i].F,y=A[i].S;
cout<<dp[x][y]+pd[x][y]+n-3<<endl;
}
}
Compilation message
adriatic.cpp:96:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
96 | main(){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
198 ms |
149264 KB |
Output is correct |
2 |
Correct |
191 ms |
149384 KB |
Output is correct |
3 |
Correct |
199 ms |
149316 KB |
Output is correct |
4 |
Correct |
200 ms |
149060 KB |
Output is correct |
5 |
Correct |
193 ms |
149156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
212 ms |
153528 KB |
Output is correct |
2 |
Correct |
199 ms |
154564 KB |
Output is correct |
3 |
Correct |
206 ms |
153584 KB |
Output is correct |
4 |
Correct |
204 ms |
149372 KB |
Output is correct |
5 |
Correct |
199 ms |
149808 KB |
Output is correct |
6 |
Correct |
201 ms |
151620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
215 ms |
157568 KB |
Output is correct |
2 |
Correct |
216 ms |
165396 KB |
Output is correct |
3 |
Correct |
209 ms |
158020 KB |
Output is correct |
4 |
Correct |
209 ms |
150928 KB |
Output is correct |
5 |
Correct |
203 ms |
150340 KB |
Output is correct |
6 |
Correct |
236 ms |
159208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
268 ms |
160632 KB |
Output is correct |
2 |
Correct |
255 ms |
192432 KB |
Output is correct |
3 |
Correct |
240 ms |
161304 KB |
Output is correct |
4 |
Correct |
235 ms |
153556 KB |
Output is correct |
5 |
Correct |
229 ms |
152332 KB |
Output is correct |
6 |
Correct |
262 ms |
160548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
624 ms |
166900 KB |
Output is correct |
2 |
Correct |
594 ms |
206292 KB |
Output is correct |
3 |
Correct |
594 ms |
184844 KB |
Output is correct |
4 |
Correct |
569 ms |
168308 KB |
Output is correct |
5 |
Correct |
552 ms |
163028 KB |
Output is correct |
6 |
Correct |
588 ms |
172120 KB |
Output is correct |
7 |
Correct |
623 ms |
171136 KB |
Output is correct |