Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.001 s | 0 KBi |
#2 |
Correcto
|
0.002 s | 0 KBi |
#3 |
Correcto
|
0.003 s | 0 KBi |
#4 |
Correcto
|
0.004 s | 1 KBi |
#5 |
Correcto
|
0.001 s | 0 KBi |
#6 |
Correcto
|
0.001 s | 0 KBi |
#7 |
Correcto
|
0.008 s | 0 KBi |
#8 |
Correcto
|
0.005 s | 1 KBi |
#9 |
Correcto
|
0.002 s | 0 KBi |
#10 |
Correcto
|
0.007 s | 2 KBi |
#11 |
Correcto
|
0.23 s | 5 KBi |
#12 |
Correcto
|
0.092 s | 4 KBi |
#13 |
Correcto
|
0.241 s | 6 KBi |
#14 |
Correcto
|
0.076 s | 4 KBi |
#15 |
Correcto
|
0.065 s | 4 KBi |
#include <bits/stdc++.h> using namespace std; void _print() { cerr << "]" << endl; } template<typename T, typename... V> void _print(T t, V... v) { cerr << t; if (sizeof...(v)) cerr << ", "; _print(v...); } #ifdef LOCAL #define dbg(x...) cerr << "[" << #x << "]: ["; _print(x) #else #define dbg(x...) #define endl '\n' #endif #define ll long long #define sz(x) int(x.size()) struct SegmentTree { vector<pair<int, int>> st; int n; SegmentTree(const vector<int> &arr) { n = sz(arr); st.assign(n << 2, {0, 0}); build(arr, 1, 0, n - 1); } int left(int v) { return v << 1; } int right(int v) { return (v << 1) | 1; } pair<int, int> operation(pair<int, int> a, pair<int, int> b) { if (a.first >= b.first) return a; return b; } void build(const vector<int> &arr, int v, int tl, int tr) { if (tl == tr) { st[v] = {arr[tl], tl}; } else { int tm = (tl + tr) >> 1; build(arr, left(v), tl, tm); build(arr, right(v), tm + 1, tr); st[v] = operation(st[left(v)], st[right(v)]); } } pair<int, int> query(int v, int tl, int tr, int l, int r) { if (l > r) return {INT_MIN, -1}; // Nuetro if (l == tl && r == tr) return st[v]; int tm = (tl + tr) >> 1; return operation(query(left(v), tl, tm, l, min(r, tm)), query(right(v), tm + 1, tr, max(l, tm + 1), r)); } pair<int, int> query(int l, int r) { return query(1, 0, n - 1, l, r); } }; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> vi(n); for (int &i : vi) cin >> i; SegmentTree st(vi); int q; cin >> q; while (q--) { int l, r; cin >> l >> r; cout << st.query(l, r).second << endl; } return 0; }