Submission #1987122


Source Code Expand

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.InputMismatchException;

public class Main {
	static InputStream is;
	static PrintWriter out;
	static String INPUT = "";
	
	static void solve()
	{
		int n = ni();
		int[][] co = new int[n][];
		for(int i = 0;i < n;i++){
			co[i] = na(2);
		}
		Arrays.sort(co, new Comparator<int[]>() {
			public int compare(int[] a, int[] b) {
				return a[0] - b[0];
			}
		});
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = co[i][1];
		a = shrink(a);
		
		int[] fl = new int[n];
		
		int[] lows = new int[n];
		lows[n-1] = a[n-1];
		for(int i = n-2;i >= 0;i--){
			lows[i] = Math.min(lows[i+1], a[i]);
		}
		
		int[] highs = new int[n];
		highs[0] = a[0];
		for(int i = 1;i < n;i++){
			highs[i] = Math.max(highs[i-1], a[i]);
		}
		
		long ans = 0;
		long[] dp = new long[n+1];
		dp[0] = 1;
		int p = 0;
		long ts = 0;
		int mod = 1000000007;
		for(int i = 0;i < n;i++){
			while(p < i && lows[i] - highs[p] > 1){
				ts -= dp[p];
				if(ts < 0)ts += mod;
				p++;
			}
			
			dp[i+1] = ts + (lows[i] == 0 ? 1 : 0);
			ts += dp[i+1];
			if(ts >= mod)ts -= mod;
			if(highs[i] == n-1){
				ans += dp[i+1];
			}
		}
		out.println(ans%mod);
	}
	
	public static int lowerBound(int[] a, int v){ return lowerBound(a, 0, a.length, v); }
	public static int lowerBound(int[] a, int l, int r, int v)
	{
		if(l > r || l < 0 || r > a.length)throw new IllegalArgumentException();
		int low = l-1, high = r;
		while(high-low > 1){
			int h = high+low>>>1;
			if(a[h] >= v){
				high = h;
			}else{
				low = h;
			}
		}
		return high;
	}

	
	public static int[] shrink(int[] a) {
		int n = a.length;
		long[] b = new long[n];
		for (int i = 0; i < n; i++)
			b[i] = (long) a[i] << 32 | i;
		Arrays.sort(b);
		int[] ret = new int[n];
		int p = 0;
		for (int i = 0; i < n; i++) {
			if (i > 0 && (b[i] ^ b[i - 1]) >> 32 != 0)
				p++;
			ret[(int) b[i]] = p;
		}
		return ret;
	}

	
	public static long pow(long a, long n, long mod) {
		//		a %= mod;
		long ret = 1;
		int x = 63 - Long.numberOfLeadingZeros(n);
		for (; x >= 0; x--) {
			ret = ret * ret % mod;
			if (n << 63 - x < 0)
				ret = ret * a % mod;
		}
		return ret;
	}

	
	public static void main(String[] args) throws Exception
	{
		long S = System.currentTimeMillis();
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);
		
		solve();
		out.flush();
		long G = System.currentTimeMillis();
		tr(G-S+"ms");
	}
	
	private static boolean eof()
	{
		if(lenbuf == -1)return true;
		int lptr = ptrbuf;
		while(lptr < lenbuf)if(!isSpaceChar(inbuf[lptr++]))return false;
		
		try {
			is.mark(1000);
			while(true){
				int b = is.read();
				if(b == -1){
					is.reset();
					return true;
				}else if(!isSpaceChar(b)){
					is.reset();
					return false;
				}
			}
		} catch (IOException e) {
			return true;
		}
	}
	
	private static byte[] inbuf = new byte[1024];
	static int lenbuf = 0, ptrbuf = 0;
	
	private static int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}
	
	private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
//	private static boolean isSpaceChar(int c) { return !(c >= 32 && c <= 126); }
	private static int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
	
	private static double nd() { return Double.parseDouble(ns()); }
	private static char nc() { return (char)skip(); }
	
	private static String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	
	private static char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}
	
	private static char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}
	
	private static int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}
	
	private static int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}
		
		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	
	private static long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}
		
		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	
	private static void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); }
}

Submission Info

Submission Time
Task E - Mr.Aoki Incubator
User uwi
Language Java8 (OpenJDK 1.8.0)
Score 0
Code Size 5513 Byte
Status WA
Exec Time 527 ms
Memory 49604 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 1200
Status
AC × 2
AC × 11
WA × 25
Set Name Test Cases
Sample s1.txt, s2.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, s1.txt, s2.txt
Case Name Status Exec Time Memory
01.txt WA 201 ms 37636 KB
02.txt WA 263 ms 38480 KB
03.txt AC 442 ms 35680 KB
04.txt WA 198 ms 40156 KB
05.txt AC 204 ms 37936 KB
06.txt AC 527 ms 35920 KB
07.txt WA 198 ms 36444 KB
08.txt WA 214 ms 36232 KB
09.txt AC 310 ms 34612 KB
10.txt AC 161 ms 36276 KB
11.txt WA 207 ms 35048 KB
12.txt WA 447 ms 33760 KB
13.txt WA 180 ms 36756 KB
14.txt WA 173 ms 35924 KB
15.txt WA 402 ms 38536 KB
16.txt WA 163 ms 35364 KB
17.txt WA 199 ms 35724 KB
18.txt WA 393 ms 38664 KB
19.txt WA 221 ms 35512 KB
20.txt WA 222 ms 34596 KB
21.txt WA 439 ms 38152 KB
22.txt WA 240 ms 35328 KB
23.txt WA 186 ms 38180 KB
24.txt WA 384 ms 35308 KB
25.txt WA 181 ms 37604 KB
26.txt WA 177 ms 36872 KB
27.txt WA 378 ms 44016 KB
28.txt WA 180 ms 34864 KB
29.txt WA 163 ms 39360 KB
30.txt WA 403 ms 49604 KB
31.txt AC 70 ms 19796 KB
32.txt AC 69 ms 19156 KB
33.txt AC 69 ms 18516 KB
34.txt AC 70 ms 19796 KB
s1.txt AC 72 ms 20692 KB
s2.txt AC 72 ms 20692 KB