結果

問題 No.961 Vibrant Fillumination
ユーザー uwiuwi
提出日時 2019-12-24 01:21:09
言語 Java21
(openjdk 21)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 8,037 bytes
コンパイル時間 4,841 ms
コンパイル使用メモリ 88,996 KB
実行使用メモリ 178,996 KB
最終ジャッジ日時 2023-10-23 23:47:05
合計ジャッジ時間 44,764 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
146,556 KB
testcase_01 AC 80 ms
146,532 KB
testcase_02 AC 769 ms
157,216 KB
testcase_03 AC 800 ms
157,432 KB
testcase_04 AC 796 ms
157,196 KB
testcase_05 AC 662 ms
157,180 KB
testcase_06 AC 673 ms
157,380 KB
testcase_07 AC 653 ms
157,416 KB
testcase_08 AC 718 ms
157,736 KB
testcase_09 AC 656 ms
157,356 KB
testcase_10 AC 1,110 ms
177,084 KB
testcase_11 AC 1,237 ms
173,368 KB
testcase_12 AC 1,271 ms
176,680 KB
testcase_13 AC 1,208 ms
173,408 KB
testcase_14 AC 1,224 ms
178,996 KB
testcase_15 AC 1,186 ms
173,188 KB
testcase_16 AC 1,204 ms
178,712 KB
testcase_17 AC 1,277 ms
171,764 KB
testcase_18 AC 1,225 ms
176,716 KB
testcase_19 AC 1,171 ms
172,024 KB
testcase_20 AC 1,190 ms
176,596 KB
testcase_21 AC 1,064 ms
171,408 KB
testcase_22 AC 1,171 ms
170,480 KB
testcase_23 AC 1,036 ms
171,160 KB
testcase_24 AC 1,154 ms
174,384 KB
testcase_25 AC 1,365 ms
173,964 KB
testcase_26 AC 444 ms
157,032 KB
testcase_27 AC 804 ms
171,048 KB
testcase_28 AC 479 ms
157,748 KB
testcase_29 AC 860 ms
171,344 KB
testcase_30 AC 701 ms
159,236 KB
testcase_31 AC 564 ms
160,008 KB
testcase_32 AC 743 ms
159,648 KB
testcase_33 AC 81 ms
146,404 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