結果

問題 No.1290 Addition and Subtraction Operation
ユーザー やむなくやむなく
提出日時 2020-11-13 23:10:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 118 ms / 2,000 ms
コード長 2,189 bytes
コンパイル時間 1,815 ms
コンパイル使用メモリ 175,744 KB
実行使用メモリ 10,680 KB
最終ジャッジ日時 2023-09-30 04:04:30
合計ジャッジ時間 7,843 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 59 ms
4,780 KB
testcase_43 AC 59 ms
4,720 KB
testcase_44 AC 58 ms
4,920 KB
testcase_45 AC 59 ms
4,916 KB
testcase_46 AC 58 ms
4,788 KB
testcase_47 AC 58 ms
4,836 KB
testcase_48 AC 59 ms
4,720 KB
testcase_49 AC 58 ms
4,852 KB
testcase_50 AC 58 ms
4,832 KB
testcase_51 AC 58 ms
4,844 KB
testcase_52 AC 58 ms
4,820 KB
testcase_53 AC 58 ms
4,716 KB
testcase_54 AC 58 ms
4,764 KB
testcase_55 AC 57 ms
4,772 KB
testcase_56 AC 59 ms
4,784 KB
testcase_57 AC 39 ms
8,648 KB
testcase_58 AC 51 ms
9,044 KB
testcase_59 AC 36 ms
8,580 KB
testcase_60 AC 87 ms
10,128 KB
testcase_61 AC 69 ms
9,580 KB
testcase_62 AC 74 ms
9,964 KB
testcase_63 AC 49 ms
9,048 KB
testcase_64 AC 22 ms
7,792 KB
testcase_65 AC 30 ms
8,200 KB
testcase_66 AC 59 ms
9,552 KB
testcase_67 AC 89 ms
10,320 KB
testcase_68 AC 71 ms
9,888 KB
testcase_69 AC 50 ms
9,036 KB
testcase_70 AC 46 ms
8,732 KB
testcase_71 AC 57 ms
9,328 KB
testcase_72 AC 30 ms
8,252 KB
testcase_73 AC 64 ms
9,644 KB
testcase_74 AC 21 ms
7,788 KB
testcase_75 AC 27 ms
8,008 KB
testcase_76 AC 46 ms
8,856 KB
testcase_77 AC 104 ms
9,968 KB
testcase_78 AC 91 ms
9,568 KB
testcase_79 AC 64 ms
8,912 KB
testcase_80 AC 118 ms
10,680 KB
testcase_81 AC 117 ms
10,388 KB
testcase_82 AC 73 ms
9,340 KB
testcase_83 AC 101 ms
10,100 KB
testcase_84 AC 96 ms
9,964 KB
testcase_85 AC 51 ms
8,204 KB
testcase_86 AC 41 ms
7,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//
// Created by yamunaku on 2020/11/13.
//

#include <bits/stdc++.h>
//#include <atcoder/all>

using namespace std;
//using namespace atcoder;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"YES"<<endl
#define CNO cout<<"NO"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main() {
    //CFS;
    int n, m;
    cin >> n >> m;
    vl b(n);
    rep(i, n) {
        cin >> b[i];
        if (i & 1) b[i] = -b[i];
//        cout << b[i] << " ";
    }
//    cout << endl;
    vector<priority_queue<int, vi, greater<int>>> v(n + 1);
    vi l(m), r(m);
    rep(i, m) {
        cin >> l[i] >> r[i];
        v[l[i] - 1].push(r[i] - 1);
    }
    vl rui(n + 1, 0);
    rep(i, n) {
        if (i > 0) rui[i] += rui[i - 1];
        ll k = b[i] - rui[i];
//        cout << i SP k << endl;
        if (v[i].empty()) {
            if (k == 0) continue;
            CNO;
            return 0;
        }
        int rr = v[i].top() + 1;
//        cout << rr << endl;
        rui[i] += k;
        rui[rr] -= k;
        while (!v[i].empty()) {
            if (v[i].top() == rr - 1) v[i].pop();
            else break;
        }
        if (v[i].size() < v[rr].size()) {
            while (!v[i].empty()) {
                v[rr].push(v[i].top());
                v[i].pop();
            }
        } else {
            while (!v[rr].empty()) {
                v[i].push(v[rr].top());
                v[rr].pop();
            }
            v[rr] = move(v[i]);
        }
    }
    CYES;
    return 0;
}
0