結果
| 問題 |
No.387 ハンコ
|
| コンテスト | |
| ユーザー |
anta
|
| 提出日時 | 2016-06-24 00:07:06 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 2,195 ms / 5,000 ms |
| コード長 | 2,178 bytes |
| コンパイル時間 | 2,397 ms |
| コンパイル使用メモリ | 85,444 KB |
| 実行使用メモリ | 63,512 KB |
| 最終ジャッジ日時 | 2024-10-11 19:08:52 |
| 合計ジャッジ時間 | 23,242 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 9 |
ソースコード
package com.example;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int[] a = new int[N], b = new int[N];
for(int i = 0; i < N; ++ i)
a[i] = sc.nextInt();
for(int i = 0; i < N; ++ i)
b[i] = sc.nextInt();
int X = (N - 1) / 64 + 1;
long[] B = new long[X * 2 + 2];
for(int i = 0; i < N; ++ i) if(b[i] == 1)
B[i / 64] |= 1L << i % 64;
List<Long> values = new ArrayList<Long>();
for(int i = 0; i < N; ++ i)
values.add((long)a[i] << 32 | i);
Collections.sort(values);
int V = 0;
int[][] shifts = new int[N][];
int[] tmp = new int[N];
for(int i = 0, j; i < N; i = j) {
int k = 0;
for(j = i; j < N && values.get(j) >>> 32 == values.get(i) >>> 32; ++ j)
tmp[k ++] = values.get(j).intValue();
shifts[V] = Arrays.copyOf(tmp, k);
++ V;
}
long[] row = new long[X * 2 + 2];
long[] C = new long[X * 2];
for(int i = 0; i < V; ++ i) {
int Y = X + shifts[i][shifts[i].length - 1] / 64 + 1;
Arrays.fill(row, 0, Y, 0L);
for(int shift : shifts[i])
shiftOr(row, B, X, shift);
for(int j = 0; j < Y; ++ j)
C[j] ^= row[j];
}
for(int i = 0; i < N * 2 - 1; ++ i)
System.out.println((C[i / 64] >>> (i % 64) & 1) != 0 ? "ODD" : "EVEN");
}
static void shiftOr(long[] x, long[] y, int N, int shift) {
if(N <= 0) return;
int offset = shift / 64;
shift %= 64;
if(shift == 0) {
for(int i = 0; i < N; ++ i)
x[offset + i] |= y[i];
}else {
int shift2 = 64 - shift;
x[offset] |= y[0] << shift;
for(int i = 0; i < N - 1; ++ i)
x[offset+ i + 1] |= y[i + 1] << shift | y[i] >>> shift2;
x[offset + N] |= y[N - 1] >>> shift2;
}
}
}
anta