Advertisement
Korotkodul

1A_v1

Sep 27th, 2023 (edited)
820
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. int main() {
  5.   std::ios::sync_with_stdio(false);
  6.   std::cin.tie(0);
  7.   std::cout.tie(0);
  8.   int num;
  9.   std::cin >> num;
  10.   std::vector<int> ar(num);
  11.   for (int& id : ar) {
  12.     std::cin >> id;
  13.   }
  14.   std::vector<int> pref(num);
  15.   std::vector<int> suf(num);
  16.   pref[0] = ar[0];
  17.   for (int id = 1; id < num; ++id) {
  18.     pref[id] = std::min(pref[id - 1], ar[id]);
  19.   }
  20.   suf[num - 1] = ar[num - 1];
  21.   for (int id = num - 2; id >= 0; --id) {
  22.     suf[id] = std::min(suf[id + 1], ar[id]);
  23.   }
  24.   int qu;
  25.   // go
  26.   std::cin >> qu;
  27.   for (int id = 0; id < qu; ++id) {
  28.     int li;
  29.     int ri;
  30.     std::cin >> li >> ri;
  31.     li--;
  32.     ri--;
  33.     int ans = std::min(pref[li], suf[ri]);
  34.     std::cout << ans << "\n";
  35.   }
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement