fork download
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int main() {
  6.  
  7. // your code here
  8. int n,q;
  9. cin>>n;
  10. int a[n];
  11. for(int i=0;i<n;i++){
  12. cin>>a[i];
  13. }
  14. int h=sqrt(n)+1;
  15. int res[h];
  16. for(int i=0;i<n;i++){
  17. res[i/h]+=a[i];
  18. }
  19. int ans=INT_MAX;
  20.  
  21. cin>>q;
  22.  
  23.  
  24. while(q>0){
  25. int l,r;
  26. cin>>l>>r;
  27. int ans=INT_MAX;
  28.  
  29. for(int i=l;i<=r;){
  30. if(i%h==0 && i+h-1<=r){
  31. ans=min(ans,res[i/h]);
  32. i=i+h;
  33. }
  34. else{
  35. ans=min(ans,a[i]);
  36. i++;
  37. }
  38. }
  39. cout<<ans<<endl;
  40.  
  41. q--;
  42. }
  43.  
  44. return 0;
  45. }
Success #stdin #stdout 0.01s 5308KB
stdin
Standard input is empty
stdout
Standard output is empty