Service Lane
Largest vehicle that can pass through a given segment of service lane. Problem statement here.

Difficulty level: Easy

Problem Setter: Abhiranjan Kumar

Problem Tester: Shashank Sharma

Expected complexity per test case: O(r-l+1) = O(1000)
, where l = Entry index, r = exit index

Overall complexity: O(1000*100) = O(10^6)

General idea:
A vehicle can enter/exit/pass through a service lane segment if its width is not greater than that of segment. So given entry index and exit index we have to check whether the width of all service lane segments between entry and exit index, including, is greater than or equal to that of vehicle. If this is true, then that vehicle can pass through those segments otherwise not.

Approach:
Given enter and exit index, (i, j), find the maximum element, mx, in subarray Width[i..j]. All types of vehicle whose width is not greater than mx can pass through those segments, so mx will be the answer. As the length of this subarray can’t exceed 1000, we can simply traverse through this subarray to find the maximum width, mx.

Setter Solution:

#include <bits/stdc++.h>
using namespace std;

int main()
{
  int N, T;
  cin >> N >> T;

  assert(1 <= N);
  assert(N <= 100000);
  assert(1 <= T);
  assert(T <= 1000);

  vector <int> width(N);
  for(int i = 0; i < (int)N; ++i) {
    cin >> width[i];
    assert(width[i] == 1 || width[i] == 2 || width[i] == 3);
  }

  for(int i = 0; i < (int)T; ++i) {
    int l, r;
    cin >> l >> r;
    assert(0 <= l);
    assert(l < r);
    assert(r < N);
    assert(r-l+1 <= min(N, 1000));

    int ans = width[l];
    while(l <= r) {
      ans = min(ans, width[l]);
      l++;
    }
    cout << ans << "\n";
  }



  return 0;
}

Tester Solution:

in1=map(int,raw_input().split())
N=in1[0]
T=in1[1]
assert N<=100000
assert N>=1
assert T<=1000
assert T>=1
a=map(int,raw_input().split())
assert max(a)<=3 
assert min(a)>=1
for i in range(0,T):
    index=map(int,raw_input().split())
    assert index[0]>=0
    assert index[1]<N
    assert index[1]>index[0]
    print min(a[index[0]:index[1]+1])