Files
python/TangDou/LuoGuBook/P3913.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

31 lines
826 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e6 + 10;
LL n; //棋盘长、宽
int K; //注意这里要使用LL使用int会有部分测试点WA
// 原因是后面的去重返回的是LL如果这里有int,应该是会自动降为int导致出问题。
//行数组与列数组
int r[N], c[N];
int main() {
//加快读取速度
ios::sync_with_stdio(false);
cin.tie();
//棋盘的长宽和车的个数
cin >> n >> k;
//读入车的位置
for (int i = 1; i <= k; i++) cin >> r[i] >> c[i];
//排序
sort(r + 1, r + k + 1);
sort(c + 1, c + k + 1);
//去重
LL x = unique(r + 1, r + k + 1) - r - 1;
LL y = unique(c + 1, c + k + 1) - c - 1;
printf("%lld", n * n - (n - x) * (n - y));
return 0;
}