結果
| 問題 | No.1290 Addition and Subtraction Operation |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-08-26 23:22:21 |
| 言語 | C++17 (gcc 15.3.0 + boost 1.92.0) |
| 結果 |
AC
|
| 実行時間 | 24 ms / 2,000 ms |
| + 175µs | |
| コード長 | 811 bytes |
| 記録 | |
| コンパイル時間 | 1,526 ms |
| コンパイル使用メモリ | 210,960 KB |
| 実行使用メモリ | 6,272 KB |
| 最終ジャッジ日時 | 2026-08-26 23:22:28 |
| 合計ジャッジ時間 | 6,442 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 85 |
ソースコード
#include <bits/stdc++.h>
using LL = long long;
const int N = 2e5 + 7;
LL sum[N];
int n, m, a[N], set[N];
int find(int x) {
return set[x] == x ? x : set[x] = find(set[x]);
}
void uni(int x, int y) {
x = find(x);
y = find(y);
if(x != y) {
sum[y] += sum[x];
set[x] = y;
}
}
void solve() {
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
if(i & 1)
a[i] = -a[i];
}
a[n + 1] = 0;
for(int i = 1; i <= n + 1; ++i) {
set[i] = i;
sum[i] = a[i] - a[i - 1];
}
while(m--) {
int l, r;
scanf("%d%d", &l, &r);
uni(l, r + 1);
}
for(int i = 1; i <= n + 1; ++i)
if(set[i] == i && sum[i]) {
puts("NO");
return ;
}
puts("YES");
}
int main() {
int cases = 1;
while(cases--)
solve();
return 0;
}