Submission #25578279
Source Code Expand
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.TreeMap;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
MyScanner in = new MyScanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
D solver = new D();
solver.solve(1, in, out);
out.close();
}
static class D {
public void solve(int testNumber, MyScanner in, PrintWriter out) {
int L = in.Int(), Q = in.Int();
TreeMap<Integer, Integer> map = new TreeMap<>();
for (int q = 0; q < Q; q++) {
int c = in.Int(), x = in.Int();
Integer fk = map.floorKey(x);
Integer ck = map.ceilingKey(x);
int pos = (fk == null) ? 0 : fk;
if (c == 1) {
map.put(x, x - pos);
if (ck != null) {
pos = x;
map.put(ck, ck - pos);
}
} else {
Integer k = map.ceilingKey(x);
int ans = k == null ? L - pos : map.get(k);
out.println(ans);
}
}
}
}
static class MyScanner {
private BufferedReader in;
private StringTokenizer st;
public MyScanner(InputStream stream) {
in = new BufferedReader(new InputStreamReader(stream));
}
public String next() {
while (st == null || !st.hasMoreTokens()) {
try {
String rl = in.readLine();
if (rl == null) {
return null;
}
st = new StringTokenizer(rl);
} catch (IOException e) {
return null;
}
}
return st.nextToken();
}
public int Int() {
return Integer.parseInt(next());
}
}
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Cutting Woods |
| User | daira4000 |
| Language | Java (OpenJDK 11.0.6) |
| Score | 400 |
| Code Size | 2452 Byte |
| Status | AC |
| Exec Time | 727 ms |
| Memory | 69780 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 400 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_max_random_00.txt, 01_max_random_01.txt, 01_max_random_02.txt, 01_max_random_03.txt, 01_max_random_04.txt, 02_all_1_00.txt, 03_all_2_00.txt, 04_hack_00.txt, 04_hack_01.txt, 04_hack_02.txt, 04_hack_03.txt, 04_hack_04.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | AC | 78 ms | 33216 KiB |
| 00_sample_01.txt | AC | 72 ms | 32320 KiB |
| 00_sample_02.txt | AC | 80 ms | 32852 KiB |
| 01_max_random_00.txt | AC | 727 ms | 66520 KiB |
| 01_max_random_01.txt | AC | 649 ms | 62824 KiB |
| 01_max_random_02.txt | AC | 682 ms | 63216 KiB |
| 01_max_random_03.txt | AC | 701 ms | 63140 KiB |
| 01_max_random_04.txt | AC | 685 ms | 63216 KiB |
| 02_all_1_00.txt | AC | 613 ms | 67276 KiB |
| 03_all_2_00.txt | AC | 374 ms | 54496 KiB |
| 04_hack_00.txt | AC | 455 ms | 68528 KiB |
| 04_hack_01.txt | AC | 456 ms | 69736 KiB |
| 04_hack_02.txt | AC | 650 ms | 67048 KiB |
| 04_hack_03.txt | AC | 592 ms | 67832 KiB |
| 04_hack_04.txt | AC | 638 ms | 69780 KiB |