#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];
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 |
219 ms |
149500 KB |
Output is correct |
2 |
Correct |
196 ms |
149308 KB |
Output is correct |
3 |
Correct |
203 ms |
149280 KB |
Output is correct |
4 |
Correct |
193 ms |
149268 KB |
Output is correct |
5 |
Correct |
192 ms |
149232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
200 ms |
153520 KB |
Output is correct |
2 |
Correct |
199 ms |
154568 KB |
Output is correct |
3 |
Correct |
204 ms |
153556 KB |
Output is correct |
4 |
Correct |
204 ms |
149472 KB |
Output is correct |
5 |
Correct |
199 ms |
149864 KB |
Output is correct |
6 |
Correct |
205 ms |
151644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
209 ms |
157612 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
254 ms |
160228 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
506 ms |
262144 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |