#include #include #include #include #include #include #include using namespace std; constexpr int N = 200000, Q = 200000; int WT, ST; int W[N], L[Q], R[Q]; int main(int argc, char **argv) { scanf("%*d %*d %d %d", &WT, &ST); for (int i = 0; i < N; i++) scanf(" %d", W + i); for (int i = 0; i < Q; i++) scanf(" %d %d", L + i, R + i); array a; iota(a.begin(), a.end(), 0); const int B = argc == 1 ? 550 : atoi(argv[1]); vector> buckets((N + B - 1) / B + 1); for (int i = 0; i < Q; i++) { const int b = L[i] / B; buckets[b].push_back(i); } for (int b = 0; b < buckets.size(); ++b) { vector &elems = buckets[b]; sort(elems.begin(), elems.end(), [b](int i, int j) { if (b % 2 == 0) return make_pair(R[i], L[i]) < make_pair(R[j], L[j]); else return make_pair(R[i], L[i]) > make_pair(R[j], L[j]); }); for (int i : elems) cout << i + 1 << ' '; } cout << endl; }