Submission #1986466
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 = 1999999999; 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 | 4850 Byte |
Status | WA |
Exec Time | 405 ms |
Memory | 38236 KB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 1200 | ||||||
Status |
|
|
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 | 141 ms | 28856 KB |
02.txt | WA | 150 ms | 32124 KB |
03.txt | AC | 351 ms | 37728 KB |
04.txt | WA | 199 ms | 31076 KB |
05.txt | AC | 149 ms | 30776 KB |
06.txt | AC | 328 ms | 34632 KB |
07.txt | WA | 151 ms | 32316 KB |
08.txt | WA | 181 ms | 30600 KB |
09.txt | WA | 356 ms | 36316 KB |
10.txt | AC | 198 ms | 29288 KB |
11.txt | WA | 179 ms | 31884 KB |
12.txt | WA | 350 ms | 38104 KB |
13.txt | WA | 151 ms | 29308 KB |
14.txt | WA | 152 ms | 31888 KB |
15.txt | WA | 354 ms | 35196 KB |
16.txt | WA | 151 ms | 30508 KB |
17.txt | WA | 139 ms | 29244 KB |
18.txt | WA | 351 ms | 38236 KB |
19.txt | WA | 201 ms | 31084 KB |
20.txt | WA | 139 ms | 30520 KB |
21.txt | WA | 405 ms | 33704 KB |
22.txt | WA | 200 ms | 30200 KB |
23.txt | WA | 140 ms | 32564 KB |
24.txt | WA | 303 ms | 34348 KB |
25.txt | WA | 198 ms | 31072 KB |
26.txt | WA | 149 ms | 30516 KB |
27.txt | WA | 338 ms | 38236 KB |
28.txt | WA | 151 ms | 32656 KB |
29.txt | WA | 156 ms | 29832 KB |
30.txt | WA | 359 ms | 37532 KB |
31.txt | AC | 69 ms | 19156 KB |
32.txt | AC | 69 ms | 19284 KB |
33.txt | AC | 69 ms | 18388 KB |
34.txt | AC | 69 ms | 18772 KB |
s1.txt | AC | 71 ms | 21332 KB |
s2.txt | AC | 69 ms | 19412 KB |