結果

問題 No.1290 Addition and Subtraction Operation
ユーザー kyort0nkyort0n
提出日時 2020-11-13 18:12:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,039 bytes
コンパイル時間 1,864 ms
コンパイル使用メモリ 174,400 KB
実行使用メモリ 15,744 KB
最終ジャッジ日時 2023-09-30 02:22:16
合計ジャッジ時間 7,685 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
12,132 KB
testcase_01 AC 4 ms
7,448 KB
testcase_02 AC 4 ms
7,448 KB
testcase_03 AC 3 ms
7,648 KB
testcase_04 AC 4 ms
7,644 KB
testcase_05 AC 3 ms
7,448 KB
testcase_06 AC 3 ms
7,484 KB
testcase_07 AC 3 ms
7,484 KB
testcase_08 AC 4 ms
7,444 KB
testcase_09 AC 4 ms
7,504 KB
testcase_10 AC 4 ms
7,524 KB
testcase_11 AC 4 ms
7,452 KB
testcase_12 AC 4 ms
7,508 KB
testcase_13 AC 3 ms
7,516 KB
testcase_14 AC 4 ms
7,444 KB
testcase_15 AC 4 ms
7,544 KB
testcase_16 AC 4 ms
7,476 KB
testcase_17 AC 3 ms
7,472 KB
testcase_18 AC 4 ms
7,636 KB
testcase_19 AC 4 ms
7,720 KB
testcase_20 AC 3 ms
7,600 KB
testcase_21 AC 4 ms
7,592 KB
testcase_22 AC 4 ms
7,448 KB
testcase_23 AC 3 ms
7,452 KB
testcase_24 AC 3 ms
7,612 KB
testcase_25 AC 3 ms
7,532 KB
testcase_26 AC 3 ms
7,476 KB
testcase_27 AC 4 ms
7,528 KB
testcase_28 AC 4 ms
7,504 KB
testcase_29 AC 3 ms
7,564 KB
testcase_30 AC 4 ms
7,460 KB
testcase_31 AC 4 ms
7,436 KB
testcase_32 AC 4 ms
7,448 KB
testcase_33 AC 3 ms
7,472 KB
testcase_34 AC 4 ms
7,448 KB
testcase_35 AC 4 ms
7,536 KB
testcase_36 AC 4 ms
7,432 KB
testcase_37 AC 4 ms
7,548 KB
testcase_38 AC 4 ms
7,712 KB
testcase_39 AC 3 ms
7,440 KB
testcase_40 AC 3 ms
7,464 KB
testcase_41 AC 4 ms
7,512 KB
testcase_42 AC 25 ms
9,664 KB
testcase_43 AC 25 ms
9,672 KB
testcase_44 AC 25 ms
9,816 KB
testcase_45 AC 25 ms
9,724 KB
testcase_46 AC 24 ms
9,728 KB
testcase_47 AC 25 ms
9,748 KB
testcase_48 AC 25 ms
9,804 KB
testcase_49 AC 25 ms
9,660 KB
testcase_50 AC 25 ms
9,756 KB
testcase_51 AC 25 ms
9,664 KB
testcase_52 AC 25 ms
9,960 KB
testcase_53 AC 25 ms
9,940 KB
testcase_54 AC 25 ms
9,672 KB
testcase_55 AC 25 ms
9,740 KB
testcase_56 AC 25 ms
9,704 KB
testcase_57 AC 23 ms
9,400 KB
testcase_58 AC 30 ms
9,860 KB
testcase_59 AC 23 ms
9,400 KB
testcase_60 TLE -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
testcase_67 -- -
testcase_68 -- -
testcase_69 -- -
testcase_70 -- -
testcase_71 -- -
testcase_72 -- -
testcase_73 -- -
testcase_74 -- -
testcase_75 -- -
testcase_76 -- -
testcase_77 -- -
testcase_78 -- -
testcase_79 -- -
testcase_80 -- -
testcase_81 -- -
testcase_82 -- -
testcase_83 -- -
testcase_84 -- -
testcase_85 -- -
testcase_86 -- -
権限があれば一括ダウンロードができます

ソースコード

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];
vector<ll> query[105000];
void merge(vector<ll> &a, vector<ll> &b) {
    if(a.size() < b.size()) swap(a, b);
    for(auto tmp : b) {
        a.push_back(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]].push_back(R[i]);
    }
    //print(C);
    for(int i = 0; i < N; i++) {
        //cerr << "---" << i << "---" << endl;
        if(query[i].empty()) continue;
        sort(query[i].begin(), query[i].end());
        query[i].erase(unique(query[i].begin(), query[i].end()), query[i].end());
        //print(query[i]);
        ll r = query[i][0];
        if(r == i) {
            C[i] = 0;
        } else 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