题意:
有n个盒子,每次放一个,有向下和向左两种重力,每次重力作用后盒子的边长为多少;
思路:
每个盒子的边长贡献为4;
- 当这一行或者这一列有一个盒子则贡献-2
- 放盒子的这一行(列)的上一行(列)或者下一行(列)的盒子数大于这一行(列),则贡献-2
Code:
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <stack>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#define hz020 return
#define mes memset
#define mec memcpy
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int>pii;
const int N = 1000010;
const int null = 0x3f3f3f3f;
const ll mod = 1000000007;
int n;
int xx[N],yy[N];
int main()
{
scanf("%d",&n);
ll ans1 = 0,ans2 = 0;
for(int i = 1;i <= n;i ++)
{
int x,y;
scanf("%d %d",&x,&y);
ans1 += 4,ans2 += 4;
if(xx[x]) ans1 -= 2;
if(yy[y]) ans2 -= 2;
if(x != 0 && xx[x] < xx[x - 1]) ans1 -= 2;
if(y != 0 && yy[y] < yy[y - 1]) ans2 -= 2;
if(xx[x] < xx[x + 1]) ans1 -= 2;
if(yy[y] < yy[y + 1]) ans2 -= 2;
xx[x]++,yy[y]++;
cout << ans1 << " " << ans2 <<endl;
}
hz020 0;
}