結果

問題 No.961 Vibrant Fillumination
ユーザー uwiuwi
提出日時 2019-12-24 01:21:09
言語 Java21
(openjdk 21)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 8,037 bytes
コンパイル時間 4,677 ms
コンパイル使用メモリ 88,992 KB
実行使用メモリ 171,264 KB
最終ジャッジ日時 2024-09-22 16:54:40
合計ジャッジ時間 48,963 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
132,352 KB
testcase_01 AC 87 ms
135,920 KB
testcase_02 AC 870 ms
146,664 KB
testcase_03 AC 930 ms
151,428 KB
testcase_04 AC 791 ms
153,264 KB
testcase_05 AC 780 ms
153,612 KB
testcase_06 AC 809 ms
153,792 KB
testcase_07 AC 1,006 ms
153,984 KB
testcase_08 AC 930 ms
151,636 KB
testcase_09 AC 769 ms
151,740 KB
testcase_10 AC 1,331 ms
169,140 KB
testcase_11 AC 1,341 ms
168,612 KB
testcase_12 AC 1,216 ms
171,044 KB
testcase_13 AC 1,261 ms
165,372 KB
testcase_14 AC 1,422 ms
171,264 KB
testcase_15 AC 1,276 ms
163,604 KB
testcase_16 AC 1,362 ms
162,844 KB
testcase_17 AC 1,274 ms
156,276 KB
testcase_18 AC 1,428 ms
160,852 KB
testcase_19 AC 1,300 ms
157,564 KB
testcase_20 AC 1,399 ms
166,032 KB
testcase_21 AC 1,407 ms
159,952 KB
testcase_22 AC 1,133 ms
164,616 KB
testcase_23 AC 1,168 ms
164,136 KB
testcase_24 AC 1,341 ms
165,508 KB
testcase_25 AC 1,348 ms
158,120 KB
testcase_26 AC 484 ms
151,772 KB
testcase_27 AC 839 ms
165,248 KB
testcase_28 AC 526 ms
152,416 KB
testcase_29 AC 873 ms
162,668 KB
testcase_30 AC 684 ms
146,676 KB
testcase_31 AC 676 ms
153,448 KB
testcase_32 AC 792 ms
150,104 KB
testcase_33 AC 89 ms
128,376 KB
testcase_34 TLE -
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[j], ys[j+1], co[0][4]};
					ret[p++] = new int[]{xs[i+1], ys[j], ys[j+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
	{
//		int n = 50000, m = 99999;
//		Random gen = new Random();
//		StringBuilder sb = new StringBuilder();
//		sb.append(n + " ");
//		for(int i = 0
//		for (int i = 0; i < n; i++) {
//			int v1 = gen.nextInt(2*n);
//			int v2 = gen.nextInt(2*n);
//			int w1 = gen.nextInt(2*n);
//			int w2 = gen.nextInt(2*n);
//			sb.append(Math.min(v1, v2) + 1 + " ");
//			sb.append(Math.min(w1, w2) + 1 + " ");
//			sb.append(Math.max(v1, v2) + 1 + " ");
//			sb.append(Math.max(w1, w2) + 1 + " ");
//			sb.append(gen.nextInt(200000) + " ");
//		}
//		INPUT = sb.toString();

		
		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