#include using namespace std; using ll = long long; struct Mo_Algorithm{ int N, D, Q;//配列の要素数,幅,クエリ数 std::vector > query; Mo_Algorithm(int n) : N(n){} void add_query(int l,int r){ query.emplace_back(l,r); } template< typename ADD, typename DEL, typename ASK> void build(const ADD& add,const DEL& del, const ASK& ask){ Q = query.size() , D = std::max(1, int(N / sqrt(Q))); std::vector order(Q), Div(Q); for(int i = 0; i < Q; i++)Div[i] = query[i].second / D; std::iota(order.begin(), order.end(), 0); std::sort(order.begin(), order.end(), [&](int i,int j){ if(Div[i] != Div[j])return Div[i] < Div[j]; return query[i] < query[j]; }); int cl = 0, cr = 0, l,r; for(auto &&qi : order){ std::tie(l, r) = query[qi]; while(cl > l)cl--, add(cl); while(cr < r)add(cr), cr++; while(cl < l)del(cl), cl++; while(cr > r)cr--, del(cr); ask(qi); } } vector build(){ Q = query.size() , D = std::max(1, int(N / sqrt(Q))); std::vector order(Q), Div(Q); for(int i = 0; i < Q; i++)Div[i] = query[i].second / D; std::iota(order.begin(), order.end(), 0); std::sort(order.begin(), order.end(), [&](int i,int j){ if(Div[i] != Div[j])return Div[i] < Div[j]; return query[i] < query[j]; }); return order; } }; int main(){ ios::sync_with_stdio(false); cin.tie(0); int N, Q, WT, ST, L, R; cin >> N >> Q >> WT >> ST; Mo_Algorithm MA(N); vector W(N); for(auto &&v:W)cin >> v; for(int i = 0; i < Q; i++){ cin >> L >> R; MA.add_query(--L, R); } auto ans = MA.build(); for(int i = 0; i < ans.size(); i++){ cout << ++ans[i] << (i + 1 == ans.size() ? '\n' : ' '); } }