Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- int main() {
- std::ios::sync_with_stdio(false);
- std::cin.tie(0);
- std::cout.tie(0);
- int num;
- std::cin >> num;
- std::vector<int> ar(num);
- for (int& id : ar) {
- std::cin >> id;
- }
- std::vector<int> pref(num);
- std::vector<int> suf(num);
- pref[0] = ar[0];
- for (int id = 1; id < num; ++id) {
- pref[id] = std::min(pref[id - 1], ar[id]);
- }
- suf[num - 1] = ar[num - 1];
- for (int id = num - 2; id >= 0; --id) {
- suf[id] = std::min(suf[id + 1], ar[id]);
- }
- int qu;
- // go
- std::cin >> qu;
- for (int id = 0; id < qu; ++id) {
- int li;
- int ri;
- std::cin >> li >> ri;
- li--;
- ri--;
- int ans = std::min(pref[li], suf[ri]);
- std::cout << ans << "\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement