using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static long NN => long.Parse(ReadLine()); static long[] NList => ReadLine().Split().Select(long.Parse).ToArray(); static long[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList; var (n, k, q) = (c[0], (int)c[1], c[2]); var walls = NArr(k); var query = NArr(q); var wlist = new List<(int id, long height)>[n]; var qlist = new List<(int id, long height)>[n]; for (var i = 0; i < n; ++i) { wlist[i] = new List<(int id, long height)>(); qlist[i] = new List<(int id, long height)>(); } for (var i = 0; i < k; ++i) { wlist[walls[i][0] - 1].Add((i, walls[i][3])); if (walls[i][1] < n) wlist[walls[i][1]].Add((i, -walls[i][3])); } for (var i = 0; i < q; ++i) { qlist[query[i][0] - 1].Add((i, query[i][1])); } var ft = new FenwickTree(k + 1); var ans = new long[q]; for (var i = 0; i < n; ++i) { foreach (var w in wlist[i]) { ft.Add(w.id, w.height); } foreach (var qi in qlist[i]) { if (ft.Sum(k) < qi.height) ans[qi.id] = -1; else ans[qi.id] = walls[ft.LowerBound(qi.height)][2]; } } WriteLine(string.Join("\n", ans)); } class FenwickTree { int size; long[] tree; public FenwickTree(int size) { this.size = size; tree = new long[size + 2]; } public void Add(int index, long value) { ++index; for (var x = index; x <= size; x += (x & -x)) tree[x] += value; } /// 先頭からindexまでの和(include index) public long Sum(int index) { if (index < 0) return 0; ++index; var sum = 0L; for (var x = index; x > 0; x -= (x & -x)) sum += tree[x]; return sum; } /// Sum(x) >= value となる最小のxを求める // 各要素は非負であること public int LowerBound(long value) { if (value < 0) return -1; var x = 0; var b = 1; while (b * 2 <= size) b <<= 1; for (var k = b; k > 0; k >>= 1) { if (x + k <= size && tree[x + k] < value) { value -= tree[x + k]; x += k; } } return x; } } }