#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using P = pair; constexpr int INF = 1001001001; constexpr int mod = 1000000007; // constexpr int mod = 998244353; template inline bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } template inline bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } template struct LazySegmentTree{ using F = function; using G = function; using H = function; int sz; vector data; vector lazy; const F f; const G g; const H h; const Monoid M1; // モノイドの単位元 const OperatorMonoid OM0; // 作用素モノイドの単位元 LazySegmentTree(int n, const F f, const G g, const H h, const Monoid &M1, const OperatorMonoid OM0) : f(f), g(g), h(h), M1(M1), OM0(OM0) { sz = 1; while(sz < n) sz <<= 1; data.assign(sz << 1, M1); lazy.assign(sz << 1, OM0); } void set(int k, const Monoid &x){ data[k + sz] = x; } void build(){ for(int k = sz - 1; k > 0; --k){ data[k] = f(data[k << 1], data[k << 1 | 1]); } } void propagate(int k){ if(lazy[k] != OM0){ if(k < sz){ lazy[k << 1] = h(lazy[k << 1], lazy[k]); lazy[k << 1 | 1] = h(lazy[k << 1 | 1], lazy[k]); } data[k] = g(data[k], lazy[k]); lazy[k] = OM0; } } Monoid update(int a, int b, const OperatorMonoid &x, int k = 1, int l = 0, int r = -1){ if(r == -1) r = sz; propagate(k); if(r <= a || b <= l) return data[k]; else if(a <= l && r <= b){ lazy[k] = h(lazy[k], x); propagate(k); return data[k]; } else{ return data[k] = f(update(a, b, x, k << 1, l, (l + r) >> 1), update(a, b, x, k << 1 | 1, (l + r) >> 1, r)); } } Monoid query(int a, int b, int k = 1, int l = 0, int r = -1){ if(r == -1) r = sz; propagate(k); if(r <= a || b <= l) return M1; else if(a <= l && r <= b) return data[k]; else{ return f(query(a, b, k << 1, l, (l + r) >> 1), query(a, b, k << 1 | 1, (l + r) >> 1, r)); } } Monoid operator[](const int &k){ return query(k, k + 1); } }; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N, M; cin >> N >> M; vector B(N); for(int i = 0; i < N; ++i) cin >> B[i]; vector> sections(N + 1); for(int i = 0; i < M; ++i){ int L, R; cin >> L >> R; sections[L - 1].emplace(R); } vector rights(N, -1); for(int l = 0; l < N; ++l){ if(sections[l].size() == 0) continue; int r = *sections[l].begin(); rights[l] = r; sections[l].erase(sections[l].begin()); if(sections[l].size() > sections[r].size()){ swap(sections[l], sections[r]); } for(auto it = sections[l].begin(); it != sections[l].end(); ){ sections[r].emplace(*it); it = sections[l].erase(it); } } struct Node { ll sum; int weight; Node(ll s = 0, int w = 0) : sum(s), weight(w) {} }; auto op = [](Node a, Node b) { return Node(a.sum + b.sum, a.weight + b.weight); }; auto mapping = [](Node a, ll x) { return Node(a.sum + x * a.weight, a.weight); }; auto composition = [](ll a, ll b) { return a + b; }; LazySegmentTree seg(N, op, mapping, composition, Node(), 0); for(int i = 0; i < N; ++i){ seg.set(i, Node(B[i], (i % 2 ? -1 : 1))); } seg.build(); for(int l = 0; l < N; ++l){ if(rights[l] == -1) continue; if(l % 2 == 0){ seg.update(l, rights[l], -seg[l].sum); } else{ seg.update(l, rights[l], seg[l].sum); } } for(int i = 0; i < N; ++i){ if(seg[i].sum != 0){ cout << "NO\n"; return 0; } } cout << "YES\n"; return 0; }