結果

問題 No.1290 Addition and Subtraction Operation
ユーザー outlineoutline
提出日時 2021-01-07 15:19:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,269 bytes
コンパイル時間 1,494 ms
コンパイル使用メモリ 143,348 KB
実行使用メモリ 13,780 KB
最終ジャッジ日時 2024-04-26 02:19:56
合計ジャッジ時間 6,798 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 1 ms
6,944 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 2 ms
6,948 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 WA -
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 1 ms
6,944 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 2 ms
6,944 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 2 ms
6,940 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 2 ms
6,940 KB
testcase_33 AC 2 ms
6,944 KB
testcase_34 AC 1 ms
6,944 KB
testcase_35 AC 2 ms
6,940 KB
testcase_36 AC 2 ms
6,940 KB
testcase_37 AC 1 ms
6,940 KB
testcase_38 AC 2 ms
6,940 KB
testcase_39 AC 2 ms
6,940 KB
testcase_40 WA -
testcase_41 AC 2 ms
6,940 KB
testcase_42 AC 37 ms
8,064 KB
testcase_43 AC 37 ms
8,064 KB
testcase_44 AC 37 ms
8,064 KB
testcase_45 AC 38 ms
8,064 KB
testcase_46 AC 38 ms
7,936 KB
testcase_47 AC 37 ms
7,936 KB
testcase_48 AC 37 ms
7,936 KB
testcase_49 AC 37 ms
8,064 KB
testcase_50 AC 36 ms
8,064 KB
testcase_51 AC 37 ms
8,064 KB
testcase_52 AC 37 ms
8,064 KB
testcase_53 AC 35 ms
7,936 KB
testcase_54 AC 36 ms
8,064 KB
testcase_55 AC 37 ms
7,936 KB
testcase_56 AC 37 ms
7,936 KB
testcase_57 AC 22 ms
11,056 KB
testcase_58 AC 29 ms
11,764 KB
testcase_59 AC 22 ms
10,956 KB
testcase_60 AC 66 ms
13,516 KB
testcase_61 AC 46 ms
12,432 KB
testcase_62 AC 52 ms
12,708 KB
testcase_63 AC 29 ms
11,648 KB
testcase_64 AC 13 ms
10,068 KB
testcase_65 AC 17 ms
10,480 KB
testcase_66 AC 36 ms
11,592 KB
testcase_67 AC 72 ms
13,780 KB
testcase_68 AC 47 ms
12,344 KB
testcase_69 AC 28 ms
11,780 KB
testcase_70 AC 27 ms
11,616 KB
testcase_71 AC 33 ms
12,284 KB
testcase_72 AC 17 ms
10,508 KB
testcase_73 AC 42 ms
12,672 KB
testcase_74 AC 13 ms
9,848 KB
testcase_75 AC 17 ms
10,448 KB
testcase_76 AC 26 ms
10,820 KB
testcase_77 WA -
testcase_78 WA -
testcase_79 WA -
testcase_80 WA -
testcase_81 WA -
testcase_82 AC 35 ms
12,344 KB
testcase_83 AC 66 ms
13,340 KB
testcase_84 AC 58 ms
12,972 KB
testcase_85 AC 24 ms
10,872 KB
testcase_86 AC 18 ms
10,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}

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 + 1].size()){
            swap(sections[l], sections[r + 1]);
        }
        for(auto it = sections[l].begin(); it != sections[l].end(); ){
            sections[r + 1].emplace(*it);
            it = sections[l].erase(it);
        }
    }

    vector<ll> finish(N + 1);
    ll sum = 0;
    for(int l = 0; l < N; ++l){
        sum -= finish[l];
        B[l] -= sum;
        if(rights[l] != -1){
            sum += B[l];
            if((rights[l] - l) % 2 == 0)    finish[rights[l]] += B[l];
            else    finish[rights[l]] -= B[l];
            B[l] = 0;
        }
        sum *= -1;
    }

    for(int i = 0; i < N; ++i){
        if(B[i] != 0){
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";

    return 0;
}
0