#include #include #include #include #include #include #include #include #define rep(i, a, b) for (int i = int(a); i < int(b); i++) using namespace std; using ll = long long int; // NOLINT using P = pair; // clang-format off #ifdef _DEBUG_ #define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; debug_print(__VA_ARGS__); } while(false) template void debug_print(const T &t, const Ts &...ts) { cerr << t; ((cerr << ", " << ts), ...); cerr << endl; } #else #define dump(...) do{ } while(false) #endif template vector make_v(size_t a, T b) { return vector(a, b); } template auto make_v(size_t a, Ts... ts) { return vector(a, make_v(ts...)); } template bool chmin(T &a, const T& b) { if (a > b) {a = b; return true; } return false; } template bool chmax(T &a, const T& b) { if (a < b) {a = b; return true; } return false; } template void print(const T& t, const Ts&... ts) { cout << t; ((cout << ' ' << ts), ...); cout << '\n'; } template void input(Ts&... ts) { (cin >> ... >> ts); } template istream &operator,(istream &in, T &t) { return in >> t; } struct Inf { template constexpr operator T() { return numeric_limits::max() / 2; } }; // clang-format on #include template class DualSegmentTree { using Func = function; public: vector data; int n; T init; Func update_func; DualSegmentTree(int _n, T _init, Func up) { init = _init; update_func = up; for (n = 1; n < _n; n *= 2) ; data.resize(2 * n - 1, init); } void update(int l, int r, T val) { for (l += n - 1, r += n - 1; l < r; l = l / 2, r = (r - 1) / 2) { if (!(l & 1)) { data[l] = update_func(data[l], val); } if (!(r & 1)) { data[r - 1] = update_func(data[r - 1], val); } } } T query(int pos) { pos += n - 1; T res = data[pos]; while (pos > 0) { pos = (pos - 1) / 2; res = update_func(res, data[pos]); } return res; } }; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, m; cin, n, m; vector b(n); rep(i, 0, n) { cin, b[i]; } if (n == 1) { if (b.front() == 0 || m) { print("YES"); } else { print("NO"); } return 0; } vector> query(n); rep(i, 0, m) { int l, r; cin, l, r; query[l - 1].emplace_back(r - 1); } auto ADD = [](ll a, ll b) { return a + b; }; DualSegmentTree odd((n + 1) / 2, 0, ADD), even(n / 2, 0, ADD); rep(i, 0, n) { auto &v = query[i]; sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); rep(j, 1, v.size()) { query[v[j - 1] + 1].emplace_back(v[j]); } if (v.size()) { auto &seg = (i % 2 ? even : odd); ll val = seg.query(i / 2); ll d = b[i] - val; int r = v.front(); if (!(i % 2) && !(r % 2)) { odd.update(i / 2, (r + 2) / 2, d); even.update((i + 1) / 2, (r + 1) / 2, -d); } else if (!(i % 2) && (r % 2)) { odd.update(i / 2, (r + 1) / 2, d); even.update((i + 1) / 2, (r + 1) / 2, -d); } else if ((i % 2) && !(r % 2)) { even.update(i / 2, (r + 1) / 2, d); odd.update((i + 1) / 2, (r + 2) / 2, -d); } else { even.update(i / 2, (r + 1) / 2, d); odd.update((i + 1) / 2, (r + 1) / 2, -d); } dump(i, d); } } rep(i, 0, n) { auto &seg = (i % 2 ? even : odd); dump(seg.query(i / 2), b[i]); if (seg.query(i / 2) != b[i]) { print("NO"); return 0; } } print("YES"); return 0; }