Problem:
Range Update Query (RUQ)

Write a program which manipulates a sequence A = {a0, a1, . . . , an−1} with the following operations:

update(s, t, x): change as, as+1, ..., at to x.

find(i): output the value of ai.

Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1.

Input

n q
query1
query2
:
queryq

In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, ith query queryi is given in the following format:

0 s t x

or

1 i

The first digit represents the type of the query. '0' denotes update(s, t, x) and '1' denotes find(i).

Output

For each find operation, print the value.

Constraints

1 ≤ n ≤ 100000

1 ≤ q ≤ 100000

0 ≤ s ≤ t < n

0 ≤ i < n

0 ≤ x < 231−1

Sample Input 1

3 5
0 0 1 1
0 1 2 3
0 2 2 2
1 0
1 1

Sample Output 1

1
3

Sample Input 2

1 3
1 0
0 0 0 5
1 0

Sample Output 2

2147483647
5

Solution in JAVA (judge verdict: Wrong Answer)

import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
import java.util.Arrays;

public class Main {
	public static class SegmentTree {
		int[] tree;
		public SegmentTree(int n) {
			int d = (int)Math.ceil(Math.log((double)n) / Math.log(2.0));
			tree = new int[(int)Math.pow(2, d+1)];
			Arrays.fill(tree, -1);
			tree[0] = Integer.MAX_VALUE;
		}

		public int find(int i) {
			i += tree.length/2-1;
			int r = tree[i];
			while(i > 0) {
				i = (i - 1) / 2;
				r = Math.max(r, tree[i]);
			}
			return r;
		}

		public void update(int i, int x) {
			i += tree.length/2-1;
			tree[i] = x;
			while(i > 0) {
				i = (i - 1) / 2;
				tree[i] = Math.min(tree[i*2+1], tree[i*2+2]);
			}
			// print();
		}

		// usage
		// updateRange(a, b, x, 0, 0, seg.tree.length/2)
		public void updateRange(int a, int b, int x, int k, int l, int r) {
			if(r <= a || b < l) return;
			if(a <= l && r-1 <= b) tree[k] = x;
			else {
				if(tree[k] >= 0) {
					tree[k*2+1] = tree[k];
					tree[k*2+2] = tree[k];
					tree[k] = -1;
				}
				updateRange(a, b, x, k*2+1, l, (l+r)/2);
				updateRange(a, b, x, k*2+2, (l+r)/2, r);
			}
		}

		// usage
		// query(a, b, 0, 0, seg.tree.length/2)
		public int query(int a, int b, int k, int l, int r) {
			// System.out.println(a+" "+b+" "+k+" "+l+" "+r);
			if(r <= a || b < l) return Integer.MAX_VALUE;
			if(a <= l && r-1 <= b) return tree[k];
			else {
				int vl = query(a, b, k*2+1, l, (l+r)/2);
				int vr = query(a, b, k*2+2, (l+r)/2, r);
				return Math.min(vl, vr);
			}
		}

		public void print() {
			for(int i=0; i<tree.length-1; i++) {
				System.out.print(tree[i]+" ");
			}
			System.out.println();
		}
	}

	public static void main(String[] args) {
		FS r = new FS();
		int n = r.nextInt();
		int q = r.nextInt();
		SegmentTree seg = new SegmentTree(n);
		for(int k=0; k<q; k++) {
			int c = r.nextInt();
			if(c == 0) {
				int s = r.nextInt();
				int t = r.nextInt();
				int x = r.nextInt();
				seg.updateRange(s, t, x, 0, 0, seg.tree.length/2);
			} else {
				int i = r.nextInt();
				System.out.println(seg.find(i));
			}
		}
	}
	
	// Read Class
	static class FS {
		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();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}
	
		private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
		private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
		private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	
		public boolean hasNext() { skipUnprintable(); 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 int nextInt() {
			return (int)nextLong();
		}
		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();
			}
		}
	}
}