样例过,交上去只对 Subtask #6 一个点。
#include <bits/stdc++.h>
#define N 2 * 114514
using namespace std;
int T, n, m, s1, s2;
bool i1[N], i2[N];
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> T;
while (T--) {
cin >> n >> m;
int ans = -1;
s1 = s2 = 0;
memset(i1, 0, sizeof i1);
memset(i2, 0, sizeof i2);
int i = 0;
while (m--) {
i++;
int type, num;
cin >> type >> num;
if (type == 1) {
s1++;
i1[num] = 1;
if (s1 == n && ans == -1) ans = i;
if (i2[num] && ans == -1) ans = i;
} else {
s2++;
i2[num] = 1;
if (s2 > 1 && ans == -1) ans = i;
if (i1[num] && ans == -1) ans = i;
}
}
cout << ans << "\n";
}
return 0;
}