Submission #1560097
Source Code Expand
import java.io.*; import java.util.*; public class Main { void submit() { int x = nextInt(); int k = nextInt(); int[] flip = new int[k]; for (int i = 0; i < k; i++) { flip[i] = nextInt(); } int q = nextInt(); Function func = new Function(x); int dir = -1; int ptr = 0; int curT = 0; while (q-- > 0) { int t = nextInt(); int qx = nextInt(); while (ptr < k && flip[ptr] <= t) { func.modify(flip[ptr] - curT, dir); curT = flip[ptr]; dir *= -1; ptr++; } func.modify(t - curT, dir); curT = t; out.println(func.getAt(qx)); } } static class Function { int flipX; int flipY; int len; final int X; public Function(int x) { flipX = 0; flipY = 0; len = x; this.X = x; } int getAt(int x) { if (x <= flipX) { return flipY; } if (x >= flipX + len) { return flipY + len; } return flipY + x - flipX; } void modify(int dist, int dir) { flipY += dist * dir; if (flipY + len <= 0) { flipX = flipY = len = 0; return; } if (flipY >= X) { flipX = len = 0; flipY = X; return; } if (flipY < 0) { int delta = -flipY; flipX += delta; len -= delta; flipY = 0; return; } if (flipY + len > X) { int delta = flipY + len - X; len -= delta; return; } } } void preCalc() { } void stress() { } void test() { } Main() throws IOException { br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); preCalc(); submit(); //stress(); //test(); out.close(); } static final Random rng = new Random(); static int rand(int l, int r) { return l + rng.nextInt(r - l + 1); } public static void main(String[] args) throws IOException { new Main(); } BufferedReader br; PrintWriter out; StringTokenizer st; String nextToken() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return st.nextToken(); } String nextString() { try { return br.readLine(); } catch (IOException e) { throw new RuntimeException(e); } } int nextInt() { return Integer.parseInt(nextToken()); } long nextLong() { return Long.parseLong(nextToken()); } double nextDouble() { return Double.parseDouble(nextToken()); } }
Submission Info
Submission Time | |
---|---|
Task | F - Sandglass |
User | mmaxio |
Language | Java8 (OpenJDK 1.8.0) |
Score | 700 |
Code Size | 2592 Byte |
Status | AC |
Exec Time | 594 ms |
Memory | 54340 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 700 / 700 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_000.txt, 0_001.txt, 0_002.txt |
All | 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt, 1_026.txt, 1_027.txt, 1_028.txt, 1_029.txt, 1_030.txt, 1_031.txt, 1_032.txt, 1_033.txt, 1_034.txt, 1_035.txt, 1_036.txt, 1_037.txt, 1_038.txt, 1_039.txt, 1_040.txt, 1_041.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_000.txt | AC | 71 ms | 21076 KB |
0_001.txt | AC | 69 ms | 17492 KB |
0_002.txt | AC | 69 ms | 16852 KB |
1_003.txt | AC | 283 ms | 41364 KB |
1_004.txt | AC | 285 ms | 43740 KB |
1_005.txt | AC | 309 ms | 47360 KB |
1_006.txt | AC | 304 ms | 43464 KB |
1_007.txt | AC | 317 ms | 44400 KB |
1_008.txt | AC | 307 ms | 46628 KB |
1_009.txt | AC | 305 ms | 44460 KB |
1_010.txt | AC | 297 ms | 45004 KB |
1_011.txt | AC | 315 ms | 47844 KB |
1_012.txt | AC | 301 ms | 47632 KB |
1_013.txt | AC | 345 ms | 43480 KB |
1_014.txt | AC | 296 ms | 44392 KB |
1_015.txt | AC | 300 ms | 42332 KB |
1_016.txt | AC | 336 ms | 45712 KB |
1_017.txt | AC | 307 ms | 43364 KB |
1_018.txt | AC | 324 ms | 45424 KB |
1_019.txt | AC | 333 ms | 46336 KB |
1_020.txt | AC | 316 ms | 42820 KB |
1_021.txt | AC | 326 ms | 46988 KB |
1_022.txt | AC | 307 ms | 44448 KB |
1_023.txt | AC | 344 ms | 44592 KB |
1_024.txt | AC | 444 ms | 52260 KB |
1_025.txt | AC | 303 ms | 44152 KB |
1_026.txt | AC | 318 ms | 44020 KB |
1_027.txt | AC | 423 ms | 46420 KB |
1_028.txt | AC | 322 ms | 45504 KB |
1_029.txt | AC | 326 ms | 44596 KB |
1_030.txt | AC | 456 ms | 54340 KB |
1_031.txt | AC | 427 ms | 52704 KB |
1_032.txt | AC | 338 ms | 44888 KB |
1_033.txt | AC | 270 ms | 39808 KB |
1_034.txt | AC | 270 ms | 39480 KB |
1_035.txt | AC | 594 ms | 42936 KB |
1_036.txt | AC | 274 ms | 43640 KB |
1_037.txt | AC | 270 ms | 36988 KB |
1_038.txt | AC | 332 ms | 44112 KB |
1_039.txt | AC | 264 ms | 42780 KB |
1_040.txt | AC | 285 ms | 42068 KB |
1_041.txt | AC | 339 ms | 47588 KB |