Submission #56570744
Source Code Expand
import java.io.*;
import java.math.*;
import java.util.*;
class Main {
private static class FastInput {
private static BufferedReader br;
private static StringTokenizer st;
private static String token;
public FastInput(InputStream in) {
br = new BufferedReader(new InputStreamReader(in));
readLine();
}
public FastInput(String fileName) {
try {
InputStream in = new FileInputStream(fileName);
br = new BufferedReader(new InputStreamReader(in));
readLine();
} catch (Exception e) {}
}
private void readLine() {
try {
String line = br.readLine();
if (line == null) {
st = null;
}
else {
st = new StringTokenizer(line);
}
token = null;
} catch (Exception e) {}
}
private String peekToken() {
if (token == null) {
while (true) {
if (st == null) {
return null;
}
else if (st.hasMoreTokens()) {
token = st.nextToken();
break;
}
else {
readLine();
}
}
}
return token;
}
private String nextToken() {
String res = peekToken();
token = null;
return res;
}
public boolean hasNext() {
return (peekToken() != null);
}
public boolean hasNextBigDecimal() {
try {
BigDecimal x = new BigDecimal(peekToken());
return true;
} catch (Exception e) {
return false;
}
}
public boolean hasNextBigInteger() {
try {
BigInteger x = new BigInteger(peekToken());
return true;
} catch (Exception e) {
return false;
}
}
public boolean hasNextBoolean() {
try {
boolean x = Boolean.parseBoolean(peekToken());
return true;
}
catch (Exception e) {
return false;
}
}
public boolean hasNextByte() {
try {
byte x = Byte.parseByte(peekToken());
return true;
}
catch (Exception e) {
return false;
}
}
public boolean hasNextDouble() {
try {
double x = Double.parseDouble(peekToken());
return true;
}
catch (Exception e) {
return false;
}
}
public boolean hasNextFloat() {
try {
float x = Float.parseFloat(peekToken());
return true;
}
catch (Exception e) {
return false;
}
}
public boolean hasNextInt() {
try {
int x = Integer.parseInt(peekToken());
return true;
}
catch (Exception e) {
return false;
}
}
public boolean hasNextLine() {
return (st != null);
}
public boolean hasNextLong() {
try {
long x = Long.parseLong(peekToken());
return true;
}
catch (Exception e) {
return false;
}
}
public boolean hasNextShort() {
try {
short x = Short.parseShort(peekToken());
return true;
}
catch (Exception e) {
return false;
}
}
public String next() {
return nextToken();
}
public BigDecimal nextBigDecimal() {
BigDecimal x = new BigDecimal(nextToken());
return x;
}
public BigInteger nextBigInteger() {
BigInteger x = new BigInteger(nextToken());
return x;
}
public boolean nextBoolean() {
boolean x = Boolean.parseBoolean(nextToken());
return x;
}
public byte nextByte() {
byte x = Byte.parseByte(nextToken());
return x;
}
public double nextDouble() {
double x = Double.parseDouble(nextToken());
return x;
}
public float nextFloat() {
float x = Float.parseFloat(nextToken());
return x;
}
public int nextInt() {
int x = Integer.parseInt(nextToken());
return x;
}
public String nextLine() {
String res = (token == null ? "" : token);
try {
res += st.nextToken("");
}
catch (Exception e) {}
readLine();
return res;
}
public long nextLong() {
long x = Long.parseLong(nextToken());
return x;
}
public short nextShort() {
short x = Short.parseShort(nextToken());
return x;
}
}
private static class FastOutput {
private static BufferedWriter bw;
public FastOutput(OutputStream out) {
bw = new BufferedWriter(new OutputStreamWriter(out));
}
public FastOutput(String fileName) {
try {
OutputStream out = new FileOutputStream(fileName);
bw = new BufferedWriter(new OutputStreamWriter(out));
} catch (Exception e) {}
}
public void flush() {
try {
bw.flush();
} catch (Exception e) {}
}
public void print(boolean b) {
print(String.valueOf(b));
}
public void print(char c) {
print(String.valueOf(c));
}
public void print(char[] s) {
try {
bw.write(s, 0, s.length);
} catch (Exception e) {}
}
public void print(double d) {
print(String.valueOf(d));
}
public void print(float f) {
print(String.valueOf(f));
}
public void print(int i) {
print(String.valueOf(i));
}
public void print(long l) {
print(String.valueOf(l));
}
public void print(Object obj) {
print(String.valueOf(obj));
}
public void print(String s) {
try {
bw.write(s, 0, s.length());
} catch (Exception e) {}
}
public void println() {
try {
bw.newLine();
} catch (Exception e) {}
}
public void println(boolean x) {
print(x);
println();
}
public void println(char x) {
print(x);
println();
}
public void println(char[] x) {
print(x);
println();
}
public void println(double x) {
print(x);
println();
}
public void println(float x) {
print(x);
println();
}
public void println(int x) {
print(x);
println();
}
public void println(long x) {
print(x);
println();
}
public void println(Object x) {
print(x);
println();
}
public void println(String x) {
print(x);
println();
}
}
private static final FastInput in = new FastInput(System.in);
private static final FastOutput out = new FastOutput(System.out);
public static void main(String[] args) {
justDoIt();
out.flush();
}
private static final int MAX_X = 1_000_000;
private static void justDoIt() {
int q = in.nextInt();
int[] cnt = new int[MAX_X + 1];
int res = 0;
for (int i = 0; i < q; i++) {
int type = in.nextInt();
if (type == 1) {
int x = in.nextInt();
if (cnt[x] > 0) {
res--;
}
cnt[x]++;
if (cnt[x] > 0) {
res++;
}
}
else if (type == 2) {
int x = in.nextInt();
if (cnt[x] > 0) {
res--;
}
cnt[x]--;
if (cnt[x] > 0) {
res++;
}
}
else {
out.println(res);
}
}
}
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Balls and Bag Query |
| User | SanguineChame |
| Language | Java (OpenJDK 17) |
| Score | 300 |
| Code Size | 9411 Byte |
| Status | AC |
| Exec Time | 241 ms |
| Memory | 59292 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 300 / 300 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | AC | 40 ms | 38564 KiB |
| 00_sample_01.txt | AC | 40 ms | 38504 KiB |
| 01_random_00.txt | AC | 198 ms | 58200 KiB |
| 01_random_01.txt | AC | 202 ms | 58176 KiB |
| 01_random_02.txt | AC | 199 ms | 58488 KiB |
| 01_random_03.txt | AC | 206 ms | 58140 KiB |
| 01_random_04.txt | AC | 209 ms | 58824 KiB |
| 01_random_05.txt | AC | 214 ms | 58640 KiB |
| 01_random_06.txt | AC | 198 ms | 58596 KiB |
| 01_random_07.txt | AC | 207 ms | 58520 KiB |
| 01_random_08.txt | AC | 198 ms | 58728 KiB |
| 01_random_09.txt | AC | 214 ms | 59108 KiB |
| 01_random_10.txt | AC | 186 ms | 58320 KiB |
| 01_random_11.txt | AC | 196 ms | 58224 KiB |
| 01_random_12.txt | AC | 197 ms | 58780 KiB |
| 01_random_13.txt | AC | 192 ms | 58572 KiB |
| 01_random_14.txt | AC | 198 ms | 58072 KiB |
| 01_random_15.txt | AC | 198 ms | 58676 KiB |
| 01_random_16.txt | AC | 200 ms | 58380 KiB |
| 01_random_17.txt | AC | 189 ms | 58780 KiB |
| 01_random_18.txt | AC | 194 ms | 58528 KiB |
| 01_random_19.txt | AC | 227 ms | 58800 KiB |
| 01_random_20.txt | AC | 218 ms | 58916 KiB |
| 01_random_21.txt | AC | 241 ms | 59292 KiB |
| 01_random_22.txt | AC | 230 ms | 58808 KiB |