結果

問題 No.1290 Addition and Subtraction Operation
ユーザー pockynypockyny
提出日時 2020-11-14 00:15:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 933 bytes
コンパイル時間 603 ms
コンパイル使用メモリ 69,764 KB
実行使用メモリ 7,280 KB
最終ジャッジ日時 2023-09-30 04:27:54
合計ジャッジ時間 5,626 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,384 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,384 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 35 ms
4,976 KB
testcase_43 AC 37 ms
4,988 KB
testcase_44 AC 35 ms
4,916 KB
testcase_45 AC 36 ms
4,916 KB
testcase_46 AC 36 ms
4,992 KB
testcase_47 AC 36 ms
4,956 KB
testcase_48 AC 35 ms
4,972 KB
testcase_49 AC 36 ms
4,972 KB
testcase_50 AC 36 ms
5,020 KB
testcase_51 AC 37 ms
4,956 KB
testcase_52 AC 36 ms
4,976 KB
testcase_53 AC 35 ms
5,124 KB
testcase_54 AC 36 ms
5,020 KB
testcase_55 AC 34 ms
4,920 KB
testcase_56 AC 35 ms
5,032 KB
testcase_57 AC 29 ms
6,312 KB
testcase_58 AC 36 ms
6,340 KB
testcase_59 AC 27 ms
6,044 KB
testcase_60 AC 61 ms
7,148 KB
testcase_61 AC 50 ms
6,756 KB
testcase_62 AC 52 ms
6,920 KB
testcase_63 AC 34 ms
6,368 KB
testcase_64 AC 18 ms
5,728 KB
testcase_65 AC 24 ms
5,952 KB
testcase_66 AC 44 ms
6,540 KB
testcase_67 AC 62 ms
7,280 KB
testcase_68 AC 54 ms
6,828 KB
testcase_69 AC 35 ms
6,316 KB
testcase_70 AC 32 ms
6,512 KB
testcase_71 AC 40 ms
6,460 KB
testcase_72 AC 23 ms
5,916 KB
testcase_73 AC 45 ms
6,652 KB
testcase_74 AC 16 ms
5,940 KB
testcase_75 AC 21 ms
5,864 KB
testcase_76 AC 35 ms
6,272 KB
testcase_77 AC 68 ms
6,880 KB
testcase_78 AC 62 ms
6,712 KB
testcase_79 AC 47 ms
6,464 KB
testcase_80 AC 77 ms
7,112 KB
testcase_81 AC 74 ms
7,096 KB
testcase_82 AC 55 ms
6,716 KB
testcase_83 AC 78 ms
7,268 KB
testcase_84 AC 73 ms
6,944 KB
testcase_85 AC 42 ms
6,260 KB
testcase_86 AC 34 ms
5,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

using namespace std;
int par[100010],sz[100010];
long long sz2[100010],b[100010];
void init(int n){
	for(int i=0;i<n;i++) par[i] = i,sz[i] = 1,sz2[i] = b[i];
}

int find(int x){
	if(par[x]==x) return x;
	return par[x] = find(par[x]);
}

void unite(int x, int y){
	x = find(x); y = find(y);
	if(x==y) return;
	if(sz[x]>sz[y]) swap(x,y);
	par[x] = y; sz[y] += sz[x]; sz2[y] += sz2[x];
}

bool same(int x, int y){
	return find(x)==find(y);
}

long long l[100010],r[100010];
int main(){
    int i,n,m; cin >> n >> m;
    for(i=0;i<n;i++) cin >> b[i];
    for(i=0;i<m;i++) cin >> l[i] >> r[i];
    for(i=0;i<n;i+=2) b[i] *= -1;
    for(i=n;i>0;i--) b[i] -= b[i - 1];
    init(n + 1);
    for(i=0;i<m;i++){
        l[i]--; r[i]--;
        unite(l[i],r[i] + 1);
    }
    for(i=0;i<=n;i++){
        if(find(i)!=i || sz2[i]==0) continue;
        cout << "NO" << endl;
        return 0;
    }
    cout << "YES" << endl;
}
0