奇偶游戏
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <bits/stdc++.h> using namespace std; const int maxn = 1e4 + 10; int n,m,cnt,a[2 * maxn],fa[2 * maxn]; string str; struct node{ int l,r,ans; }que[maxn]; int find(int x){ if(x == fa[x]) return x; return fa[x] = find(fa[x]); } void read_discrete(){ cin >> n >> m; for(int i = 1; i <= m; i++) { cin >> que[i].l >> que[i].r >> str; que[i].ans = (str == "odd" ? 1 : 0); a[++cnt] = que[i].l - 1; a[++cnt] = que[i].r; } sort(a + 1,a + 1 + cnt); n = unique(a + 1, a + 1 + cnt) - a - 1; } signed main(){ // freopen("in","r",stdin); ios::sync_with_stdio(0); read_discrete(); for(int i = 0; i <= 2 * n; i++) fa[i] = i; for(int i = 1; i <= m; i++){ int x = lower_bound(a + 1, a + 1 + n,que[i].l - 1) - a; int y = lower_bound(a + 1, a + 1 + n,que[i].r) - a; int x_odd = x,x_even = x + n,y_odd = y,y_even = y + n; if(!que[i].ans){ if(find(x_odd) == find(y_even)){ cout << i - 1 << endl; return 0; } fa[find(x_odd)] = find(y_odd); fa[find(x_even)] = find(y_even); } else { if (find(x_odd) == find(y_odd)){ cout << i - 1 << endl; return 0; } fa[find(x_even)] = find(y_odd); fa[find(x_odd)] = find(y_even); } } cout << m << endl; return 0; }