fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. long arr[50010],sum[50010][18],bst[50010][18],lt[50010][18],rt[50010][18];
  4. int main(){
  5. long n;
  6. scanf("%ld",&n);
  7. for(int i=0;i<n;i++){
  8. scanf("%ld",&arr[i]);
  9. }
  10. for(int i=0;i<n;i++){
  11. sum[i][0]=arr[i];
  12. bst[i][0]=arr[i];
  13. lt[i][0]=arr[i];
  14. rt[i][0]=arr[i];
  15. }
  16. for(int i=0;i<n;i++){
  17. for(int j=1;i+(1<<(j))-1<n;j++){
  18. lt[i][j]=max(lt[i][j-1],sum[i][j-1]+lt[i+ 1<<(j-1) ][j-1]);
  19. rt[i][j]=max(rt[i][j-1]+sum[i+ 1<<(j-1)][j-1],rt[i+ 1<<(j-1)][j-1]);
  20. sum[i][j]=sum[i+ 1<<(j-1)][j-1]+sum[i][j-1];
  21. bst[i][j]=max(max(bst[i][j-1],bst[i+ 1<<(j-1)][j-1]),rt[i][j-1]+lt[i+ 1<<(j-1)][j-1]);
  22. }
  23. }
  24. long q,x,y,z;
  25. scanf("%ld",&q);
  26.  
  27. while(q--){
  28. scanf("%ld %ld",&x,&y);
  29. //We can calculate the binary representation of (y-x) and calculate the answer
  30. }
  31. return 0;
  32. }
  33.  
Time limit exceeded #stdin #stdout 5s 17560KB
stdin
Standard input is empty
stdout
Standard output is empty