Advertisement
a53

Graffiti

a53
May 21st, 2022
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3. const int N=1e5;
  4. const int Log=17;
  5. long long S[N+1];
  6. int rmq[Log+1][N+1],lg2[N+1];
  7. int main()
  8. {
  9. int n,m,L,x,y;
  10. ifstream fin("graffiti.in");
  11. fin>>n;
  12. for(int i=1;i<=n;++i)
  13. fin>>L>>rmq[0][i],S[i]=S[i-1]+L;
  14. for(int i=2;i<=n;++i)
  15. lg2[i]=lg2[i>>1]+1;
  16. for(int i=1;i<=Log;++i)
  17. for(int j=1;j+(1<<(i-1))-1<=n;++j)
  18. rmq[i][j]=min(rmq[i-1][j],rmq[i-1][j+(1<<(i-1))]);
  19. fin>>m;
  20. ofstream fout("graffiti.out");
  21. while(m--)
  22. {
  23. fin>>x>>y;
  24. int l_lg=lg2[y-x+1];
  25. fout<<(S[y]-S[x-1])*min(rmq[l_lg][x],rmq[l_lg][y-(1<<l_lg)+1])<<'\n';
  26. }
  27. return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement