Тёмный

Segment Tree (Implementation) 

Errichto Hard Algorithms
Подписаться 46 тыс.
Просмотров 34 тыс.
50% 1

Опубликовано:

 

8 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 49   
@goblin1390
@goblin1390 3 года назад
To be honest Segment tree was a nightmare until now. Thanks for very easy and nice explanation.
@vishnusingh4118
@vishnusingh4118 3 года назад
What a way to start the morning. For once I dont mind early morning RU-vid notifications. I literally watched the whole thing in 1 go before I could even get off the bed. Time to implement after breakfast. Thanks a ton for the amazing content Errichto!
@mystic3549
@mystic3549 9 месяцев назад
there is a whole different vibe studying from you :) honestly....so grateful for people like you who contribute sm to the community after acing a particular skill... _/\_ orz SIR
@shivamgupta917
@shivamgupta917 3 года назад
Thank you, sir. I watched your binary search lecture, now I am able to solve difficult binary search problems. Today I finished your segment tree lecture. I hope I can solve query problems now.
@ahmmedsakibnoman2849
@ahmmedsakibnoman2849 3 года назад
I can't thank you enough.. was looking for segment tree from you for a log time. ❤❤
@mystic3549
@mystic3549 9 месяцев назад
and like everything feels so concrete after you claim a thing :) with other teachers there is still a 1% of doubt left in mind if they claim something which is not that easily acceptable even if its correct..but when you claim something, my mind refuses any intent of not believing it automatically and can so easily accept and trust you
@padhai_karle_bhai
@padhai_karle_bhai 3 месяца назад
you made it so easy for me
@josephwong2832
@josephwong2832 3 года назад
great way to understand and visualize O(logN) time concept in general. Thanks errichto!
@AdityaKumar-be7hx
@AdityaKumar-be7hx 3 месяца назад
Ah! Should have seen this video first. Learned Fenwick tree first and then this one. Could have avoided it. Nevertheless, no knowledge is ever wasted :) Thanks for the great explanation!
@Faby__
@Faby__ Год назад
perfect explanation. thanks!
@yessinejallouli7785
@yessinejallouli7785 3 года назад
I can watch you the whole day without being bored. Thanks a lot 😁
@iprakhar22
@iprakhar22 3 года назад
You look exactly like the european basketball player Nikola Jokic! He is very famous these days.
@BGOPC
@BGOPC 8 месяцев назад
Man I miss this guy, wish he restarts
@sunnyrawat931
@sunnyrawat931 Год назад
Very nice explanation
@Rubiks892
@Rubiks892 Год назад
What is the point of "padding vector a with 0s?
@ananyapamde4514
@ananyapamde4514 2 года назад
May god bless you
@UltraKillpc
@UltraKillpc 7 месяцев назад
I finished all 3 b2back, binary lifting, rmq and segment trees, i feel powdered
@animeshgupta812
@animeshgupta812 Год назад
Thanks :) Learnt a lot!
@mohammedsamir5142
@mohammedsamir5142 2 года назад
A new fan is here
@ankitkumar-jo2cz
@ankitkumar-jo2cz 3 года назад
Can you also talk about link cut trees (comparison using splay and treaps) like you compared segment and fenwick tree uses.
@HimanshuSingh-jq7yg
@HimanshuSingh-jq7yg 7 месяцев назад
Awesome!!
@anandverma2083
@anandverma2083 3 года назад
hi errichto can you show how we can count different prime nums in a query or count of all prime nums in a query. Is persistent datastructure required in such cases
@nikhilgautam2857
@nikhilgautam2857 3 года назад
There is one way pashka does in ITMO lecture what would you prefer ?
@sunnykumarsingh7039
@sunnykumarsingh7039 2 года назад
This is gold!❤️
@TomerBenDavid
@TomerBenDavid 3 года назад
Which keyboard do a master like you use?
@chenguanghe6074
@chenguanghe6074 3 года назад
using sqrt decomposition has the same time/sapce complexity?
@thetester8371
@thetester8371 3 года назад
Its complexity is a lot worse - sqrt(n) vs log (n). However , it is very useful in some problems. There are lot of problems where writing a segment tree solution is a lot more complex.
@josejuansuarezelizalde4600
@josejuansuarezelizalde4600 Год назад
I came here in ordered to see why some implementations does tree.resize(4 * n) but he just did tree.resize(2*n) (which makes sense for me) I don't get why 4*n
@CarrotCakeMake
@CarrotCakeMake Год назад
The 4*n ones are probably doing both range updates and range queries which requires extra space to store both the sum and the overriding update value, I guess.
@vado4003
@vado4003 Год назад
How does this account for uneven trees?
@swb6843
@swb6843 3 года назад
I've struggled with problems of unique element query(find number of unique elements in [l, r]). Probably the only type of range query that can't be done with segtree. or can it be done? tried with a vector of sets but its too slow
@ankitkumar-jo2cz
@ankitkumar-jo2cz 3 года назад
If the array has no updates it can be simply done using a simple segment tree(just store the pos of next duplicate in the current node of segment tree)
@nikhilkumarmishra4994
@nikhilkumarmishra4994 3 года назад
Can be done with Mo's algo
@mathewtjosejose327
@mathewtjosejose327 3 года назад
Hi Errichto, Thanks for the content..it's really helpful. At 32:51 at line number 45 , the function is calling with attributes 0, n-1. It should be 0, 2*n-1 right?. As n is 8 in the example . Or am I missing something?..
@vedangdanej
@vedangdanej 3 года назад
It should be 0, n-1. The first argument (node) represents the sum of the elements form node_low to node_high (both inclusive) . So, the root node (1) will have the sum of elements form 0 to n-1 i.e the total sum of all the array elements.
@codecspy3479
@codecspy3479 3 года назад
Can you come up with 2D segment tree implementation as well ??
@m.e.t.a.l3125
@m.e.t.a.l3125 9 месяцев назад
my name is patrick bateman
@arafathhossain5612
@arafathhossain5612 2 года назад
can't find the code in github
@KaranDoshicool
@KaranDoshicool 3 года назад
Can i get link to the segtree code?
@anonymoussloth6687
@anonymoussloth6687 3 года назад
Hey. Do you have the code?
@primerevan8403
@primerevan8403 3 года назад
You will learn I will teach :) xd
@slayers2966
@slayers2966 Год назад
Ur code will fail if u will be asked to update some node to -1.
@nihalk9069
@nihalk9069 3 года назад
Errichto add this to Edu
@alisaquibraza6870
@alisaquibraza6870 2 года назад
can anyone leave the code in comments ? thanks...
@geiogeio6726
@geiogeio6726 3 года назад
There is contest going on codingame
@codecorn8030
@codecorn8030 Год назад
#include using namespace std; #define int long long vector segment_tree; void BuildSegmentTree (vector&a) { int n =a.size(); while(__builtin_popcountll(n)!=1) { a.push_back(0); n++; } segment_tree.resize(2*n); for(int i=0;i=1;--i) segment_tree[i]= segment_tree[2*i] + segment_tree[2*i+1] ; } void update(int pos ,int val,int n) { segment_tree[pos+n]=val; for(int i=(pos+n)/2; i>=1; i/=2) segment_tree[i]= segment_tree[2*i] + segment_tree[2*i+1] ; } int query(int node, int l,int r,int nodel, int noder) { if(noderr) return 0; if(ln>>t; vector a(n); for(int i=0;i>a[i]; BuildSegmentTree(a); n = a.size(); while(t--) { int a1,a2,a3;cin>>a1>>a2>>a3; if(a1==1){ a2--; update(a2,a3,n); } else cout
@tuhinmukherjee8141
@tuhinmukherjee8141 3 года назад
Am I the only one who thinks that Errichto speaks lile Borat?
@vaalarivan_p
@vaalarivan_p Год назад
8:00
@ahmadbodayr7203
@ahmadbodayr7203 8 месяцев назад
read about islam man❤
Далее
Square Root Decomposition, Mo's Algorithm
1:29:36
Просмотров 29 тыс.
The hidden beauty of the A* algorithm
19:22
Просмотров 867 тыс.
Codeforces Edu 142 (Div. 2) live coding
1:21:06
Просмотров 12 тыс.
[Hard] Square Root Decomposition - Homework
1:13:50
Просмотров 6 тыс.
Enter The Arena: Simplifying Memory Management (2023)
1:47:50
Codeforces 844 (Div. 1+2), Tourist's Round
2:19:44
Просмотров 14 тыс.
Sparse Table & RMQ (Range Minimum Query)
18:42
Просмотров 76 тыс.
Google Hash Code 2022 Quals Upsolving
1:12:30
Просмотров 8 тыс.