Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- const int k = 16;
- const int N = 1e5;
- const int ZERO = 1e9 + 1;
- int table[N][k + 1];
- int Arr[N];
- int main()
- {
- int t,cnt=1;
- cin>>t;
- while(t--)
- {
- int n, L, R, q;
- scanf("%d%d",&n,&q);
- for(int i = 0; i < n; i++)
- scanf("%d",&Arr[i]);
- for(int i = 0; i < n; i++)
- table[i][0] = Arr[i];
- for(int j = 1; j <= k; j++)
- {
- for(int i = 0; i <= n - (1 << j); i++)
- table[i][j] = min(table[i][j - 1], table[i + (1 << (j - 1))][j - 1]);
- }
- printf("Case %d:\n",cnt++);
- for(int i = 0; i < q; i++)
- {
- scanf("%d%d",&L,&R);
- L--,R--;
- int answer = ZERO;
- for(int j = k; j >= 0; j--)
- {
- if(L + (1 << j) - 1 <= R)
- {
- answer = min(answer, table[L][j]);
- L += 1 << j;
- }
- }
- cout << answer << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment