結果

問題 No.1290 Addition and Subtraction Operation
ユーザー CinnamorollCinnamoroll
提出日時 2020-11-11 20:38:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 7,806 bytes
コンパイル時間 1,594 ms
コンパイル使用メモリ 178,024 KB
実行使用メモリ 16,220 KB
最終ジャッジ日時 2023-09-30 02:20:08
合計ジャッジ時間 6,250 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,700 KB
testcase_01 AC 4 ms
5,708 KB
testcase_02 WA -
testcase_03 AC 4 ms
5,732 KB
testcase_04 AC 3 ms
5,740 KB
testcase_05 AC 4 ms
5,724 KB
testcase_06 AC 4 ms
5,736 KB
testcase_07 AC 4 ms
5,672 KB
testcase_08 WA -
testcase_09 AC 4 ms
5,808 KB
testcase_10 AC 3 ms
5,668 KB
testcase_11 AC 3 ms
5,700 KB
testcase_12 AC 3 ms
5,688 KB
testcase_13 AC 3 ms
5,700 KB
testcase_14 AC 3 ms
5,736 KB
testcase_15 AC 3 ms
5,724 KB
testcase_16 AC 4 ms
5,696 KB
testcase_17 WA -
testcase_18 AC 4 ms
5,724 KB
testcase_19 AC 4 ms
5,648 KB
testcase_20 AC 3 ms
5,688 KB
testcase_21 AC 3 ms
5,704 KB
testcase_22 WA -
testcase_23 AC 4 ms
5,716 KB
testcase_24 AC 4 ms
5,924 KB
testcase_25 AC 3 ms
5,684 KB
testcase_26 AC 3 ms
5,708 KB
testcase_27 WA -
testcase_28 AC 4 ms
5,928 KB
testcase_29 AC 3 ms
5,660 KB
testcase_30 AC 4 ms
5,948 KB
testcase_31 AC 3 ms
5,732 KB
testcase_32 AC 3 ms
5,728 KB
testcase_33 AC 3 ms
5,736 KB
testcase_34 AC 3 ms
5,712 KB
testcase_35 WA -
testcase_36 AC 4 ms
5,688 KB
testcase_37 WA -
testcase_38 AC 3 ms
5,648 KB
testcase_39 AC 4 ms
5,708 KB
testcase_40 WA -
testcase_41 AC 4 ms
5,696 KB
testcase_42 AC 35 ms
10,620 KB
testcase_43 AC 34 ms
10,372 KB
testcase_44 AC 34 ms
10,392 KB
testcase_45 AC 34 ms
10,388 KB
testcase_46 AC 34 ms
10,432 KB
testcase_47 AC 34 ms
10,376 KB
testcase_48 AC 36 ms
10,504 KB
testcase_49 AC 34 ms
10,500 KB
testcase_50 AC 34 ms
10,388 KB
testcase_51 AC 34 ms
10,432 KB
testcase_52 AC 35 ms
10,548 KB
testcase_53 AC 34 ms
10,500 KB
testcase_54 AC 35 ms
10,560 KB
testcase_55 AC 34 ms
10,516 KB
testcase_56 AC 34 ms
10,412 KB
testcase_57 AC 22 ms
13,056 KB
testcase_58 AC 31 ms
13,544 KB
testcase_59 AC 22 ms
12,708 KB
testcase_60 AC 56 ms
16,052 KB
testcase_61 AC 46 ms
14,796 KB
testcase_62 AC 51 ms
15,268 KB
testcase_63 AC 31 ms
13,460 KB
testcase_64 AC 15 ms
11,700 KB
testcase_65 AC 18 ms
12,148 KB
testcase_66 AC 38 ms
14,432 KB
testcase_67 AC 65 ms
16,220 KB
testcase_68 AC 47 ms
14,896 KB
testcase_69 AC 31 ms
13,492 KB
testcase_70 AC 27 ms
13,436 KB
testcase_71 AC 36 ms
14,060 KB
testcase_72 AC 19 ms
12,216 KB
testcase_73 AC 44 ms
14,580 KB
testcase_74 AC 14 ms
11,644 KB
testcase_75 AC 16 ms
12,024 KB
testcase_76 AC 30 ms
13,280 KB
testcase_77 WA -
testcase_78 WA -
testcase_79 WA -
testcase_80 WA -
testcase_81 WA -
testcase_82 AC 38 ms
13,952 KB
testcase_83 AC 65 ms
15,840 KB
testcase_84 AC 57 ms
15,320 KB
testcase_85 AC 24 ms
12,456 KB
testcase_86 AC 19 ms
11,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// warm heart, wagging tail,and a smile just for you!
//                                                                     ███████████
//                                                                   ███╬╬╬╬╬╬╬╬╬╬███
//                                                                ███╬╬╬╬╬████╬╬╬╬╬╬███
//                                            ███████████       ██╬╬╬╬╬████╬╬████╬╬╬╬╬██
//                                      █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██
//                               ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██
//                             ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██
//                           ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████
//                         ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██
//                       ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███
//                     ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██
//                 ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████
//     █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████
//   ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████
//   ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
//       ██████████████  ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████
//                         ███████                           █████  ███████████████████  
//
#include "bits/stdc++.h"
using namespace std;
#define INF (1<<30)
#define LINF (1LL<<60)
#define fs first
#define sc second
// #define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl
#define SP << " " << 
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#define MSB(x) (63-__builtin_clzll(x))
#define pcnt(x) (__builtin_popcountll(x))
#define parity(i,j) (i&(1LL<<j))
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

