hello i am writing this blog because i asked a question but havent got asnwer for it, please explain me why do we need to use segment tree to calculate sums, why cant we just use c++ operator + (read more about this operator here — https://www.w3schools.com/cpp/cpp_operators.asp)
I hope you're kidding
no i am not kidding please explain
how you became Blue??
i have used + operator
The + operator in general won't give you the sum of an array over an index range [l...r] in log(N) time. A segment tree will.
yes but + operator is O(1) while segment tree is logN, so we should use + operator, isnt it?
Because you need to apply the + operator (r — l) = O(n) times to find the sum from l to r. With a segment tree, you can do this in O(log N)
r — l = n it means that r — l — n = 0 so the complexity is O(0), right?
i am trying to solve this problem — https://mirror.codeforces.com/problemset/problem/409/H?locale=ru
but my segment tree solution fails
This problem is troll; look at the result of the submission when I use the plus operator: https://mirror.codeforces.com/contest/409/submission/70091573
Is it just me, or did the language of my codeforces suddenly change to Russian?
i think your solution has failed, because you used + operator instead of segment tree
Its big brain time!
yeah it's your time