题意
链接: link.
思路
用一个数组记录死亡次数模拟即可
AC代码
#include <bits/stdc++.h>
using namespace std;
const int N = 2E5 + 10;
int arr[N];
int main()
{
int n, m;
cin >> n >> m;
int a, b;
memset(arr, 0, sizeof(arr));
while (m--)
{
cin >> a >> b;
if (a < b)
{
arr[a]--;
}
else
{
arr[b]--;
}
}
int res = 0;
for (int i = 1; i <= n; i++)
{
if (arr[i] == 0)
res++;
}
int last = 0;
int q;
cin >> q;
int now, x, y;
while (q--)
{
cin >> now;
if (now == 1)
{
cin >> x >> y;
if (x < y)
{
arr[x]--;
if (arr[x] == -1)
last--;
}
}
if (now == 2)
{
cin >> x >> y;
if (x < y)
{
arr[x]++;
if (arr[x] == 0)
last++;
}
}
if (now == 3)
{
res = res + last;
last = 0;
cout << res << endl;
}
}
//system("pause");
return 0;
}