This documentation is automatically generated by online-judge-tools/verification-helper
This project is maintained by tsutaj
#define IGNORE #define PROBLEM "https://atcoder.jp/contests/abc155/tasks/abc155_f" // #define _GLIBCXX_DEBUG // for STL debug (optional) #include <iostream> #include <iomanip> #include <cstdio> #include <string> #include <cstring> #include <deque> #include <list> #include <queue> #include <stack> #include <vector> #include <utility> #include <algorithm> #include <map> #include <set> #include <complex> #include <cmath> #include <limits> #include <cfloat> #include <climits> #include <ctime> #include <cassert> #include <numeric> #include <fstream> #include <functional> #include <bitset> using namespace std; using ll = long long int; using int64 = long long int; template<typename T> void chmax(T &a, T b) {a = max(a, b);} template<typename T> void chmin(T &a, T b) {a = min(a, b);} template<typename T> void chadd(T &a, T b) {a = a + b;} int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; const int INF = 1LL << 29; const ll LONGINF = 1LL << 60; const ll MOD = 1000000007LL; #include "../../../graph/linear_system_incidence.cpp" #include "../../../math/math_017_modint.cpp" using mint = ModInt<2>; int main() { int N, M; cin >> N >> M; vector< pair<int, int> > bomb; for(int i=0; i<N; i++) { int A, B; cin >> A >> B; bomb.emplace_back(A, B); } sort(bomb.begin(), bomb.end()); // 隣接 xor vector<mint> b(N + 1); b[0] = mint(bomb.front().second); for(int i=0; i+1<N; i++) { b[i+1] = mint(bomb[i].second ^ bomb[i+1].second); } b[N] = mint(bomb.back().second); vector< pair<int, int> > edges; vector<int> ids; for(int i=0; i<M; i++) { int L, R; cin >> L >> R; // 範囲内にある爆弾のインデックス [bl, br) int bl = lower_bound(bomb.begin(), bomb.end(), make_pair(L, 0)) - bomb.begin(); int br = upper_bound(bomb.begin(), bomb.end(), make_pair(R, 1)) - bomb.begin(); if(bl >= br) continue; edges.emplace_back(bl, br); ids.emplace_back(i); } M = edges.size(); // Ax + b = 0 -> Ax = b (mod 2) LinearSystemIncidence<mint> lsi(N+1, edges); auto ans = lsi.solve(b); if(!ans.first) cout << -1 << endl; else { vector<int> vec; for(int i=0; i<M; i++) { if(ans.second[i] == mint(1)) vec.emplace_back(ids[i]); } cout << vec.size() << endl; for(size_t i=0; i<vec.size(); i++) cout << vec[i] + 1 << " \n"[i + 1 == vec.size()]; } return 0; }
#line 1 "verifying_test/AtCoder/ABC155/linear_system_incidence.test.cpp" #define IGNORE #define PROBLEM "https://atcoder.jp/contests/abc155/tasks/abc155_f" // #define _GLIBCXX_DEBUG // for STL debug (optional) #include <iostream> #include <iomanip> #include <cstdio> #include <string> #include <cstring> #include <deque> #include <list> #include <queue> #include <stack> #include <vector> #include <utility> #include <algorithm> #include <map> #include <set> #include <complex> #include <cmath> #include <limits> #include <cfloat> #include <climits> #include <ctime> #include <cassert> #include <numeric> #include <fstream> #include <functional> #include <bitset> using namespace std; using ll = long long int; using int64 = long long int; template<typename T> void chmax(T &a, T b) {a = max(a, b);} template<typename T> void chmin(T &a, T b) {a = min(a, b);} template<typename T> void chadd(T &a, T b) {a = a + b;} int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; const int INF = 1LL << 29; const ll LONGINF = 1LL << 60; const ll MOD = 1000000007LL; #line 2 "graph/linear_system_incidence.cpp" /** * @brief 接続行列を係数に持つ線形方程式のソルバ * @docs docs/graph/linear_system_incidence.md */ #line 10 "graph/linear_system_incidence.cpp" #include <tuple> #line 12 "graph/linear_system_incidence.cpp" template <typename Tp> class LinearSystemIncidence { public: struct Edge { int id, to; bool is_forward; Edge(int id, int to, int is_forward) : id(id), to(to), is_forward(is_forward) {} }; LinearSystemIncidence(int N, const vector< pair<int, int> >& edges) : N(N), M(edges.size()), G(N) { for(int i=0; i<M; i++) { int u, v; tie(u, v) = edges[i]; G[u].emplace_back(i, v, true); G[v].emplace_back(i, u, false); } } Tp dfs(int u, const vector<Tp> &b) { assert(!used[u]); used[u] = true; Tp res = b[u]; for(const auto &e : G[u]) { if(used[e.to]) continue; Tp res_to = dfs(e.to, b); if(e.is_forward) x[e.id] = res_to; else x[e.id] = -res_to; res += res_to; } return res; } pair< bool, vector<Tp> > solve(vector<Tp> &b) { assert(static_cast<int>(b.size()) == N); used.assign(N, false); x.assign(M, Tp(0)); for(int i=0; i<N; i++) { if(used[i]) continue; Tp v = dfs(i, b); if(v != Tp(0)) return make_pair(false, vector<Tp>()); } return {true, move(x)}; } private: int N, M; vector< vector<Edge> > G; vector<bool> used; vector<Tp> x; // Ax = b }; #line 1 "math/math_017_modint.cpp" // ModInt begin using ll = long long; template<ll mod> struct ModInt { ll v; ll mod_pow(ll x, ll n) const { return (!n) ? 1 : (mod_pow((x*x)%mod,n/2) * ((n&1)?x:1)) % mod; } ModInt(ll a = 0) : v((a %= mod) < 0 ? a + mod : a) {} ModInt operator+ ( const ModInt& b ) const { return (v + b.v >= mod ? ModInt(v + b.v - mod) : ModInt(v + b.v)); } ModInt operator- () const { return ModInt(-v); } ModInt operator- ( const ModInt& b ) const { return (v - b.v < 0 ? ModInt(v - b.v + mod) : ModInt(v - b.v)); } ModInt operator* ( const ModInt& b ) const {return (v * b.v) % mod;} ModInt operator/ ( const ModInt& b ) const {return (v * mod_pow(b.v, mod-2)) % mod;} bool operator== ( const ModInt &b ) const {return v == b.v;} bool operator!= ( const ModInt &b ) const {return !(*this == b); } ModInt& operator+= ( const ModInt &b ) { v += b.v; if(v >= mod) v -= mod; return *this; } ModInt& operator-= ( const ModInt &b ) { v -= b.v; if(v < 0) v += mod; return *this; } ModInt& operator*= ( const ModInt &b ) { (v *= b.v) %= mod; return *this; } ModInt& operator/= ( const ModInt &b ) { (v *= mod_pow(b.v, mod-2)) %= mod; return *this; } ModInt pow(ll x) { return ModInt(mod_pow(v, x)); } // operator int() const { return int(v); } // operator long long int() const { return v; } }; template<ll mod> ModInt<mod> pow(ModInt<mod> n, ll k) { return ModInt<mod>(n.mod_pow(n.v, k)); } template<ll mod> ostream& operator<< (ostream& out, ModInt<mod> a) {return out << a.v;} template<ll mod> istream& operator>> (istream& in, ModInt<mod>& a) { in >> a.v; return in; } // ModInt end #line 46 "verifying_test/AtCoder/ABC155/linear_system_incidence.test.cpp" using mint = ModInt<2>; int main() { int N, M; cin >> N >> M; vector< pair<int, int> > bomb; for(int i=0; i<N; i++) { int A, B; cin >> A >> B; bomb.emplace_back(A, B); } sort(bomb.begin(), bomb.end()); // 隣接 xor vector<mint> b(N + 1); b[0] = mint(bomb.front().second); for(int i=0; i+1<N; i++) { b[i+1] = mint(bomb[i].second ^ bomb[i+1].second); } b[N] = mint(bomb.back().second); vector< pair<int, int> > edges; vector<int> ids; for(int i=0; i<M; i++) { int L, R; cin >> L >> R; // 範囲内にある爆弾のインデックス [bl, br) int bl = lower_bound(bomb.begin(), bomb.end(), make_pair(L, 0)) - bomb.begin(); int br = upper_bound(bomb.begin(), bomb.end(), make_pair(R, 1)) - bomb.begin(); if(bl >= br) continue; edges.emplace_back(bl, br); ids.emplace_back(i); } M = edges.size(); // Ax + b = 0 -> Ax = b (mod 2) LinearSystemIncidence<mint> lsi(N+1, edges); auto ans = lsi.solve(b); if(!ans.first) cout << -1 << endl; else { vector<int> vec; for(int i=0; i<M; i++) { if(ans.second[i] == mint(1)) vec.emplace_back(ids[i]); } cout << vec.size() << endl; for(size_t i=0; i<vec.size(); i++) cout << vec[i] + 1 << " \n"[i + 1 == vec.size()]; } return 0; }