結果

問題 No.961 Vibrant Fillumination
ユーザー uwiuwi
提出日時 2019-12-24 01:11:32
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 7,472 bytes
コンパイル時間 4,129 ms
コンパイル使用メモリ 90,192 KB
実行使用メモリ 758,708 KB
最終ジャッジ日時 2024-09-19 05:40:57
合計ジャッジ時間 42,655 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
143,656 KB
testcase_01 AC 79 ms
143,596 KB
testcase_02 AC 813 ms
155,860 KB
testcase_03 AC 817 ms
155,752 KB
testcase_04 AC 788 ms
154,252 KB
testcase_05 AC 632 ms
153,868 KB
testcase_06 AC 767 ms
154,104 KB
testcase_07 AC 660 ms
154,052 KB
testcase_08 AC 681 ms
154,552 KB
testcase_09 AC 662 ms
154,112 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 468 ms
153,684 KB
testcase_27 WA -
testcase_28 AC 472 ms
154,564 KB
testcase_29 WA -
testcase_30 AC 616 ms
156,356 KB
testcase_31 AC 543 ms
156,960 KB
testcase_32 AC 685 ms
156,724 KB
testcase_33 AC 75 ms
143,720 KB
testcase_34 MLE -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

package adv2019;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.InputMismatchException;

public class D24 {
	InputStream is;
	PrintWriter out;
	String INPUT = "";
	
	void solve()
	{
		int n = ni();
		long[] h = new long[n];
		for(int i = 0;i < n;i++){
			h[i] = nl();
		}
		int B = (int)Math.sqrt(n);
		
		int[][] co = new int[n][];
//		int[] f = new int[n];
		for(int i = 0;i < n;i++){
			co[i] = na(5);
			co[i][4]--;
//			f[co[i][4]]++;
		}
		Arrays.sort(co, new Comparator<int[]>() {
			public int compare(int[] a, int[] b) {
				if(a[4] != b[4])return a[4] - b[4];
				return a[0] - b[0];
			}
		});
		
		int Q = ni();
		int[][] qs = new int[Q][];
		for(int i = 0;i < Q;i++){
			qs[i] = new int[]{ni(), ni(), i};
		}
		Arrays.sort(qs, new Comparator<int[]>() {
			public int compare(int[] a, int[] b) {
				return a[0] - b[0];
			}
		});

		
		long[] anss = new long[Q];

//		int[] big = new int[n/B+1];
//		int bp = 0;
		int[][] es = new int[23000000][];
		int p = 0;
		for(int i = 0;i < n;){
			int j = i;
			while(j < n && co[j][4] == co[i][4]){
				j++;
			}
			if(j-i >= B){
				solve(Arrays.copyOfRange(co, i, j), qs, anss, h[co[i][4]], 2*n);
			}else{
				int[][] les = expand(Arrays.copyOfRange(co, i, j));
				for(int[] le : les){
					es[p++] = le;
				}
			}
			i = j;
		}
		
		es = Arrays.copyOf(es, p);
		Arrays.sort(es, new Comparator<int[]>() {
			public int compare(int[] a, int[] b) {
				return a[0] - b[0];
			}
		});
		
		long[] ft = new long[2*n+5];
		
		int qp = 0;
		for(int[] e : es){
			while(qp < Q && qs[qp][0] < e[0]){
				anss[qs[qp][2]] ^= sumFenwick(ft, qs[qp][1]);
				qp++;
			}
			addFenwick(ft, e[1], e[2], h[e[3]]);
		}
		
		for(long v : anss){
			out.println(v);
		}
	}
	
