結果

問題 No.1290 Addition and Subtraction Operation
ユーザー 👑 NachiaNachia
提出日時 2020-11-13 22:35:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 108 ms / 2,000 ms
コード長 1,061 bytes
コンパイル時間 1,744 ms
コンパイル使用メモリ 175,976 KB
実行使用メモリ 10,100 KB
最終ジャッジ日時 2023-09-30 03:35:20
合計ジャッジ時間 7,871 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 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,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 38 ms
4,380 KB
testcase_43 AC 39 ms
4,376 KB
testcase_44 AC 38 ms
4,380 KB
testcase_45 AC 37 ms
4,376 KB
testcase_46 AC 36 ms
4,428 KB
testcase_47 AC 39 ms
4,596 KB
testcase_48 AC 36 ms
4,376 KB
testcase_49 AC 35 ms
4,380 KB
testcase_50 AC 36 ms
4,624 KB
testcase_51 AC 36 ms
4,376 KB
testcase_52 AC 36 ms
4,380 KB
testcase_53 AC 38 ms
4,432 KB
testcase_54 AC 38 ms
4,376 KB
testcase_55 AC 40 ms
4,460 KB
testcase_56 AC 38 ms
4,384 KB
testcase_57 AC 37 ms
8,372 KB
testcase_58 AC 48 ms
9,248 KB
testcase_59 AC 34 ms
8,312 KB
testcase_60 AC 79 ms
10,020 KB
testcase_61 AC 67 ms
9,984 KB
testcase_62 AC 73 ms
9,896 KB
testcase_63 AC 47 ms
9,260 KB
testcase_64 AC 22 ms
7,460 KB
testcase_65 AC 30 ms
8,304 KB
testcase_66 AC 55 ms
9,620 KB
testcase_67 AC 88 ms
9,944 KB
testcase_68 AC 75 ms
9,680 KB
testcase_69 AC 47 ms
8,896 KB
testcase_70 AC 48 ms
8,912 KB
testcase_71 AC 56 ms
9,296 KB
testcase_72 AC 30 ms
8,240 KB
testcase_73 AC 65 ms
9,572 KB
testcase_74 AC 18 ms
7,468 KB
testcase_75 AC 25 ms
7,928 KB
testcase_76 AC 46 ms
9,096 KB
testcase_77 AC 87 ms
9,900 KB
testcase_78 AC 78 ms
9,512 KB
testcase_79 AC 59 ms
8,684 KB
testcase_80 AC 103 ms
10,084 KB
testcase_81 AC 108 ms
10,100 KB
testcase_82 AC 75 ms
9,176 KB
testcase_83 AC 99 ms
9,880 KB
testcase_84 AC 94 ms
9,700 KB
testcase_85 AC 50 ms
8,584 KB
testcase_86 AC 40 ms
7,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

struct dsu {
	vector<int> V;
	dsu(int n) { V.resize(n); rep(i, n) V[i] = i; }
	int root(int a) { if (V[a] == a) return a; return V[a] = root(V[a]); }
	void merge(int r, int s) { V[root(s)] = root(r); }
};

struct RangeProc {
	vector<vector<int>> G;
	vector<int> X;

	void proc() {
		int N = G.size();
		dsu Q(N * 2);
		rep(u, N) for (int v : G[u]) {
			Q.merge(u, v);
		}
		X.resize(N);
		rep(i, N) X[i] = Q.root(i);
	}
};

int main() {
	int N, Q; cin >> N >> Q;
	vector<LL> A(N); rep(i, N) cin >> A[i];
	rep(i, N) if (i % 2 == 1) A[i] = -A[i];
	A.push_back(0);
	for (int i = N - 1; i >= 0; i--) A[i + 1] -= A[i];

	RangeProc G; G.G.resize(N + 1);
	rep(i, Q) {
		int l, r; cin >> l >> r; l--;
		G.G[l].push_back(r);
		G.G[r].push_back(l);
	}
	G.proc();

	vector<LL> S(N + 1);
	rep(i, N + 1) S[G.X[i]] += A[i];
	bool ok = true;
	rep(i, N) if (S[i] != 0) ok = false;
	cout << (ok ? "YES" : "NO") << endl;

	return 0;
}

0