直接用异或实现是否过马路的增量
C++ 代码
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
int id, side;
int res = 0;
map<int, int> st;
while (n--) {
cin >> id >> side;
if (st.find(id) != st.end())
res += side ^ st[id];
st[id] = side;
}
cout << res << endl;
return 0;
}