結果

問題 No.1290 Addition and Subtraction Operation
ユーザー kyort0nkyort0n
提出日時 2020-11-13 18:14:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 1,850 bytes
コンパイル時間 1,816 ms
コンパイル使用メモリ 174,352 KB
実行使用メモリ 16,628 KB
最終ジャッジ日時 2023-09-30 02:22:00
合計ジャッジ時間 6,395 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,544 KB
testcase_01 AC 4 ms
9,692 KB
testcase_02 AC 4 ms
9,736 KB
testcase_03 AC 4 ms
9,500 KB
testcase_04 AC 4 ms
9,504 KB
testcase_05 AC 4 ms
9,704 KB
testcase_06 AC 4 ms
9,492 KB
testcase_07 AC 4 ms
9,552 KB
testcase_08 AC 4 ms
9,516 KB
testcase_09 AC 4 ms
9,640 KB
testcase_10 AC 4 ms
9,504 KB
testcase_11 AC 4 ms
9,712 KB
testcase_12 AC 4 ms
9,764 KB
testcase_13 AC 3 ms
9,632 KB
testcase_14 AC 4 ms
9,760 KB
testcase_15 AC 4 ms
9,564 KB
testcase_16 AC 4 ms
9,556 KB
testcase_17 AC 4 ms
9,496 KB
testcase_18 AC 4 ms
9,504 KB
testcase_19 AC 4 ms
9,496 KB
testcase_20 AC 4 ms
9,488 KB
testcase_21 AC 4 ms
9,500 KB
testcase_22 AC 4 ms
9,500 KB
testcase_23 AC 4 ms
9,560 KB
testcase_24 AC 4 ms
9,640 KB
testcase_25 AC 4 ms
9,508 KB
testcase_26 AC 4 ms
9,548 KB
testcase_27 AC 4 ms
9,500 KB
testcase_28 AC 4 ms
9,504 KB
testcase_29 AC 4 ms
9,492 KB
testcase_30 AC 4 ms
9,508 KB
testcase_31 AC 4 ms
9,508 KB
testcase_32 AC 4 ms
9,540 KB
testcase_33 AC 5 ms
9,712 KB
testcase_34 AC 4 ms
9,500 KB
testcase_35 AC 4 ms
9,548 KB
testcase_36 AC 4 ms
9,544 KB
testcase_37 AC 4 ms
9,504 KB
testcase_38 AC 4 ms
9,492 KB
testcase_39 AC 5 ms
9,496 KB
testcase_40 AC 4 ms
9,496 KB
testcase_41 AC 4 ms
9,556 KB
testcase_42 AC 35 ms
14,572 KB
testcase_43 AC 36 ms
14,580 KB
testcase_44 AC 35 ms
14,704 KB
testcase_45 AC 36 ms
14,572 KB
testcase_46 AC 37 ms
14,568 KB
testcase_47 AC 36 ms
14,780 KB
testcase_48 AC 36 ms
14,584 KB
testcase_49 AC 36 ms
14,568 KB
testcase_50 AC 36 ms
14,576 KB
testcase_51 AC 36 ms
14,572 KB
testcase_52 AC 36 ms
14,572 KB
testcase_53 AC 36 ms
14,580 KB
testcase_54 AC 35 ms
14,768 KB
testcase_55 AC 35 ms
14,584 KB
testcase_56 AC 36 ms
14,568 KB
testcase_57 AC 24 ms
11,840 KB
testcase_58 AC 31 ms
12,736 KB
testcase_59 AC 23 ms
11,860 KB
testcase_60 AC 73 ms
15,984 KB
testcase_61 AC 53 ms
14,028 KB
testcase_62 AC 53 ms
14,480 KB
testcase_63 AC 31 ms
12,664 KB
testcase_64 AC 15 ms
10,860 KB
testcase_65 AC 18 ms
11,448 KB
testcase_66 AC 36 ms
13,560 KB
testcase_67 AC 75 ms
16,628 KB
testcase_68 AC 49 ms
14,348 KB
testcase_69 AC 28 ms
12,748 KB
testcase_70 AC 27 ms
12,504 KB
testcase_71 AC 33 ms
13,268 KB
testcase_72 AC 19 ms
11,416 KB
testcase_73 AC 41 ms
13,732 KB
testcase_74 AC 14 ms
10,816 KB
testcase_75 AC 16 ms
11,240 KB
testcase_76 AC 29 ms
12,444 KB
testcase_77 AC 58 ms
14,248 KB
testcase_78 AC 49 ms
13,824 KB
testcase_79 AC 30 ms
12,140 KB
testcase_80 AC 77 ms
15,844 KB
testcase_81 AC 72 ms
15,564 KB
testcase_82 AC 40 ms
13,264 KB
testcase_83 AC 72 ms
15,324 KB
testcase_84 AC 66 ms
14,776 KB
testcase_85 AC 24 ms
11,608 KB
testcase_86 AC 18 ms
10,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const long long INF = 1e18;
//const ll mod = 1000000007;
ll N, M;
ll B[100500];
vector<ll> C;
ll L[105000], R[105000];
set<ll> query[105000];
void merge(set<ll> &a, set<ll> &b) {
    if(a.size() < b.size()) swap(a, b);
    for(auto tmp : b) {
        a.insert(tmp);
    }
}

void print(vector<ll> v) {
    cerr << "{";
    for(int i = 0; i < v.size(); i++) {
        if(i != 0) cerr << ", ";
        cerr << v[i];
    }
    cerr << "}" << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M;
    for(int i = 1; i <= N; i++) cin >> B[i];
    C.resize(N + 1);
    for(int i = 0; i <= N; i++) {
        C[i] = B[i] + B[i+1];
    }
    N++;
    for(int i = 0; i < M; i++) {
        cin >> L[i] >> R[i];
        L[i]--;
        query[L[i]].insert(R[i]);
    }
    //print(C);
    for(int i = 0; i < N; i++) {
        //cerr << "---" << i << "---" << endl;
        if(query[i].empty()) continue;
        //print(query[i]);
        ll r = *query[i].begin();
        if((r - i) % 2 == 0) {
            ll delta = C[i];
            C[i] -= delta;
            C[r] += delta;
        } else {
            ll delta = C[i];
            C[i] -= delta;
            C[r] -= delta;
        }
        query[i].erase(query[i].begin());
        merge(query[r], query[i]);
    }
    //print(C);
    string ans = "YES";
    for(int i = 0; i < N; i++) {
        if(C[i] != 0) {
            ans = "NO";
        }
    }
    cout << ans << endl;
    return 0;
}
0