結果

問題 No.1290 Addition and Subtraction Operation
ユーザー leaf_1415leaf_1415
提出日時 2020-11-13 22:31:53
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 1,653 bytes
コンパイル時間 2,471 ms
コンパイル使用メモリ 84,568 KB
実行使用メモリ 11,224 KB
最終ジャッジ日時 2023-09-30 03:31:30
合計ジャッジ時間 5,869 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 3 ms
4,380 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,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 3 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 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,376 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 18 ms
5,232 KB
testcase_43 AC 17 ms
5,280 KB
testcase_44 AC 17 ms
4,900 KB
testcase_45 AC 17 ms
4,904 KB
testcase_46 AC 17 ms
4,900 KB
testcase_47 AC 17 ms
5,000 KB
testcase_48 AC 17 ms
4,956 KB
testcase_49 AC 17 ms
5,168 KB
testcase_50 AC 17 ms
5,324 KB
testcase_51 AC 17 ms
4,916 KB
testcase_52 AC 17 ms
5,000 KB
testcase_53 AC 17 ms
5,004 KB
testcase_54 AC 18 ms
4,904 KB
testcase_55 AC 17 ms
5,316 KB
testcase_56 AC 17 ms
5,180 KB
testcase_57 AC 40 ms
10,072 KB
testcase_58 AC 42 ms
9,364 KB
testcase_59 AC 39 ms
10,228 KB
testcase_60 AC 38 ms
7,604 KB
testcase_61 AC 39 ms
8,348 KB
testcase_62 AC 38 ms
7,992 KB
testcase_63 AC 42 ms
9,276 KB
testcase_64 AC 32 ms
11,152 KB
testcase_65 AC 38 ms
10,688 KB
testcase_66 AC 42 ms
8,784 KB
testcase_67 AC 39 ms
7,504 KB
testcase_68 AC 38 ms
8,220 KB
testcase_69 AC 42 ms
9,280 KB
testcase_70 AC 41 ms
9,668 KB
testcase_71 AC 43 ms
9,060 KB
testcase_72 AC 38 ms
10,704 KB
testcase_73 AC 40 ms
8,352 KB
testcase_74 AC 30 ms
11,140 KB
testcase_75 AC 36 ms
11,088 KB
testcase_76 AC 42 ms
9,536 KB
testcase_77 AC 43 ms
8,144 KB
testcase_78 AC 44 ms
8,336 KB
testcase_79 AC 45 ms
9,640 KB
testcase_80 AC 43 ms
7,704 KB
testcase_81 AC 42 ms
7,784 KB
testcase_82 AC 47 ms
8,900 KB
testcase_83 AC 42 ms
7,820 KB
testcase_84 AC 42 ms
7,792 KB
testcase_85 AC 43 ms
10,332 KB
testcase_86 AC 37 ms
11,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(),(x).end()
#define inf 1e18

using namespace std;

typedef long long llint;
typedef pair<llint, llint> P;

struct UnionFind{
	int size;
	vector<int> parent;
	
	UnionFind(){}
	UnionFind(int size){
		this->size = size;
		parent.resize(size+1);
		init();
	}
	void init(){
		for(int i = 0; i <= size; i++) parent[i] = i;
	}
	int root(int i){
		if(parent[i] == i) return i;
		return parent[i] = root(parent[i]);
	}
	bool same(int i, int j){
		return root(i) == root(j);
	}
	void unite(int i, int j){
		int root_i = root(i), root_j = root(j);
		if(root_i == root_j) return;
		parent[root_i] = root_j;
	}
};

llint n, m;
llint b[100005], d[100005];
llint l[100005], r[100005];
UnionFind uf(100005);
map<llint, llint> mp;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m;
	rep(i, 1, n) cin >> b[i];
	rep(i, 1, m) cin >> l[i] >> r[i];
	
	rep(i, 1, n) if(i % 2 == 0) b[i] *= -1;
	rep(i, 1, n+1) d[i] = b[i] - b[i-1];
	rep(i, 1, m) uf.unite(l[i], r[i]+1);
	rep(i, 1, n+1) mp[uf.root(i)] += d[i];
	
	//rep(i, 1, n+1) cout << d[i] << " "; cout << endl;
	
	for(auto x : mp){
		if(x.second){
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	
	return 0;
}
0