#include using namespace std; #define INF_LL (int64)1e18 #define INF (int32)1e9 #define REP(i, n) for(int64 i = 0;i < (n);i++) #define FOR(i, a, b) for(int64 i = (a);i < (b);i++) #define all(x) x.begin(),x.end() #define fs first #define sc second using int32 = int_fast32_t; using uint32 = uint_fast32_t; using int64 = int_fast64_t; using uint64 = uint_fast64_t; using PII = pair; using PLL = pair; const double eps = 1e-10; templateinline void chmin(A &a, B b){if(a > b) a = b;} templateinline void chmax(A &a, B b){if(a < b) a = b;} template vector make_v(size_t a){return vector(a);} template auto make_v(size_t a,Ts... ts){ return vector(ts...))>(a,make_v(ts...)); } template typename enable_if::value!=0>::type fill_v(U &u,const V... v){u=U(v...);} template typename enable_if::value==0>::type fill_v(U &u,const V... v){ for(auto &e:u) fill_v(e,v...); } int64 N, X; vector A; using T = tuple; map mp; int64 dfs(int i, int64 rem) { // cout << "call: " << i << " " << rem << endl; if (i == 0 && (N == 1 || abs(rem) < A[i+1])) { return 1; } if (mp.count({i, rem})) return mp[{i, rem}]; int64 res = 0; if (i == N-1 || rem < A[i+1]) { res += dfs(i - 1, rem % A[i]); if (rem % A[i] != 0 && (i == N-1 || rem + A[i] < A[i+1])) res += dfs(i - 1, A[i] - rem % A[i]); } return mp[{i, rem}] = res; } int main(void){ cin.tie(0); ios::sync_with_stdio(false); int64 N, M; cin >> N >> M; vector B(N+2, 0); REP(i, N) cin >> B[i+1]; vector> L(N+2), R(N+2); vector parity(M); REP(i, M) { int l, r; cin >> l >> r; r++; parity[i] = (r - l) % 2; L[l].push_back(i); R[r].push_back(i); } vector> mat; vector b; vector> piv(M); FOR(i, 1, N+2) { if (L[i].size() == 0 && R[i].size() == 0 && B[i] * -1 != B[i-1]) { cout << i << " " << B[i] << " " << B[i-1] << endl; cout << "NO" << endl; return 0; } if (L[i].size() != 0 || R[i].size() != 0) { map mp; REP(j, L[i].size()) { mp[L[i][j]] = 1; piv[L[i][j]].insert(mat.size()); } REP(j, R[i].size()) { mp[R[i][j]] = parity[R[i][j]] ? 1 : -1; piv[R[i][j]].insert(mat.size()); } mat.push_back(mp); b.push_back(B[i] * -1 - B[i - 1]); } } int rank = 0; auto swap_mat = [&](int r1, int r2) { swap(mat[r1], mat[r2]); swap(b[r1], b[r2]); for (auto &x : mat[r1]) { piv[x.first].erase(r2); piv[x.first].insert(r1); } for (auto &x : mat[r2]) { piv[x.first].erase(r1); piv[x.first].insert(r2); } }; auto add_mat = [&](int r2, int r1, double mul) { // mat[r2] += mat[r1] * mul for (auto &x : mat[r1]) { if (mat[r2][x.first] == 0) { piv[x.first].insert(r2); } mat[r2][x.first] += x.second * mul; if (mat[r2][x.first] == 0) { piv[x.first].erase(r2); mat[r2].erase(x.first); } } b[r2] += b[r1] * mul; }; // REP(i, mat.size()) { // for (auto &x : mat[i]) { // cout << "(" << x.first << " " << x.second << ") "; // } // cout << b[i] << endl; // } // cout << endl; vector ord(mat.size()); iota(all(ord), ord.size()); sort(all(ord), [&](int x, int y) { return mat[x].size() < mat[y].size(); }); for (int i = M-1; i >= 0; i--) { if (piv[i].size() == 0) continue; bool will_do = 0; for (auto &x : piv[i]) { if (x < rank) continue; swap_mat(rank, x); will_do = 1; break; } if (!will_do) continue; // cout << rank << ": "; for (auto &x : piv[i]) { if (x <= rank) continue; // cout << x << " "; double mul = - mat[x][i] / mat[rank][i]; add_mat(x, rank, mul); } // cout << endl; // REP(i, mat.size()) { // for (auto &x : mat[i]) { // cout << "(" << x.first << " " << x.second << ") "; // } // cout << b[i] << endl; // } // cout << endl; rank++; } // REP(i, mat.size()) { // for (auto &x : mat[i]) { // cout << "(" << x.first << " " << x.second << ") "; // } // cout << b[i] << endl; // } REP(i, mat.size()) { bool ok = 1; for (auto &x : mat[i]) { if (abs(x.second) > eps) ok = 0; } if (ok && abs(b[i]) > eps) { cout << "NO" << endl; return 0; } } cout << "YES" << endl; }