Submission #1986463


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];
		
		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 low = 99999999;
		for(int i = 0;i < n;i++){
			if(low >= lows[i]){
				fl[i] |= 1;
			}
			low = Math.min(low, 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]);
		}
		int high = -1;
		for(int i = n-1;i >= 0;i--){
			if(high <= highs[i]){
				fl[i] |= 2;
			}
			high = Math.max(high, a[i]);
		}
		int[] ff = new int[4];
		for(int v : fl)ff[v]++;
		
		int mod = 1000000007;
		long ans = 
		(pow(2, ff[3], mod) - 1) * pow(2, ff[0]+ff[1]+ff[2], mod) + 
		(pow(2, ff[1], mod) - 1) * (pow(2, ff[2], mod) - 1) % mod * pow(2, ff[0], mod);
		out.println(ans%mod);
	}
	
	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 4848 Byte
Status WA
Exec Time 401 ms
Memory 36868 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 1200
Status
AC × 2
AC × 10
WA × 26
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 151 ms 30876 KB
02.txt WA 178 ms 30084 KB
03.txt AC 319 ms 33144 KB
04.txt WA 191 ms 29932 KB
05.txt AC 148 ms 30596 KB
06.txt AC 361 ms 36868 KB
07.txt WA 141 ms 32516 KB
08.txt WA 178 ms 32776 KB
09.txt WA 346 ms 30712 KB
10.txt AC 180 ms 32772 KB
11.txt WA 179 ms 32640 KB
12.txt WA 346 ms 35276 KB
13.txt WA 149 ms 30624 KB
14.txt WA 178 ms 32392 KB
15.txt WA 320 ms 32764 KB
16.txt WA 197 ms 30176 KB
17.txt WA 194 ms 33028 KB
18.txt WA 316 ms 32256 KB
19.txt WA 154 ms 29840 KB
20.txt WA 180 ms 30596 KB
21.txt WA 401 ms 33880 KB
22.txt WA 141 ms 31356 KB
23.txt WA 149 ms 30652 KB
24.txt WA 346 ms 31708 KB
25.txt WA 199 ms 30700 KB
26.txt WA 178 ms 30972 KB
27.txt WA 328 ms 34824 KB
28.txt WA 150 ms 33980 KB
29.txt WA 177 ms 29448 KB
30.txt WA 325 ms 36520 KB
31.txt AC 69 ms 18004 KB
32.txt AC 69 ms 21204 KB
33.txt AC 69 ms 18260 KB
34.txt AC 67 ms 21204 KB
s1.txt AC 68 ms 18388 KB
s2.txt AC 69 ms 21076 KB