結果

問題 No.274 The Wall
ユーザー airisairis
提出日時 2015-08-29 01:03:06
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,709 bytes
コンパイル時間 869 ms
コンパイル使用メモリ 89,000 KB
実行使用メモリ 11,448 KB
最終ジャッジ日時 2023-09-25 19:32:58
合計ジャッジ時間 2,067 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 6 ms
11,212 KB
testcase_02 AC 5 ms
11,148 KB
testcase_03 AC 6 ms
11,176 KB
testcase_04 AC 5 ms
11,148 KB
testcase_05 AC 6 ms
11,176 KB
testcase_06 AC 6 ms
11,248 KB
testcase_07 AC 6 ms
11,444 KB
testcase_08 AC 5 ms
11,152 KB
testcase_09 AC 6 ms
11,204 KB
testcase_10 AC 6 ms
11,236 KB
testcase_11 AC 5 ms
11,228 KB
testcase_12 AC 7 ms
11,168 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 6 ms
11,148 KB
testcase_17 AC 6 ms
11,280 KB
testcase_18 AC 6 ms
11,148 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 6 ms
11,144 KB
testcase_23 AC 6 ms
11,228 KB
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <numeric>
#include <bitset>
#include <complex>
#define rep(x, to) for (int x = 0; x < (to); x++)
#define REP(x, a, to) for (int x = (a); x < (to); x++)
#define foreach(itr, x) for (typeof((x).begin()) itr = (x).begin(); itr != (x).end(); itr++)
#define EPS (1e-14)

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef complex<double> Complex;
typedef vector< vector<int> > Mat;


// 遅延評価SegmentTree
struct LazyPropagationSegmentTree {
	int n;
	ll lazy[500005];
	ll  dat[500005];
	void init(int m) {
		n = 1;
		while (n < m) n *= 2;
		memset(lazy, 0, sizeof(lazy));
		memset(dat, 0, sizeof(dat));
	}
	// ノードkの遅延評価を行う
	void lazy_evaluate(int k, int l, int r) {
		dat[k] += (r - l) * lazy[k];
		if (k < n - 1) {
			lazy[2 * k + 1] += lazy[k];
			lazy[2 * k + 2] += lazy[k];
		}
		lazy[k] = 0;
	}
	// 区間[a,b)にxを加える。
	// k,l,rは現在ノードkに着目し、ノードkは区間[l,r)を指すことを示す
	void add(int a, int b, int x, int k, int l, int r) {
		//再帰で帰ってきたとき、範囲外の領域のlazyも考慮する必要があるため
		//範囲外チェックの前に遅延評価を行う
		if (lazy[k] != 0) {
			lazy_evaluate(k, l, r);
		}
		if (b <= l || r <= a) return;
		if (a <= l && r <= b) {
			dat[k] += (r - l) * x;
			if (k < n - 1) {
				lazy[2 * k + 1] += x;
				lazy[2 * k + 2] += x;
			}
			return;
		}
		int m = (l + r) / 2;
		int chl = 2 * k + 1;
		int chr = 2 * k + 2;
		add(a, b, x, chl, l, m);
		add(a, b, x, chr, m, r);
		dat[k] = dat[chl] + dat[chr];
	}
	// 区間[a,b)の値を参照する
	// k,l,rは現在ノードkに着目し、ノードkは区間[l,r)を指すことを示す
	ll query(int a, int b, int k, int l, int r) {
		if (lazy[k] != 0) {
			lazy_evaluate(k, l, r);
		}
		if (b <= l || r <= a) return 0;
		if (a <= l && r <= b) return dat[k];
		int m = (l + r) / 2;
		int chl = 2 * k + 1;
		int chr = 2 * k + 2;
		return query(a, b, chl, l, m) + query(a, b, chr, m, r);
	}
};

LazyPropagationSegmentTree seg;
int N, M;

int main() {
	cin >> N >> M;
	seg.init(M);
	rep(i, N) {
		int L, R;
		cin >> L >> R;
		int x = seg.query(L, R + 1, 0, 0, seg.n);
		int y = seg.query(M - R - 1, M - L - 1, 0, 0, seg.n);
		if (x == 0) {
			seg.add(L, R + 1, 1, 0, 0, seg.n);
		} else if (y == 0) {
			seg.add(M - R - 1, M - L - 1, 1, 0, 0, seg.n);
		} else {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}


0