fork(1) download
  1. //
  2. // Light Oj - 1082 - Array Queries
  3. // too lazy to RTE :(
  4.  
  5.  
  6. #include <bits/stdc++.h>
  7. using namespace std;
  8. #define sc(a) scanf("%d" , &a)
  9.  
  10. const int MAX = 1e5 + 55;
  11. int t, n, q, l, r;
  12. int tree[4*MAX] , a[4*MAX];
  13.  
  14. void build(int p , int st , int en){
  15. if(st == en){
  16. tree[p] = a[st];
  17. return;
  18. }
  19. int md = (st+en)>>1;
  20. build(p * 2 , st , md);
  21. build(p*2+1 , md + 1 , en);
  22. tree[p] = min(tree[p*2] , tree[p*2+1]);
  23. }
  24.  
  25. int qwr(int p , int st ,int en){
  26. if(st >= l && en <= r)
  27. return tree[p];
  28. if(st > r || en < l)
  29. return 1000000000;
  30. int md = (st+en)>>1;
  31. return min(qwr(p*2 , st , md) , qwr(p*2+1 , md + 1 , en));
  32. }
  33.  
  34. int main()
  35. {
  36.  
  37.  
  38. //freopen("input.txt", "rt", stdin);
  39. //freopen("output.txt", "wt", stdout);
  40.  
  41. sc(t);
  42. for (int ti=1; ti<=t; ti++)
  43. {
  44. sc(n);sc(q);
  45.  
  46. for (int i=0; i<n; i++)
  47. sc(a[i]);
  48.  
  49. build(1 , 0 , n - 1);
  50.  
  51. cout << "Case " << ti << ":\n";
  52. for (int i=0; i<q; i++)
  53. {
  54. sc(l);sc(r);
  55. --l;--r;
  56. cout << qwr (1 , 0 , n - 1) << "\n";
  57. }
  58. }
  59.  
  60. return 0;
  61. }
Success #stdin #stdout 0s 18360KB
stdin
Standard input is empty
stdout
Standard output is empty