fork 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.  
  9. const int MAX = 1e5 + 55;
  10. int t, n, q, l, r;
  11. int tree[4*MAX] , a[4*MAX];
  12.  
  13. void build(int p , int st , int en){
  14. if(st == en){
  15. tree[p] = a[st];
  16. return;
  17. }
  18. int md = (st+en)>>1;
  19. build(p * 2 , st , md);
  20. build(p*2+1 , md + 1 , en);
  21. tree[p] = min(tree[p*2] , tree[p*2+1]);
  22. }
  23.  
  24. int qwr(int p , int st ,int en){
  25. if(st >= l && en <= r)
  26. return tree[p];
  27. if(st > r || en < l)
  28. return 1000000000;
  29. int md = (st+en)>>1;
  30. return min(qwr(p*2 , st , md) , qwr(p*2+1 , md + 1 , en));
  31. }
  32.  
  33. int main()
  34. {
  35. ios_base::sync_with_stdio(false);
  36. cin.tie(NULL);
  37.  
  38. //freopen("input.txt", "rt", stdin);
  39. //freopen("output.txt", "wt", stdout);
  40.  
  41. cin >> t;
  42. for (int ti=1; ti<=t; ti++)
  43. {
  44. cin >> n >> q;
  45.  
  46. for (int i=0; i<n; i++)
  47. cin >> 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. cin >> l >> 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