Submission #1389389


Source Code Expand

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] s = new int[n];
		int[] t = new int[n];
		int sz = 1_000_00;
		SegmentTree st = new SegmentTree(sz);
		for (int i = 0; i < n; ++i) {
			s[i] = sc.nextInt();
			t[i] = sc.nextInt();
			--s[i];
			--t[i];
			st.add(s[i], t[i], 1);
		}
		int ans = Integer.MAX_VALUE;
		for (int i = 0; i < n; ++i) {
			st.add(s[i], t[i], -1);
			ans = Math.min(ans, st.query(0, sz));
			st.add(s[i], t[i], 1);
		}
		System.out.println(ans);

	}

	class SegmentTree {
		int n = 1;
		int[] v;
		int[] lazy;

		public SegmentTree(int n_) {
			while (n < n_) {
				n *= 2;
			}
			v = new int[2 * n - 1];
			lazy = new int[2 * n - 1];
			Arrays.fill(v, 0);
		}

		void push(int k) {
			if (lazy[k] == 0) {
				return;
			}
			if (k < n - 1) {
				lazy[2 * k + 1] += lazy[k];
				lazy[2 * k + 2] += lazy[k];
			}
			v[k] += lazy[k];
			lazy[k] = 0;
		}

		int add(int a, int b, int add) {
			return query(a, b, 0, n, 0, add);
		}

		int query(int a, int b) {
			return query(a, b, 0, n, 0, 0);
		}

		// [a,b)
		// [l,r)
		int query(int a, int b, int l, int r, int k, int add) {
			push(k);
			if (a <= l && r <= b) {
				lazy[k] = add;
				push(k);
				return v[k];
			} else if (b <= l || r <= a) {
				return 0;
			} else {
				int vl = query(a, b, l, (l + r) / 2, 2 * k + 1, add);
				int vr = query(a, b, (l + r) / 2, r, 2 * k + 2, add);
				v[k] = Math.max(v[2 * k + 1], v[2 * k + 2]);
				return Math.max(vl, vr);
			}
		}

	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Submission Info

Submission Time
Task D - 足ゲームII
User fortoobye
Language Java8 (OpenJDK 1.8.0)
Score 100
Code Size 1810 Byte
Status AC
Exec Time 742 ms
Memory 83804 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 3
AC × 34
Set Name Test Cases
Sample sample-01.txt, sample-02.txt, sample-03.txt
All sample-01.txt, sample-02.txt, sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, sample-01.txt, sample-02.txt, sample-03.txt
Case Name Status Exec Time Memory
01-01.txt AC 101 ms 21972 KB
01-02.txt AC 105 ms 21972 KB
01-03.txt AC 109 ms 21460 KB
01-04.txt AC 148 ms 27332 KB
01-05.txt AC 726 ms 65928 KB
01-06.txt AC 722 ms 62996 KB
01-07.txt AC 718 ms 81936 KB
01-08.txt AC 725 ms 63572 KB
01-09.txt AC 709 ms 63756 KB
01-10.txt AC 112 ms 24276 KB
01-11.txt AC 725 ms 65732 KB
01-12.txt AC 711 ms 63636 KB
01-13.txt AC 705 ms 65168 KB
01-14.txt AC 729 ms 63232 KB
01-15.txt AC 179 ms 29664 KB
01-16.txt AC 711 ms 64088 KB
01-17.txt AC 732 ms 83804 KB
01-18.txt AC 731 ms 81952 KB
01-19.txt AC 704 ms 63924 KB
01-20.txt AC 177 ms 27928 KB
01-21.txt AC 714 ms 79476 KB
01-22.txt AC 742 ms 82836 KB
01-23.txt AC 700 ms 68288 KB
01-24.txt AC 631 ms 62400 KB
01-25.txt AC 107 ms 19668 KB
01-26.txt AC 97 ms 25812 KB
01-27.txt AC 627 ms 62456 KB
01-28.txt AC 687 ms 64424 KB
sample-01.txt AC 104 ms 21972 KB
sample-02.txt AC 106 ms 21332 KB
sample-03.txt AC 107 ms 23892 KB