Scanline Algorithm | Codeforces Round 636 | Constant Palindrome Sum | I say it prefix trick

Поделиться
HTML-код
  • Опубликовано: 21 янв 2025

Комментарии • 127

  • @mayankchaudhary5515
    @mayankchaudhary5515 4 года назад +42

    After the contest, I was looking into other solutions but really I didn't get it anything and now I was waiting for the editorial and to my surprise, you made a video with a clear explanation to it. Thanks, bro keep making videos on C and D codeforces problems. it really helps a lot.

  • @ganeshchowdhary3024
    @ganeshchowdhary3024 4 года назад +9

    In brief:
    Standard algo to be known : Prefix trick : For finding zero and one change required pairs
    some adhoc thinking : Using map for finding zero changing pairs (this is awesome)
    Remainging is two changing pairs
    Thanks buddy! Awesome thinking! Hope i get these kind of thoughts on one kind. Until then practice, participate, Don't lose the adrenaline rush and don't lose hope.

  • @atishayjain1423
    @atishayjain1423 4 года назад +16

    Thanks man I wasn't able to get it by my own after checking so many solutions but after watching your video now I understand the logic thank you
    Thanks for helping beginners programmes

  • @piyushgoyal6298
    @piyushgoyal6298 4 года назад +4

    One of the best Recommendation RUclips has ever gave me. Thanks bro for such beautiful content. Keep making such videos :)

  • @prachij
    @prachij 4 года назад +5

    Even after struggling for 1.5hr, was unable to solve it. Thank you for the video. Great explanation!!

  • @aishwaryaramesh4877
    @aishwaryaramesh4877 4 года назад +2

    Thanks a ton for the explanation, I couldn't understand the tutorial and was searching for clarity in the comments when I came across your link to your explanation!

  • @tryingtobecometourist2477
    @tryingtobecometourist2477 4 года назад +2

    I JUST WANTED TO SAY THAT PLEASE DONT STOP THIS GOOD WORK because i started the same but stopped... I HOPE YOU WILL KEEP GOING as it really helps

  • @dineshkumar-kz3nc
    @dineshkumar-kz3nc 4 года назад +2

    From the beginning part of my journey at cp I want to upsolve problems and for beginners problem c and problem d is not such easy to understand by editorial in short time but this videos really helped me to understand this easily. KEEP GOING ON BUDDY BE LIKE THAT FOR EVERY PROBLEM OF CODEFORCES

  • @allmighty2000
    @allmighty2000 4 года назад +1

    the basic query problem that u solved using prefix sum , i am known to that method already , i solved a problem in GFG array section using this , the question was " you will be given some ranges and you have to print the most repeated element with in the range " ,
    i almost solved the question with basic prefix sum concept , i mean i guessed it will be like this but i was all the time putting the negative values ( that help us to indicate wheres it ending ) to the upper limit index rather than the next element to the range's upper limit,
    BUT this question was beyond my reach , though i am having only 2 months into serious programming still it hurts when you cant find the solution on your own :(

  • @ajmal2168
    @ajmal2168 3 года назад

    I had no idea about this prefix table, once I understood the logic from your explanation, i solved it easily

  • @theone1064
    @theone1064 3 года назад +2

    if only i was not a student I would have applauded.Nice Explanation my friend

    • @takeUforward
      @takeUforward  3 года назад

      No issues man. You commented, thats more than enough :)

  • @BEEMohdArbazAli
    @BEEMohdArbazAli 2 года назад

    Participated in virtual content and couldn't solve it, i dind't understood editorial and other's solution, then found your editorial and before watching it i was like " striver bhayya ne editorial banaya hai to samajh a hi jayga" and guess what ,at 11 min i paused the video and coded the solution and ACed. Also today i learned a new technique of prefix . Thank you bhayya.

  • @amitranjan2854
    @amitranjan2854 4 года назад +1

    Really a very nice explaination. For the prefix trick I used to do it with BIT. I thought of this trick earlier but didn't use earlier. But thanks to you now I have two techniques.😄

    • @takeUforward
      @takeUforward  4 года назад

      Yeah BIT is better if it had updates, but here we have no updates.

  • @satyamkumar2820
    @satyamkumar2820 4 года назад +2

    Thanks for such a wonderful explanation. finally I understood the solution of this problem. Thanks for your effort.

  • @ritikagupta8847
    @ritikagupta8847 4 года назад

    Thanks for the video. Making one video on one topic explaining it thoroughly is what I like the most.

  • @noobcoder6773
    @noobcoder6773 4 года назад +1

    Thanks a lot brother. I understood every part of the solution. Before your solution I was searching different solutions but understood nothing. Thanks a lot😃😃

  • @wolfgalax8204
    @wolfgalax8204 4 года назад

    Nice video, and explaining the underlying algorithm separately is a good way to understand problem. Great !!

  • @PritamKumar-mr5dv
    @PritamKumar-mr5dv 3 года назад

    I doing the cp list I understand the algo but can't get sol , so watched this video 4 times and I finally get its best use of scanline algo.thnks bhaiya

  • @shrinathbhoslay3014
    @shrinathbhoslay3014 4 года назад

    Thank you so much. I finally understood it. Keep making solution videos for newbies like me.

  • @gauravtripathi9456
    @gauravtripathi9456 4 года назад

    thanks, man for such an explanatory video keep making cf c & d problems vides, It helps a lot.

  • @dhananjaysonawane1996
    @dhananjaysonawane1996 4 года назад

    Good explanation. Your write clean code, makes understanding the stuff easier. Thanks :)

  • @RudraSingh-pb5ls
    @RudraSingh-pb5ls 4 года назад

    Suppose I had an array { 3, 4, 5, 6} (non zero based indexing here)
    And I have two queries
    Q1 : from 1 to 3rd index add -1
    Q2 : from 2 to 3rd index add 2
    And then in the end tell the sum of array elements between index 2 and 4 (1 and 4 are inclusive).
    In this thing I am not able to use scanline algorithm

  • @2018-s7y
    @2018-s7y 4 года назад

    Best explanation friend thanks for making such quality content. Understood every part of it and thanks for explaining also the underlying algos behind the problem. You are really the best.

  • @joaopedrosa2246
    @joaopedrosa2246 4 года назад

    Great tutorial! Thanks for providing good quality content!

  • @bittu100bhar4
    @bittu100bhar4 4 года назад +2

    Please go on making codeforces rounds video tutorials....it helps a lot

  • @shivamojha7999
    @shivamojha7999 4 года назад +1

    Thank u so much!! Keep uploading solution videos of Div.3 and Div.2

  • @navinsingh7539
    @navinsingh7539 4 года назад +1

    really awesome explanation!!!!
    keep it up bro.

  • @basharhamadah8073
    @basharhamadah8073 4 года назад

    good explanation it helps too much ...keep making videos ❤

  • @jaydippansuriya5003
    @jaydippansuriya5003 4 года назад +2

    Thank you So much ! Please keep it up it is very helpful.

  • @harshitpandey1698
    @harshitpandey1698 4 года назад

    Great use of prefix sum..and nicely expained !

  • @pawankholiya6150
    @pawankholiya6150 4 года назад +1

    I'm bit confused which part of the solution uses exactly Scanline Algorithm Directly or Indirectly

    • @takeUforward
      @takeUforward  4 года назад +3

      When you are building the prefix array, from the ranges L, R for every pair. The prefix trick is the scanline algo.

  • @ganuking5977
    @ganuking5977 4 года назад +1

    Thanks for the great video, can you suggest on how to solve problems in cf contets quickly?

    • @takeUforward
      @takeUforward  4 года назад +1

      Practice, do as many problems u can in a day that really helps.

  • @gopikrishna1551
    @gopikrishna1551 4 года назад

    AWESOME EXPLANATION
    keep doing more videos bro :)

  • @mukulbindal2303
    @mukulbindal2303 4 года назад +22

    Struggled for 1.5 hour yesterday 😂😂😂😂

  • @TheNayanava
    @TheNayanava 4 года назад

    This is sheer brilliance man, but I want to understand if there isn't a way to solve it using binary search? if yes can you leave a tip?

  • @RAMSINGH-kt3wk
    @RAMSINGH-kt3wk 4 года назад

    i watch your video it is best, your way of explanation is best ,if possible kindly try to give solution of some practice problem of dp,graph of medium level difficulty c,d,e

  • @ankitmittal9396
    @ankitmittal9396 4 года назад

    great tutorial man! hope to see some more of them. cheers!

  • @PANKAJSharma-he4gg
    @PANKAJSharma-he4gg 4 года назад +1

    Thanks for this really simple and clear explanation . great efforts.
    CAN YOU PLEASE TELL ME WHICH IDE YOU ARE USING??

  • @daniel.w8112
    @daniel.w8112 2 года назад

    That was very clear Thanks Man

  • @nikhilmehra845
    @nikhilmehra845 4 года назад

    int l = it.fi + 1;
    int r = it.se + k;
    why u have added it.f1+1 && se+k ??
    not getting bro how u maintained prefix array in the solution .

  • @karthik5369
    @karthik5369 4 года назад

    simply superb bro very nice explanation.

  • @prateeksinghal630
    @prateeksinghal630 4 года назад +1

    This algorithm is brilliant!!

  • @deveshjha5141
    @deveshjha5141 4 года назад

    Out of context question, but which digital pen you use for writing/drawing on pc? anyway great video learned new algo.

  • @RoshanKumar-nx6rk
    @RoshanKumar-nx6rk 4 года назад +1

    Can you please help? What is prefix sum trick and how will we make prefix table in O(n). Shouldn't be it O(n.k)?Please help!

    • @takeUforward
      @takeUforward  4 года назад

      Initially I have made it, you can have a check in the code link in the description.

  • @keshavgupta605
    @keshavgupta605 4 года назад +1

    How to start with programming and the sources for learning?

    • @takeUforward
      @takeUforward  4 года назад +3

      Learn basic programming with loops and stuffs, keep learning Data Structures, different Algorithms starting from basic one. Keep solving problems related to those algorithms once u have learned the Algo. Try to participate at every contest at Codeforces, after the contest try to do the first two questions that you could not do. To improve in CF, practice questions from a2oj static ladder.

  • @RudraSingh-pb5ls
    @RudraSingh-pb5ls 4 года назад

    Striver can you give some place where I can find this scan line trick ?

  • @rbiswas876
    @rbiswas876 4 года назад

    great explanation. Really helped.

  • @amanraj3646
    @amanraj3646 4 года назад +3

    Keep making videos buddy , you are just improving my threshold point thanks 👍👍

  • @kushagra4401
    @kushagra4401 3 года назад +1

    thank you for this video too!!

  • @darshantak5872
    @darshantak5872 4 года назад

    Sir , What will be the use of hash table as from the prefix array we will get the total possibilities ?

    • @takeUforward
      @takeUforward  4 года назад

      Prefix table gives u which pairs are having 0/1 changes, so you to know the pairs which gives 1 changes, you have to subtract them. Hence table can say it directly how many needs to be subtracted.

    • @darshantak5872
      @darshantak5872 4 года назад

      @@takeUforward yes yes i got it. Thanks very much.

    • @darshantak5872
      @darshantak5872 4 года назад

      @@takeUforward sir i saw your profile on CF like initially you have given every contest. I wanted to ask that after giving the contest do you review the problems again ? And if so you just look at the soln or try it.? And how many questions do you tend to review after contest overs.
      I hope you will reply

  • @1234sat
    @1234sat 4 года назад +1

    bro nice explanation.pls keep posting

  • @sahilsharma2952
    @sahilsharma2952 4 года назад

    Read about "Difference Arrays" to understand this better.

  • @travelinGuitarist
    @travelinGuitarist 4 года назад +3

    great explaination 😍

  • @yashhiran8485
    @yashhiran8485 4 года назад

    How do manage the problem of infinite loop or recursion in your sublime text as the pc may stop working which is not afforadable during a live contest

    • @ganuking5977
      @ganuking5977 4 года назад

      Use a different editor, like Dev C++ and are you on Windows or Linux?
      Because in my case it just gives an error and force closes the executable file

    • @takeUforward
      @takeUforward  4 года назад

      I am posting a video about using sublime text for cp in 10 minutes.

  • @shagunlamba6481
    @shagunlamba6481 4 года назад

    very well explained bro, thank you !

  • @swapno2k
    @swapno2k 4 года назад

    whhy at prefix sum there is +10 in forloop??

  • @bhaskarashoktripathi3791
    @bhaskarashoktripathi3791 4 года назад

    great explanation!!!

  • @raysk4798
    @raysk4798 3 года назад

    Thank you bro for the good explanation

  • @madhupatel4484
    @madhupatel4484 4 года назад +1

    Bro in second last for loop you have used 2*k+10 but I think it should2*k+1

    • @takeUforward
      @takeUforward  4 года назад

      Yeah usually I do it for safety during the contest.

    • @nikhilmehra845
      @nikhilmehra845 4 года назад

      @@takeUforward what kind of safety bro, i think 2*k+1 will work fine for every testcase.

  • @NadeemShaikh-ot8yl
    @NadeemShaikh-ot8yl 4 года назад

    Nice Explanation!!

  • @adityakajale4403
    @adityakajale4403 3 года назад

    Nice explanation :)

  • @mahendrabishnoi
    @mahendrabishnoi 4 года назад

    Nice explanation brother :)

  • @farazanwar4624
    @farazanwar4624 3 года назад

    🎶🎶 kitni dafaa striver tune mera kaam aasan kia hai 🎶🎶

  • @rajgothi2633
    @rajgothi2633 4 года назад

    Great Explanation Bro..Thank you very much for this link of video highlighted in Codeforce's comment section....

    • @takeUforward
      @takeUforward  4 года назад

      Thanks, please leave a comment in the CF section if possible, helps people to know that this a genuine link.

  • @simdmklover6271
    @simdmklover6271 4 года назад

    Best video editorials in the west

  • @mozammalhossain968
    @mozammalhossain968 4 года назад

    How you've chosen only 3 values of x?

  • @tushartyagi7554
    @tushartyagi7554 4 года назад +1

    love you brother...nicely explained...

  • @shashikant123kadam
    @shashikant123kadam 4 года назад

    awesome video! thank you so much

  • @xiquandong1183
    @xiquandong1183 4 года назад

    Can you add explanation for problem F? Thanks.

    • @takeUforward
      @takeUforward  4 года назад

      Yeah once I am free, am really buzy with my internship, hence I do post videos during the night only.

    • @xiquandong1183
      @xiquandong1183 4 года назад

      @@takeUforward No problem, I finally understood the solution and was able to code it on my own. Thanks for your help.

  • @justworkfine321
    @justworkfine321 3 года назад

    Discord link?

  • @rohithpothula6050
    @rohithpothula6050 4 года назад

    thanks a for great explanation

  • @shuvbhowmickbestin
    @shuvbhowmickbestin 3 года назад

    someone please explain what is for0()

  • @sourabhsingh3209
    @sourabhsingh3209 4 года назад

    good job man...thanks

  • @voiceoftech6703
    @voiceoftech6703 4 года назад

    really helpful video

  • @user32132x
    @user32132x 4 года назад

    Thanks, a lot bro you are the best

  • @drishyapremchandani6438
    @drishyapremchandani6438 4 года назад

    Really loved the explanation !! I am on 1500 right now, can you guide me on how to improve?

  • @haltsimog
    @haltsimog 4 года назад

    Very didactic. Thanks!

  • @kermitthealmighty8355
    @kermitthealmighty8355 4 года назад

    I wanted to be expert this contest, but instead got a negative 50 delta. Please tell me how I can improve my speed coding abilities. I took 30 minutes to code only problem C!

  • @yashpreetbathla4653
    @yashpreetbathla4653 4 года назад

    WOw really really nice explanation brother :)

  • @j.shreyansh
    @j.shreyansh 4 года назад

    This will not work for the test case
    1
    4 2
    1 2 1 2
    map=[0, 2, 2, 2]
    hash={3:2}

    • @j.shreyansh
      @j.shreyansh 4 года назад

      This is the code i wrote, i may be wrong too, please correct me
      t=int(input())
      for _ in range(t):
      n,b=map(int,input().split())
      arr=list(map(int,input().split()))
      ans=float("inf")
      m={}
      pairs=int(n/2)
      ind=[0]*((2*b)+1)
      for i in range(1,int(n/2)+1):
      if arr[i-1]+arr[-i] in m:
      m[arr[i-1]+arr[-i]]+=1
      else:
      m[arr[i-1]+arr[-i]]=1
      for i in range(1,int(n/2)+1):
      ind[min(arr[i-1],arr[-i])+1]+=1
      if max(arr[i-1],arr[-i])+b+1

    • @takeUforward
      @takeUforward  4 года назад

      This works bro, the answer is 0, which the code gives. If you take x = 3, so 0 changes are 2 pairs, 1 changes are 0 pairs, 2 changes are 0, hence total pairs left to be changed is 0, hence count is 0*2 = 0 changes.

    • @takeUforward
      @takeUforward  4 года назад

      @@j.shreyansh am really bad at debugging a code of a language am not familiar to. I have the code link in the description, please compare to it, by using print statements. Try putting print and check if your values and my code values are coming same or not. In this way you can figure it out.

  • @scoopedcontent
    @scoopedcontent 4 года назад

    Beautiful problem

  • @jagrit07
    @jagrit07 4 года назад

    Nailed it.

  • @notanchowdhury3543
    @notanchowdhury3543 4 года назад

    thanks, man!

  • @jllnnnl
    @jllnnnl 4 года назад

    nicely done

  • @nazmulhossainnahid7061
    @nazmulhossainnahid7061 4 года назад

    keep it up ... good one

  • @Foodie_and_moodie
    @Foodie_and_moodie 3 года назад

    2:00

  • @rkhamim4574
    @rkhamim4574 4 года назад

    Nice explanation. Thanks.

  • @abhijitburman1260
    @abhijitburman1260 4 года назад +1

    Great explanation Bhaiya.

  • @vanshajsingh6314
    @vanshajsingh6314 4 года назад

    Cool!!

  • @showdownx8276
    @showdownx8276 6 месяцев назад

    Mera dimag kamjor hai ki ye question tough hai