結果
問題 | No.1290 Addition and Subtraction Operation |
ユーザー | outline |
提出日時 | 2021-01-07 15:35:24 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 188 ms / 2,000 ms |
コード長 | 4,966 bytes |
コンパイル時間 | 1,976 ms |
コンパイル使用メモリ | 156,140 KB |
実行使用メモリ | 19,772 KB |
最終ジャッジ日時 | 2024-11-08 16:37:50 |
合計ジャッジ時間 | 9,004 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 1 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 1 ms
5,248 KB |
testcase_07 | AC | 2 ms
5,248 KB |
testcase_08 | AC | 2 ms
5,248 KB |
testcase_09 | AC | 1 ms
5,248 KB |
testcase_10 | AC | 2 ms
5,248 KB |
testcase_11 | AC | 2 ms
5,248 KB |
testcase_12 | AC | 1 ms
5,248 KB |
testcase_13 | AC | 2 ms
5,248 KB |
testcase_14 | AC | 2 ms
5,248 KB |
testcase_15 | AC | 2 ms
5,248 KB |
testcase_16 | AC | 2 ms
5,248 KB |
testcase_17 | AC | 1 ms
5,248 KB |
testcase_18 | AC | 2 ms
5,248 KB |
testcase_19 | AC | 2 ms
5,248 KB |
testcase_20 | AC | 2 ms
5,248 KB |
testcase_21 | AC | 2 ms
5,248 KB |
testcase_22 | AC | 2 ms
5,248 KB |
testcase_23 | AC | 2 ms
5,248 KB |
testcase_24 | AC | 2 ms
5,248 KB |
testcase_25 | AC | 2 ms
5,248 KB |
testcase_26 | AC | 2 ms
5,248 KB |
testcase_27 | AC | 2 ms
5,248 KB |
testcase_28 | AC | 2 ms
5,248 KB |
testcase_29 | AC | 2 ms
5,248 KB |
testcase_30 | AC | 2 ms
5,248 KB |
testcase_31 | AC | 2 ms
5,248 KB |
testcase_32 | AC | 2 ms
5,248 KB |
testcase_33 | AC | 2 ms
5,248 KB |
testcase_34 | AC | 2 ms
5,248 KB |
testcase_35 | AC | 2 ms
5,248 KB |
testcase_36 | AC | 2 ms
5,248 KB |
testcase_37 | AC | 1 ms
5,248 KB |
testcase_38 | AC | 2 ms
5,248 KB |
testcase_39 | AC | 2 ms
5,248 KB |
testcase_40 | AC | 2 ms
5,248 KB |
testcase_41 | AC | 2 ms
5,248 KB |
testcase_42 | AC | 38 ms
7,936 KB |
testcase_43 | AC | 37 ms
7,936 KB |
testcase_44 | AC | 37 ms
7,936 KB |
testcase_45 | AC | 36 ms
7,936 KB |
testcase_46 | AC | 36 ms
7,936 KB |
testcase_47 | AC | 36 ms
7,936 KB |
testcase_48 | AC | 37 ms
7,936 KB |
testcase_49 | AC | 36 ms
7,808 KB |
testcase_50 | AC | 36 ms
7,936 KB |
testcase_51 | AC | 37 ms
7,936 KB |
testcase_52 | AC | 36 ms
7,936 KB |
testcase_53 | AC | 36 ms
7,808 KB |
testcase_54 | AC | 37 ms
7,936 KB |
testcase_55 | AC | 36 ms
7,936 KB |
testcase_56 | AC | 36 ms
7,936 KB |
testcase_57 | AC | 60 ms
16,280 KB |
testcase_58 | AC | 88 ms
17,152 KB |
testcase_59 | AC | 55 ms
16,256 KB |
testcase_60 | AC | 163 ms
19,584 KB |
testcase_61 | AC | 138 ms
18,304 KB |
testcase_62 | AC | 145 ms
18,816 KB |
testcase_63 | AC | 87 ms
17,280 KB |
testcase_64 | AC | 18 ms
15,360 KB |
testcase_65 | AC | 38 ms
15,712 KB |
testcase_66 | AC | 110 ms
17,748 KB |
testcase_67 | AC | 168 ms
19,772 KB |
testcase_68 | AC | 139 ms
18,468 KB |
testcase_69 | AC | 90 ms
17,152 KB |
testcase_70 | AC | 78 ms
16,912 KB |
testcase_71 | AC | 109 ms
17,524 KB |
testcase_72 | AC | 41 ms
15,744 KB |
testcase_73 | AC | 119 ms
18,048 KB |
testcase_74 | AC | 15 ms
15,232 KB |
testcase_75 | AC | 30 ms
15,616 KB |
testcase_76 | AC | 80 ms
17,024 KB |
testcase_77 | AC | 165 ms
18,684 KB |
testcase_78 | AC | 154 ms
18,048 KB |
testcase_79 | AC | 100 ms
16,700 KB |
testcase_80 | AC | 188 ms
19,448 KB |
testcase_81 | AC | 186 ms
19,456 KB |
testcase_82 | AC | 109 ms
17,664 KB |
testcase_83 | AC | 172 ms
19,328 KB |
testcase_84 | AC | 157 ms
18,944 KB |
testcase_85 | AC | 52 ms
16,040 KB |
testcase_86 | AC | 24 ms
15,360 KB |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <queue> #include <string> #include <map> #include <set> #include <stack> #include <tuple> #include <deque> #include <array> #include <numeric> #include <bitset> #include <iomanip> #include <cassert> #include <chrono> #include <random> #include <limits> #include <iterator> #include <functional> #include <sstream> #include <fstream> #include <complex> #include <cstring> #include <unordered_map> #include <unordered_set> using namespace std; using ll = long long; using P = pair<int, int>; constexpr int INF = 1001001001; constexpr int mod = 1000000007; // constexpr int mod = 998244353; template<class T> inline bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } template<class T> inline bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } template<typename Monoid, typename OperatorMonoid = Monoid> struct LazySegmentTree{ using F = function<Monoid(Monoid, Monoid)>; using G = function<Monoid(Monoid, OperatorMonoid)>; using H = function<OperatorMonoid(OperatorMonoid, OperatorMonoid)>; int sz; vector<Monoid> data; vector<OperatorMonoid> 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<ll> B(N); for(int i = 0; i < N; ++i) cin >> B[i]; vector<set<int>> sections(N + 1); for(int i = 0; i < M; ++i){ int L, R; cin >> L >> R; sections[L - 1].emplace(R); } vector<int> 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<Node, ll> 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; }