結果

問題 No.1290 Addition and Subtraction Operation
ユーザー pockynypockyny
提出日時 2020-11-14 00:11:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 933 bytes
コンパイル時間 633 ms
コンパイル使用メモリ 70,332 KB
実行使用メモリ 7,252 KB
最終ジャッジ日時 2023-09-30 04:27:08
合計ジャッジ時間 6,211 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 WA -
testcase_08 AC 2 ms
4,380 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 WA -
testcase_16 AC 2 ms
4,376 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 2 ms
4,376 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 2 ms
4,376 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 WA -
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 AC 33 ms
6,088 KB
testcase_58 AC 42 ms
6,344 KB
testcase_59 AC 32 ms
6,108 KB
testcase_60 AC 71 ms
7,240 KB
testcase_61 AC 57 ms
6,764 KB
testcase_62 AC 62 ms
6,872 KB
testcase_63 AC 41 ms
6,324 KB
testcase_64 AC 21 ms
5,732 KB
testcase_65 AC 27 ms
5,992 KB
testcase_66 AC 49 ms
6,572 KB
testcase_67 AC 74 ms
7,252 KB
testcase_68 AC 58 ms
7,056 KB
testcase_69 AC 41 ms
6,352 KB
testcase_70 AC 38 ms
6,248 KB
testcase_71 AC 46 ms
6,500 KB
testcase_72 AC 27 ms
5,916 KB
testcase_73 AC 52 ms
6,652 KB
testcase_74 AC 19 ms
5,800 KB
testcase_75 AC 24 ms
5,848 KB
testcase_76 AC 39 ms
6,296 KB
testcase_77 WA -
testcase_78 WA -
testcase_79 WA -
testcase_80 WA -
testcase_81 WA -
testcase_82 AC 65 ms
6,488 KB
testcase_83 AC 86 ms
7,084 KB
testcase_84 AC 81 ms
6,952 KB
testcase_85 AC 47 ms
6,116 KB
testcase_86 AC 39 ms
5,852 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