struct UnionFind {
  private:
  vector<int> child,tree;
  vector<vector<int>> list;

public:
  UnionFind(int v) {
    tree.resize(v);
    list.resize(v);
    REP(i,v) tree[i] = i, list[i].push_back(i);
  }

  int root(int i){
    if(i == tree[i]){
      REP(j,child.size()) tree[child[j]] = i;
      child.clear(); 
      return i;
    }
    else{
      child.push_back(i);
      return i = root(tree[i]);
    }
  }

  int size(int i){
    return list[root(i)].size();
  }

  vector<int> nodes(int no){
    return list[root(no)];
  }

  bool unit(int x, int y){
    x = root(x);
    y = root(y);
    if(x==y) return false;
    if(list[x].size() < list[y].size()) swap(x,y);
    for(int no:list[y]) list[x].emplace_back(no);
    tree[y] = x;
    return true;
  }

  bool isUnit(int x, int y){
    return root(x) == root(y);
  }
};

void ng(){
  cout << "NO";
  exit(0);
}

const int N = 1e5+10;
vector<int> edge[N],color(N,0);

bool isBip(int no){
  if(!color[no]) color[no] = 1;
  bool flag = true;
  for(auto to:edge[no]){
    if(color[no]==color[to]) flag = false;
    else if(!color[to]){
      color[to] = -color[no];
      if(!isBip(to)) flag = false;
    }
  }
  return flag;
}

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n,m;
  cin >> n >> m;
  
  vector<int> b(n+2);
  REP(i,n) cin >> b[i+1];

  vector<int> d(n+1);
  REP(i,n+1) d[i] = b[i]+b[i+1];

  set<int> op[n+2];
  REP(i,m){
    int x,y;
    cin >> x >> y;
    op[x-1].insert(y);
  }

  vec p(n+2); REP(i,n+2) p[i] = i;
  REP(x,n+1){
    int i = p[x];
    if(!op[i].size()) continue;
    int now = -d[x], r = *op[i].begin();
    op[i].erase(r);
    d[x] += now;
    if((r-x)%2) d[r] += now;
    else d[r] -= now;

    r = p[r];
    if(op[i].size() < op[r].size()){
      ITR(itr,op[i]) op[r].insert(*itr);
      op[i].clear();
    }
    else{
      ITR(itr,op[r]) op[i].insert(*itr);
      op[r].clear();  p[r] = i;
    }
    // REP(i,n+1) cout << d[i] << " ";
    // cout << endl;
  }

  REP(i,n+1) if(d[i]) ng();
 
  cout << "YES";

  return 0;
}
0