	int[][] expand(int[][] co)
	{
		int m = co.length;
		
		int[] xs = new int[2*m];
		{
			int p = 0;
			for(int i = 0;i < m;i++){
				xs[p++] = co[i][0];
				xs[p++] = co[i][2];
			}
			Arrays.sort(xs);
			xs = uniq(xs);
		}
		
		int[] ys = new int[2*m];
		{
			int p = 0;
			for(int i = 0;i < m;i++){
				ys[p++] = co[i][1];
				ys[p++] = co[i][3];
			}
			Arrays.sort(ys);
			ys = uniq(ys);
		}
		
		int[][] g = new int[xs.length+1][ys.length+1];
		for(int i = 0;i < m;i++){
			int xl = Arrays.binarySearch(xs, co[i][0]);
			int xr = Arrays.binarySearch(xs, co[i][2]);
			int yl = Arrays.binarySearch(ys, co[i][1]);
			int yr = Arrays.binarySearch(ys, co[i][3]);
			g[xl][yl]++;
			g[xl][yr]--;
			g[xr][yl]--;
			g[xr][yr]++;
		}
		for(int i = 0;i <= xs.length;i++){
			for(int j = 0;j <= ys.length;j++){
				if(i-1 >= 0)g[i][j] += g[i-1][j];
				if(j-1 >= 0)g[i][j] += g[i][j-1];
				if(i-1 >= 0 && j-1 >= 0){
					g[i][j] -= g[i-1][j-1];
				}
			}
		}
		int[][] ret = new int[xs.length*ys.length*2][];
		int p = 0;
		for(int i = 0;i < xs.length;i++){
			for(int j = 0;j < ys.length;j++){
				if(g[i][j] > 0){
					ret[p++] = new int[]{xs[i], ys[i], ys[i+1], co[0][4]};
					ret[p++] = new int[]{xs[i+1], ys[i], ys[i+1], co[0][4]};
				}
			}
		}
		return Arrays.copyOf(ret, p);
	}
	
	public static int[] uniq(int[] a)
	{
		int n = a.length;
		int p = 0;
		for(int i = 0;i < n;i++) {
			if(i == 0 || a[i] != a[i-1])a[p++] = a[i];
		}
		return Arrays.copyOf(a, p);
	}

	
	void solve(int[][] co, int[][] qs, long[] anss, long h, int H)
	{
		int m = co.length;
		int[][] es = new int[m*2][];
		int p = 0;
		for(int i = 0;i < m;i++){
			es[p++] = new int[]{co[i][0], co[i][1], co[i][3], 1};
			es[p++] = new int[]{co[i][2], co[i][1], co[i][3], -1};
		}
		Arrays.sort(es, new Comparator<int[]>() {
			public int compare(int[] a, int[] b) {
				return a[0] - b[0];
			}
		});
		int[] ft = new int[H+5];
		int qp = 0;
		for(int[] e : es){
			while(qp < qs.length && qs[qp][0] < e[0]){
				if(sumFenwick(ft, qs[qp][1]) >= 1){
					anss[qs[qp][2]] ^= h;
				}
				qp++;
			}
			addFenwick(ft, e[1], e[2], e[3]);
		}
	}
	
	public static int sumFenwick(int[] ft, int i)
	{
		int sum = 0;
		for(i++;i > 0;i -= i&-i)sum += ft[i];
		return sum;
	}
	
	public static void addFenwick(int[] ft, int l, int r, int v)
	{
		addFenwick(ft, l, v);
		addFenwick(ft, r, -v);
	}
	
	public static void addFenwick(int[] ft, int i, int v)
	{
		if(v == 0 || i < 0)return;
		int n = ft.length;
		for(i++;i < n;i += i&-i)ft[i] += v;
	}

	
	public static long sumFenwick(long[] ft, int i)
	{
		long sum = 0;
		for(i++;i > 0;i -= i&-i)sum ^= ft[i];
		return sum;
	}
	
	public static void addFenwick(long[] ft, int l, int r, long v)
	{
		addFenwick(ft, l, v);
		addFenwick(ft, r, v);
	}
	
	public static void addFenwick(long[] ft, int i, long v)
	{
		if(v == 0)return;
		int n = ft.length;
		for(i++;i < n;i += i&-i)ft[i] ^= v;
	}

	
	void run() throws Exception
	{
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);
		
		long s = System.currentTimeMillis();
		solve();
		out.flush();
		if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
//		Thread t = new Thread(null, null, "~", Runtime.getRuntime().maxMemory()){
//			@Override
//			public void run() {
//				long s = System.currentTimeMillis();
//				solve();
//				out.flush();
//				if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
//			}
//		};
//		t.start();
//		t.join();
	}
	
	public static void main(String[] args) throws Exception { new D24().run(); }
	
	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;
	
	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}
	
	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
	
	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }
	
	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	
	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}
	
	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}
	
	private long[] nal(int n)
	{
		long[] a = new long[n];
		for(int i = 0;i < n;i++)a[i] = nl();
		return a;
	}
	
	private char[][] nm(int n, int m) {
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}
	
	private int[][] nmi(int n, int m) {
		int[][] map = new int[n][];
		for(int i = 0;i < n;i++)map[i] = na(m);
		return map;
	}
	
	private int ni() { return (int)nl(); }
	
	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}
		
		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	
	private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); }
}
0