提出 #63282366
ソースコード 拡げる
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
class Main {
public static void main(String[] args) {
FastScanner sc = new FastScanner();
int N = sc.nextInt();
int Q = sc.nextInt();
int[] P = new int[N+1];
int[] S = new int[N+1];
int[] S2 = new int[N+1];
for (int i = 1; i <= N; i++) {
P[i] = i;
S[i] = i;
S2[i] = i;
}
for (int i = 0; i < Q; i++) {
int q = sc.nextInt();
if (q == 1){
int a = sc.nextInt();
int b = sc.nextInt();
P[a] = S[b];
}
if (q == 2){
int a = sc.nextInt();
int b = sc.nextInt();
int c = S[a];
S[a] = S[b];
S[b] = c;
S2[S[a]] = a;
S2[S[b]] = b;
}
if (q == 3){
int a = sc.nextInt();
System.out.println(S2[P[a]]);
}
}
MyWriter.flush();
}
private static class MyWriter{
static StringBuilder sb = new StringBuilder();
protected static void flush(){
System.out.print(sb);
sb = new StringBuilder();
}
protected static void println(){
sb.append("\n");
}
protected static void println(int i){
sb.append(i).append("\n");
}
protected static void println(long l) {
sb.append(l).append("\n");
}
protected static void println(double d) {
sb.append(d).append("\n");
}
protected static void println(float f) {
sb.append(f).append("\n");
}
protected static void println(char c) {
sb.append(c).append("\n");
}
protected static void println(boolean b) {
sb.append(b).append("\n");
}
protected static void println(Object obj) {
String s = String.valueOf(obj);
sb.append(s).append("\n");
}
protected static void print(int i){
sb.append(i);
}
protected static void print(long l) {
sb.append(l);
}
protected static void print(double d) {
sb.append(d);
}
protected static void print(float f) {
sb.append(f);
}
protected static void print(char c) {
sb.append(c);
}
protected static void print(boolean b) {
sb.append(b);
}
protected static void print(Object obj) {
String s = String.valueOf(obj);
sb.append(s);
}
protected static void printInv(long a,long b,long MOD){
a %= MOD;
b %= MOD;
println((a * invGcd(b,MOD)[1])%MOD);
}
private static long safeMod(long x, long m){
x %= m;
if(x<0) x += m;
return x;
}
private static long[] invGcd(long a, long b){
a = safeMod(a, b);
if(a==0) return new long[]{b,0};
long s=b, t=a;
long m0=0, m1=1;
while(t>0){
long u = s/t;
s -= t*u;
m0 -= m1*u;
long tmp = s; s = t; t = tmp;
tmp = m0; m0 = m1; m1 = tmp;
}
if(m0<0) m0 += b/s;
return new long[]{s,m0};
}
public static long writerGcd(long... a){
if(a.length == 0) return 0;
long r = Math.abs(a[0]);
for(int i=1; i<a.length; i++){
if(a[i]!=0) {
if(r==0) r = Math.abs(a[i]);
else r = invGcd(r, Math.abs(a[i]))[0];
}
}
return r;
}
}
private static class FastScanner {
private final InputStream in = System.in;
private final byte[] buffer = new byte[1024];
private int ptr = 0;
private int buflen = 0;
private boolean hasNextByte() {
if (ptr < buflen) {
return true;
} else {
ptr = 0;
try {
buflen = in.read(buffer);
} catch (IOException e) {
e.printStackTrace();
}
return buflen > 0;
}
}
private int readByte() {
if (hasNextByte()) return buffer[ptr++];
else return -1;
}
private static boolean isPrintableChar(int c) {
return 33 <= c && c <= 126;
}
public boolean hasNext() {
while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
return !hasNextByte();
}
public String next() {
if (hasNext()) throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int b = readByte();
while (isPrintableChar(b)) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public long nextLong() {
if (hasNext()) throw new NoSuchElementException();
long n = 0;
boolean minus = false;
int b = readByte();
if (b == '-') {
minus = true;
b = readByte();
}
if (b < '0' || '9' < b) {
throw new NumberFormatException();
}
while (true) {
if ('0' <= b && b <= '9') {
n *= 10;
n += b - '0';
} else if (b == -1 || !isPrintableChar(b)) {
return minus ? -n : n;
} else {
throw new NumberFormatException();
}
b = readByte();
}
}
public int nextInt() {
long nl = nextLong();
if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
return (int) nl;
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | D - Pigeon Swap |
| ユーザ | AAH_tomato |
| 言語 | Java (OpenJDK 17) |
| 得点 | 350 |
| コード長 | 6562 Byte |
| 結果 | AC |
| 実行時間 | 659 ms |
| メモリ | 84140 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 350 / 350 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| 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_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, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 00_sample_00.txt | AC | 38 ms | 34076 KiB |
| 00_sample_01.txt | AC | 37 ms | 33840 KiB |
| 00_sample_02.txt | AC | 38 ms | 33988 KiB |
| 01_random_03.txt | AC | 437 ms | 83800 KiB |
| 01_random_04.txt | AC | 385 ms | 75548 KiB |
| 01_random_05.txt | AC | 439 ms | 84140 KiB |
| 01_random_06.txt | AC | 383 ms | 75380 KiB |
| 01_random_07.txt | AC | 87 ms | 43720 KiB |
| 01_random_08.txt | AC | 275 ms | 56332 KiB |
| 01_random_09.txt | AC | 107 ms | 50728 KiB |
| 01_random_10.txt | AC | 307 ms | 68100 KiB |
| 01_random_11.txt | AC | 431 ms | 69164 KiB |
| 01_random_12.txt | AC | 108 ms | 53752 KiB |
| 01_random_13.txt | AC | 539 ms | 73780 KiB |
| 01_random_14.txt | AC | 411 ms | 71900 KiB |
| 01_random_15.txt | AC | 112 ms | 53736 KiB |
| 01_random_16.txt | AC | 575 ms | 74312 KiB |
| 01_random_17.txt | AC | 551 ms | 73772 KiB |
| 01_random_18.txt | AC | 113 ms | 51864 KiB |
| 01_random_19.txt | AC | 397 ms | 72068 KiB |
| 01_random_20.txt | AC | 260 ms | 70760 KiB |
| 01_random_21.txt | AC | 109 ms | 53760 KiB |
| 01_random_22.txt | AC | 543 ms | 73624 KiB |
| 01_random_23.txt | AC | 582 ms | 73672 KiB |
| 01_random_24.txt | AC | 551 ms | 75788 KiB |
| 01_random_25.txt | AC | 649 ms | 69564 KiB |
| 01_random_26.txt | AC | 596 ms | 73744 KiB |
| 01_random_27.txt | AC | 596 ms | 70332 KiB |
| 01_random_28.txt | AC | 414 ms | 70656 KiB |
| 01_random_29.txt | AC | 659 ms | 73992 KiB |
| 01_random_30.txt | AC | 358 ms | 53752 KiB |