SlideShare a Scribd company logo
Aim and Clarications
             Common Problems
              Parsing a problem
      Standard Template Library
                  Using Bitwise
                       Problems




           Introductory Lecture
Topics: basics, resources, stl, bitwise tricks

                ve—gue of €rogr—mmers

                       ACA, IIT Kanpur




                     y™to˜er PID PHIP




        League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                        Common Problems
                         Parsing a problem
                 Standard Template Library
                             Using Bitwise
                                  Problems

Outline

  1   eim —nd gl—ri(™—tions

  2   gommon €ro˜lems

  3   €—rsing — pro˜lem

  4   ƒt—nd—rd „empl—te vi˜r—ry

  5   …sing fitwise

  6   €ro˜lems


                      League of Programmers   Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                      Common Problems
                       Parsing a problem
               Standard Template Library
                           Using Bitwise
                                Problems

Aim

      his™ussion ™—mp not — le™ture seriesF ‰ou need to show
      motiv—tionF




                 League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                      Common Problems
                       Parsing a problem
               Standard Template Library
                           Using Bitwise
                                Problems

Aim

      his™ussion ™—mp not — le™ture seriesF ‰ou need to show
      motiv—tionF
      „o help you introdu™e to the world of —lgorithms —nd
      ™ompetitive progr—mming




                 League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                      Common Problems
                       Parsing a problem
               Standard Template Library
                           Using Bitwise
                                Problems

Aim

      his™ussion ™—mp not — le™ture seriesF ‰ou need to show
      motiv—tionF
      „o help you introdu™e to the world of —lgorithms —nd
      ™ompetitive progr—mming
      w—ny useful —lgorithmsD m—them—ti™—l insights




                 League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                      Common Problems
                       Parsing a problem
               Standard Template Library
                           Using Bitwise
                                Problems

Aim

      his™ussion ™—mp not — le™ture seriesF ‰ou need to show
      motiv—tionF
      „o help you introdu™e to the world of —lgorithms —nd
      ™ompetitive progr—mming
      w—ny useful —lgorithmsD m—them—ti™—l insights
      …seful for —ny progr—mming ™ontest th—t you m—y en™ounter




                 League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                       Common Problems
                        Parsing a problem
                Standard Template Library
                            Using Bitwise
                                 Problems

Aim

      his™ussion ™—mp not — le™ture seriesF ‰ou need to show
      motiv—tionF
      „o help you introdu™e to the world of —lgorithms —nd
      ™ompetitive progr—mming
      w—ny useful —lgorithmsD m—them—ti™—l insights
      …seful for —ny progr—mming ™ontest th—t you m—y en™ounter
      efter this you ™—n ro™k in jo˜Ginternship interviews




                  League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                       Common Problems
                        Parsing a problem
                Standard Template Library
                            Using Bitwise
                                 Problems

Aim

      his™ussion ™—mp not — le™ture seriesF ‰ou need to show
      motiv—tionF
      „o help you introdu™e to the world of —lgorithms —nd
      ™ompetitive progr—mming
      w—ny useful —lgorithmsD m—them—ti™—l insights
      …seful for —ny progr—mming ™ontest th—t you m—y en™ounter
      efter this you ™—n ro™k in jo˜Ginternship interviews
      st9s fun too3




                  League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                       Common Problems
                        Parsing a problem
                Standard Template Library
                            Using Bitwise
                                 Problems

Aim

      his™ussion ™—mp not — le™ture seriesF ‰ou need to show
      motiv—tionF
      „o help you introdu™e to the world of —lgorithms —nd
      ™ompetitive progr—mming
      w—ny useful —lgorithmsD m—them—ti™—l insights
      …seful for —ny progr—mming ™ontest th—t you m—y en™ounter
      efter this you ™—n ro™k in jo˜Ginternship interviews
      st9s fun too3
      „here —re h—ndsome rew—rds E prestigeD joy of le—rning new
      thingsD —nd yes lots of money3


                  League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                     Common Problems
                      Parsing a problem
              Standard Template Library
                          Using Bitwise
                               Problems

Language specications


      v—ngu—ge we will stress uponX gD gCCD t—v—
      egwEsg€g y0™i—l l—ngu—gesF ellowed in —lmost every
      ™ontests




                League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                      Common Problems
                       Parsing a problem
               Standard Template Library
                           Using Bitwise
                                Problems

Language specications


      v—ngu—ge we will stress uponX gD gCCD t—v—
      egwEsg€g y0™i—l l—ngu—gesF ellowed in —lmost every
      ™ontests
      futD t—v— is ™omp—r—tively very slowD so sometimes —n optim—l
      —lgorithm might time out on the judge




                 League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                      Common Problems
                       Parsing a problem
               Standard Template Library
                           Using Bitwise
                                Problems

Language specications


      v—ngu—ge we will stress uponX gD gCCD t—v—
      egwEsg€g y0™i—l l—ngu—gesF ellowed in —lmost every
      ™ontests
      futD t—v— is ™omp—r—tively very slowD so sometimes —n optim—l
      —lgorithm might time out on the judge
      g h—s too restri™tive —nd does not support stlGtempl—tes
      G™l—sses




                 League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                      Common Problems
                       Parsing a problem
               Standard Template Library
                           Using Bitwise
                                Problems

Language specications


      v—ngu—ge we will stress uponX gD gCCD t—v—
      egwEsg€g y0™i—l l—ngu—gesF ellowed in —lmost every
      ™ontests
      futD t—v— is ™omp—r—tively very slowD so sometimes —n optim—l
      —lgorithm might time out on the judge
      g h—s too restri™tive —nd does not support stlGtempl—tes
      G™l—sses
      …se vi˜r—ry fun™tions —nd h—t— ƒtru™tures inste—d of writing
      your own every time



                 League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                   Common Problems
                    Parsing a problem
            Standard Template Library
                        Using Bitwise
                             Problems

Programming competitions




     egwEsg€g




                League of Programmers   Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                    Common Problems
                     Parsing a problem
             Standard Template Library
                         Using Bitwise
                              Problems

Programming competitions




     egwEsg€g
     qoogle gode t—m E qoogle9s —nnu—l progr—mming ™ontest




                League of Programmers    Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                     Common Problems
                      Parsing a problem
              Standard Template Library
                          Using Bitwise
                               Problems

Programming competitions




     egwEsg€g
     qoogle gode t—m E qoogle9s —nnu—l progr—mming ™ontest
     p—™e˜ook r—™ker gup E —n e—sy g—tew—y to f—™e˜ook jo˜




                League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                     Common Problems
                      Parsing a problem
              Standard Template Library
                          Using Bitwise
                               Problems

Programming competitions




     egwEsg€g
     qoogle gode t—m E qoogle9s —nnu—l progr—mming ™ontest
     p—™e˜ook r—™ker gup E —n e—sy g—tew—y to f—™e˜ook jo˜
     sy€g @ss„uAD ƒh——str— @ss„wAD fitwise @ss„ugpA




                League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                      Common Problems
                       Parsing a problem
               Standard Template Library
                           Using Bitwise
                                Problems

Websites for practice




      gompete —g—inst sndi—n ™oders in live ™ontestsX gode™hef
      ƒhort €rogr—mming gontestsX godefor™esD „op™oder
      €ro˜lem set er™hivesX ƒ€ytD €roje™t iulerD live—r™hiveD
      —™mFsguFru —nd m—ny more




                 League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                        Common Problems
                         Parsing a problem
                 Standard Template Library
                             Using Bitwise
                                  Problems

Outline

  1   eim —nd gl—ri(™—tions

  2   gommon €ro˜lems

  3   €—rsing — pro˜lem

  4   ƒt—nd—rd „empl—te vi˜r—ry

  5   …sing fitwise

  6   €ro˜lems


                      League of Programmers   Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                    Common Problems
                     Parsing a problem
             Standard Template Library
                         Using Bitwise
                              Problems

Overow

  #includestdio.h
  int main()
  {
  int a, b;
  scanf(%d %d, a, b);
  printf(%dn, a+b);
  return 0;
  }




               League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                    Common Problems
                     Parsing a problem
             Standard Template Library
                         Using Bitwise
                              Problems

Overow

  #includestdio.h
  int main()
  {
  int a, b;
  scanf(%d %d, a, b);
  printf(%dn, a+b);
  return 0;
  }

     ‡h—t if the given num˜ers —re r…qic



               League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                      Common Problems
                       Parsing a problem
               Standard Template Library
                           Using Bitwise
                                Problems

Overow

  #includestdio.h
  int main()
  {
  int a, b;
  scanf(%d %d, a, b);
  printf(%dn, a+b);
  return 0;
  }

     ‡h—t if the given num˜ers —re r…qic
     xot —ll the input ™onstr—ints —re expli™it


                 League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                      Common Problems
                       Parsing a problem
               Standard Template Library
                           Using Bitwise
                                Problems

Overow

  #includestdio.h
  int main()
  {
  int a, b;
  scanf(%d %d, a, b);
  printf(%dn, a+b);
  return 0;
  }

     ‡h—t if the given num˜ers —re r…qic
     xot —ll the input ™onstr—ints —re expli™it
     elw—ys think —˜out the worst ™—se s™en—rioD edge ™—sesD et™F
                 League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                     Common Problems
                      Parsing a problem
              Standard Template Library
                          Using Bitwise
                               Problems

Others

     gomp—ring dou˜les
     elw—ys keep — ™ushion of




                League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                     Common Problems
                      Parsing a problem
              Standard Template Library
                          Using Bitwise
                               Problems

Others

     gomp—ring dou˜les
     elw—ys keep — ™ushion of
     double a, b;
     a==b, not a very good idea




                League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                      Common Problems
                       Parsing a problem
               Standard Template Library
                           Using Bitwise
                                Problems

Others

     gomp—ring dou˜les
     elw—ys keep — ™ushion of
     double a, b;
     a==b, not a very good idea
     inste—dD do the following
     #define EPS 0.0000001
     (a-EPSb and a+EPSb)




                 League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                      Common Problems
                       Parsing a problem
               Standard Template Library
                           Using Bitwise
                                Problems

Others

     gomp—ring dou˜les
     elw—ys keep — ™ushion of
     double a, b;
     a==b, not a very good idea
     inste—dD do the following
     #define EPS 0.0000001
     (a-EPSb and a+EPSb)
     ƒegment—tion f—ult




                 League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                      Common Problems
                       Parsing a problem
               Standard Template Library
                           Using Bitwise
                                Problems

Others

     gomp—ring dou˜les
     elw—ys keep — ™ushion of
     double a, b;
     a==b, not a very good idea
     inste—dD do the following
     #define EPS 0.0000001
     (a-EPSb and a+EPSb)
     ƒegment—tion f—ult
         Invalid memory reference
         Using too much memory than provided


                 League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                        Common Problems
                         Parsing a problem
                 Standard Template Library
                             Using Bitwise
                                  Problems

Outline

  1   eim —nd gl—ri(™—tions

  2   gommon €ro˜lems

  3   €—rsing — pro˜lem

  4   ƒt—nd—rd „empl—te vi˜r—ry

  5   …sing fitwise

  6   €ro˜lems


                      League of Programmers   Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                     Common Problems
                      Parsing a problem
              Standard Template Library
                          Using Bitwise
                               Problems

Problem Solving Methodology

     …nderst—nd wh—t the progr—m is expe™ted to doF




                League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                     Common Problems
                      Parsing a problem
              Standard Template Library
                          Using Bitwise
                               Problems

Problem Solving Methodology

     …nderst—nd wh—t the progr—m is expe™ted to doF
     …nderst—nd the snputGyutput form—t —nd use ex—™tly th—t
     form—t




                League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                     Common Problems
                      Parsing a problem
              Standard Template Library
                          Using Bitwise
                               Problems

Problem Solving Methodology

     …nderst—nd wh—t the progr—m is expe™ted to doF
     …nderst—nd the snputGyutput form—t —nd use ex—™tly th—t
     form—t
     we—ning of ™onstr—ints




                League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                     Common Problems
                      Parsing a problem
              Standard Template Library
                          Using Bitwise
                               Problems

Problem Solving Methodology

     …nderst—nd wh—t the progr—m is expe™ted to doF
     …nderst—nd the snputGyutput form—t —nd use ex—™tly th—t
     form—t
     we—ning of ™onstr—ints
     ‡h—t do time limit —nd memory limit me—ncc




                League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                     Common Problems
                      Parsing a problem
              Standard Template Library
                          Using Bitwise
                               Problems

Problem Solving Methodology

     …nderst—nd wh—t the progr—m is expe™ted to doF
     …nderst—nd the snputGyutput form—t —nd use ex—™tly th—t
     form—t
     we—ning of ™onstr—ints
     ‡h—t do time limit —nd memory limit me—ncc
     €redi™t the order requirements of the given pro˜lem




                League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                     Common Problems
                      Parsing a problem
              Standard Template Library
                          Using Bitwise
                               Problems

Problem Solving Methodology

     …nderst—nd wh—t the progr—m is expe™ted to doF
     …nderst—nd the snputGyutput form—t —nd use ex—™tly th—t
     form—t
     we—ning of ™onstr—ints
     ‡h—t do time limit —nd memory limit me—ncc
     €redi™t the order requirements of the given pro˜lem
     Isec ≈ (I − P) ∗ IH8 oper—tions




                League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                     Common Problems
                      Parsing a problem
              Standard Template Library
                          Using Bitwise
                               Problems

Problem Solving Methodology

     …nderst—nd wh—t the progr—m is expe™ted to doF
     …nderst—nd the snputGyutput form—t —nd use ex—™tly th—t
     form—t
     we—ning of ™onstr—ints
     ‡h—t do time limit —nd memory limit me—ncc
     €redi™t the order requirements of the given pro˜lem
     Isec ≈ (I − P) ∗ IH8 oper—tions
     xMB ≈ x /R ∗ IH   6
                           sized int —rr—ys




                League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                     Common Problems
                      Parsing a problem
              Standard Template Library
                          Using Bitwise
                               Problems

Problem Solving Methodology

     …nderst—nd wh—t the progr—m is expe™ted to doF
     …nderst—nd the snputGyutput form—t —nd use ex—™tly th—t
     form—t
     we—ning of ™onstr—ints
     ‡h—t do time limit —nd memory limit me—ncc
     €redi™t the order requirements of the given pro˜lem
     Isec ≈ (I − P) ∗ IH8 oper—tions
     xMB ≈ x /R ∗ IH   6
                           sized int —rr—ys
     por ex—mpleD IH test ™—ses with        N = IHHHH me—ns O (N                 2
                                                                                     ) is
     required

                League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                       Common Problems
                        Parsing a problem
                Standard Template Library
                            Using Bitwise
                                 Problems

Problem Solving Methodology

   1   …nderst—nding the pro˜lemD m—them—ti™—l formul—tion of the
       pro˜lem




                  League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                       Common Problems
                        Parsing a problem
                Standard Template Library
                            Using Bitwise
                                 Problems

Problem Solving Methodology

   1   …nderst—nding the pro˜lemD m—them—ti™—l formul—tion of the
       pro˜lem
   2   g—tegorizing the pro˜lem into one of the m—ny types known




                  League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                       Common Problems
                        Parsing a problem
                Standard Template Library
                            Using Bitwise
                                 Problems

Problem Solving Methodology

   1   …nderst—nding the pro˜lemD m—them—ti™—l formul—tion of the
       pro˜lem
   2   g—tegorizing the pro˜lem into one of the m—ny types known
   3   pormul—te — solution




                  League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                       Common Problems
                        Parsing a problem
                Standard Template Library
                            Using Bitwise
                                 Problems

Problem Solving Methodology

   1   …nderst—nding the pro˜lemD m—them—ti™—l formul—tion of the
       pro˜lem
   2   g—tegorizing the pro˜lem into one of the m—ny types known
   3   pormul—te — solution
   4   †erify with the s—mple test ™—sesD m—ke sure your solution
       —tle—st works for them




                  League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                       Common Problems
                        Parsing a problem
                Standard Template Library
                            Using Bitwise
                                 Problems

Problem Solving Methodology

   1   …nderst—nding the pro˜lemD m—them—ti™—l formul—tion of the
       pro˜lem
   2   g—tegorizing the pro˜lem into one of the m—ny types known
   3   pormul—te — solution
   4   †erify with the s—mple test ™—sesD m—ke sure your solution
       —tle—st works for them
   5   qener—te some sm—ll test ™—ses of your ownD the s—mple test
       ™—ses m—y not ˜e in™lude some ˜ound—ry ™—sesF




                  League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                        Common Problems
                         Parsing a problem
                 Standard Template Library
                             Using Bitwise
                                  Problems

Problem Solving Methodology

   1   …nderst—nding the pro˜lemD m—them—ti™—l formul—tion of the
       pro˜lem
   2   g—tegorizing the pro˜lem into one of the m—ny types known
   3   pormul—te — solution
   4   †erify with the s—mple test ™—sesD m—ke sure your solution
       —tle—st works for them
   5   qener—te some sm—ll test ™—ses of your ownD the s—mple test
       ™—ses m—y not ˜e in™lude some ˜ound—ry ™—sesF
   6   goding the solution @the e—siest p—rt of —llA




                   League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                        Common Problems
                         Parsing a problem
                 Standard Template Library
                             Using Bitwise
                                  Problems

Problem Solving Methodology

   1   …nderst—nding the pro˜lemD m—them—ti™—l formul—tion of the
       pro˜lem
   2   g—tegorizing the pro˜lem into one of the m—ny types known
   3   pormul—te — solution
   4   †erify with the s—mple test ™—sesD m—ke sure your solution
       —tle—st works for them
   5   qener—te some sm—ll test ™—ses of your ownD the s—mple test
       ™—ses m—y not ˜e in™lude some ˜ound—ry ™—sesF
   6   goding the solution @the e—siest p—rt of —llA
   7   he˜ugging („vi: time limit ex™eededD ‡e : in™orre™t solution
       et™.)

                   League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                    Common Problems
                     Parsing a problem
             Standard Template Library
                         Using Bitwise
                              Problems

Some optimizations


     xot —ll oper—tions —re equ—lly f—stX
     oper—tions on unsigned ints/long long —re f—ster
     ˜itwise oper—tors —nd shift oper—tors (ˆ |    )
     …sing too mu™h memory ( IHMB ) slows down progr—mmes




               League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                     Common Problems
                      Parsing a problem
              Standard Template Library
                          Using Bitwise
                               Problems

Some optimizations


     xot —ll oper—tions —re equ—lly f—stX
     oper—tions on unsigned ints/long long —re f—ster
     ˜itwise oper—tors —nd shift oper—tors (ˆ |    )
     …sing too mu™h memory ( IHMB ) slows down progr—mmes
     vook —t other people9s ™ode for referen™e —nd optimis—tions




                League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                     Common Problems
                      Parsing a problem
              Standard Template Library
                          Using Bitwise
                               Problems

Some optimizations


     xot —ll oper—tions —re equ—lly f—stX
     oper—tions on unsigned ints/long long —re f—ster
     ˜itwise oper—tors —nd shift oper—tors (ˆ |    )
     …sing too mu™h memory ( IHMB ) slows down progr—mmes
     vook —t other people9s ™ode for referen™e —nd optimis—tions
     ‚e—d thisX http://www.codeproject.com/KB/cpp/C___
     Code_Optimization.aspx




                League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                     Common Problems
                      Parsing a problem
              Standard Template Library
                          Using Bitwise
                               Problems

Some optimizations


     xot —ll oper—tions —re equ—lly f—stX
     oper—tions on unsigned ints/long long —re f—ster
     ˜itwise oper—tors —nd shift oper—tors (ˆ |    )
     …sing too mu™h memory ( IHMB ) slows down progr—mmes
     vook —t other people9s ™ode for referen™e —nd optimis—tions
     ‚e—d thisX http://www.codeproject.com/KB/cpp/C___
     Code_Optimization.aspx
     sGyX do xy„ use ™inG™out for l—rge input output




                League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                    Common Problems
                     Parsing a problem
             Standard Template Library
                         Using Bitwise
                              Problems

Some Standard paradigms
     ƒorting
     ƒe—r™hing
     €repro™essing
     hivideE—ndEgonquer
     hyn—mi™ €rogr—mming
     qreedy elgorithms
     qr—ph
     xetwork plow
     f—™ktr—™king
     gomput—tion—l qeometry
     €ure m—ths
     edEho™ pro˜lems
               League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                        Common Problems
                         Parsing a problem
                 Standard Template Library
                             Using Bitwise
                                  Problems

Outline

  1   eim —nd gl—ri(™—tions

  2   gommon €ro˜lems

  3   €—rsing — pro˜lem

  4   ƒt—nd—rd „empl—te vi˜r—ry

  5   …sing fitwise

  6   €ro˜lems


                      League of Programmers   Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                     Common Problems
                      Parsing a problem
              Standard Template Library
                          Using Bitwise
                               Problems

Standard template library
  ‡e˜site: http://www.cplusplus.com/reference
   1 h—t— ƒtru™tures




                League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                     Common Problems
                      Parsing a problem
              Standard Template Library
                          Using Bitwise
                               Problems

Standard template library
  ‡e˜site: http://www.cplusplus.com/reference
   1 h—t— ƒtru™tures

           vector




                League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                     Common Problems
                      Parsing a problem
              Standard Template Library
                          Using Bitwise
                               Problems

Standard template library
  ‡e˜site: http://www.cplusplus.com/reference
   1 h—t— ƒtru™tures

           vector
           stack




                League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                     Common Problems
                      Parsing a problem
              Standard Template Library
                          Using Bitwise
                               Problems

Standard template library
  ‡e˜site: http://www.cplusplus.com/reference
   1 h—t— ƒtru™tures

           vector
           stack
           queue




                League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                     Common Problems
                      Parsing a problem
              Standard Template Library
                          Using Bitwise
                               Problems

Standard template library
  ‡e˜site: http://www.cplusplus.com/reference
   1 h—t— ƒtru™tures

           vector
           stack
           queue
           priority_queue




                League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                     Common Problems
                      Parsing a problem
              Standard Template Library
                          Using Bitwise
                               Problems

Standard template library
  ‡e˜site: http://www.cplusplus.com/reference
   1 h—t— ƒtru™tures

           vector
           stack
           queue
           priority_queue
           set




                League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                     Common Problems
                      Parsing a problem
              Standard Template Library
                          Using Bitwise
                               Problems

Standard template library
  ‡e˜site: http://www.cplusplus.com/reference
   1 h—t— ƒtru™tures

           vector
           stack
           queue
           priority_queue
           set
           map




                League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                     Common Problems
                      Parsing a problem
              Standard Template Library
                          Using Bitwise
                               Problems

Standard template library
  ‡e˜site: http://www.cplusplus.com/reference
   1 h—t— ƒtru™tures

           vector
           stack
           queue
           priority_queue
           set
           map
   2 elgorithms




                League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                     Common Problems
                      Parsing a problem
              Standard Template Library
                          Using Bitwise
                               Problems

Standard template library
  ‡e˜site: http://www.cplusplus.com/reference
   1 h—t— ƒtru™tures

           vector
           stack
           queue
           priority_queue
           set
           map
   2 elgorithms

           nd




                League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                     Common Problems
                      Parsing a problem
              Standard Template Library
                          Using Bitwise
                               Problems

Standard template library
  ‡e˜site: http://www.cplusplus.com/reference
   1 h—t— ƒtru™tures

           vector
           stack
           queue
           priority_queue
           set
           map
   2 elgorithms

           nd
           max, min




                League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                     Common Problems
                      Parsing a problem
              Standard Template Library
                          Using Bitwise
                               Problems

Standard template library
  ‡e˜site: http://www.cplusplus.com/reference
   1 h—t— ƒtru™tures

           vector
           stack
           queue
           priority_queue
           set
           map
   2 elgorithms

           nd
           max, min
           sort



                League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                     Common Problems
                      Parsing a problem
              Standard Template Library
                          Using Bitwise
                               Problems

Standard template library
  ‡e˜site: http://www.cplusplus.com/reference
   1 h—t— ƒtru™tures

           vector
           stack
           queue
           priority_queue
           set
           map
   2 elgorithms

           nd
           max, min
           sort
           reverse


                League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                     Common Problems
                      Parsing a problem
              Standard Template Library
                          Using Bitwise
                               Problems

Standard template library
  ‡e˜site: http://www.cplusplus.com/reference
   1 h—t— ƒtru™tures

           vector
           stack
           queue
           priority_queue
           set
           map
   2 elgorithms

           nd
           max, min
           sort
           reverse
           swap
                League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                        Common Problems
                         Parsing a problem
                 Standard Template Library
                             Using Bitwise
                                  Problems

Stack



   1    v—st inD (rst out @vspyA




                   League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                        Common Problems
                         Parsing a problem
                 Standard Template Library
                             Using Bitwise
                                  Problems

Stack



   1    v—st inD (rst out @vspyA
   2    ƒupports three ™onst—ntEtime oper—tions




                   League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                        Common Problems
                         Parsing a problem
                 Standard Template Library
                             Using Bitwise
                                  Problems

Stack



   1    v—st inD (rst out @vspyA
   2    ƒupports three ™onst—ntEtime oper—tions
            Push(x): inserts x into the stack




                   League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                        Common Problems
                         Parsing a problem
                 Standard Template Library
                             Using Bitwise
                                  Problems

Stack



   1    v—st inD (rst out @vspyA
   2    ƒupports three ™onst—ntEtime oper—tions
            Push(x): inserts x into the stack
            Pop(): removes the newest item




                   League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                        Common Problems
                         Parsing a problem
                 Standard Template Library
                             Using Bitwise
                                  Problems

Stack



   1    v—st inD (rst out @vspyA
   2    ƒupports three ™onst—ntEtime oper—tions
            Push(x): inserts x into the stack
            Pop(): removes the newest item
            Top(): returns the newest item




                   League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                        Common Problems
                         Parsing a problem
                 Standard Template Library
                             Using Bitwise
                                  Problems

Stack



   1    v—st inD (rst out @vspyA
   2    ƒupports three ™onst—ntEtime oper—tions
            Push(x): inserts x into the stack
            Pop(): removes the newest item
            Top(): returns the newest item
   3    gCC —nd t—v— h—ve implement—tions of st—™k




                   League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                         Common Problems
                          Parsing a problem
                  Standard Template Library
                              Using Bitwise
                                   Problems

Queue



   1    pirst inD (rst out @pspyA




                    League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                         Common Problems
                          Parsing a problem
                  Standard Template Library
                              Using Bitwise
                                   Problems

Queue



   1    pirst inD (rst out @pspyA
   2    ƒupports three ™onst—ntEtime oper—tions




                    League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                         Common Problems
                          Parsing a problem
                  Standard Template Library
                              Using Bitwise
                                   Problems

Queue



   1    pirst inD (rst out @pspyA
   2    ƒupports three ™onst—ntEtime oper—tions
            Enqueue(x): inserts x into the queue




                    League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                         Common Problems
                          Parsing a problem
                  Standard Template Library
                              Using Bitwise
                                   Problems

Queue



   1    pirst inD (rst out @pspyA
   2    ƒupports three ™onst—ntEtime oper—tions
            Enqueue(x): inserts x into the queue
            Dequeue(): removes the oldest item




                    League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                         Common Problems
                          Parsing a problem
                  Standard Template Library
                              Using Bitwise
                                   Problems

Queue



   1    pirst inD (rst out @pspyA
   2    ƒupports three ™onst—ntEtime oper—tions
            Enqueue(x): inserts x into the queue
            Dequeue(): removes the oldest item
            Front(): returns the oldest item




                    League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                         Common Problems
                          Parsing a problem
                  Standard Template Library
                              Using Bitwise
                                   Problems

Queue



   1    pirst inD (rst out @pspyA
   2    ƒupports three ™onst—ntEtime oper—tions
            Enqueue(x): inserts x into the queue
            Dequeue(): removes the oldest item
            Front(): returns the oldest item
   3    gCC —nd t—v— h—ve implement—tions of queue




                    League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                        Common Problems
                         Parsing a problem
                 Standard Template Library
                             Using Bitwise
                                  Problems

Priority Queue


    1   i—™h element in — € h—s — priority v—lue




                   League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                        Common Problems
                         Parsing a problem
                 Standard Template Library
                             Using Bitwise
                                  Problems

Priority Queue


    1   i—™h element in — € h—s — priority v—lue
    2   „hree oper—tionsX




                   League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                        Common Problems
                         Parsing a problem
                 Standard Template Library
                             Using Bitwise
                                  Problems

Priority Queue


    1   i—™h element in — € h—s — priority v—lue
    2   „hree oper—tionsX
            Insert(x, p): inserts x into the PQ, whose priority is p




                   League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                        Common Problems
                         Parsing a problem
                 Standard Template Library
                             Using Bitwise
                                  Problems

Priority Queue


    1   i—™h element in — € h—s — priority v—lue
    2   „hree oper—tionsX
            Insert(x, p): inserts x into the PQ, whose priority is p
            RemoveTop(): removes the element with the highest priority




                   League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                        Common Problems
                         Parsing a problem
                 Standard Template Library
                             Using Bitwise
                                  Problems

Priority Queue


    1   i—™h element in — € h—s — priority v—lue
    2   „hree oper—tionsX
            Insert(x, p): inserts x into the PQ, whose priority is p
            RemoveTop(): removes the element with the highest priority
            Top(): returns the element with the highest priority




                   League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                        Common Problems
                         Parsing a problem
                 Standard Template Library
                             Using Bitwise
                                  Problems

Priority Queue


    1   i—™h element in — € h—s — priority v—lue
    2   „hree oper—tionsX
            Insert(x, p): inserts x into the PQ, whose priority is p
            RemoveTop(): removes the element with the highest priority
            Top(): returns the element with the highest priority
    3   ell oper—tions ™—n ˜e done qui™kly if implemented using — he—p




                   League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                        Common Problems
                         Parsing a problem
                 Standard Template Library
                             Using Bitwise
                                  Problems

Priority Queue


    1   i—™h element in — € h—s — priority v—lue
    2   „hree oper—tionsX
            Insert(x, p): inserts x into the PQ, whose priority is p
            RemoveTop(): removes the element with the highest priority
            Top(): returns the element with the highest priority
    3   ell oper—tions ™—n ˜e done qui™kly if implemented using — he—p
    4   gCC —nd t—v— h—ve implement—tions of priority queue




                   League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                       Common Problems
                        Parsing a problem
                Standard Template Library
                            Using Bitwise
                                 Problems

Heap


   1   gomplete ˜in—ry tree with the he—p propertyX
       v—lue of — node ≥ v—lues of its ™hildren




                  League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                       Common Problems
                        Parsing a problem
                Standard Template Library
                            Using Bitwise
                                 Problems

Heap


   1   gomplete ˜in—ry tree with the he—p propertyX
       v—lue of — node ≥ v—lues of its ™hildren
   2   „he root node h—s the m—ximum v—lue




                  League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                       Common Problems
                        Parsing a problem
                Standard Template Library
                            Using Bitwise
                                 Problems

Heap


   1   gomplete ˜in—ry tree with the he—p propertyX
       v—lue of — node ≥ v—lues of its ™hildren
   2   „he root node h—s the m—ximum v—lue
   3   gonst—ntEtimeX top@A




                  League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                       Common Problems
                        Parsing a problem
                Standard Template Library
                            Using Bitwise
                                 Problems

Heap


   1   gomplete ˜in—ry tree with the he—p propertyX
       v—lue of — node ≥ v—lues of its ™hildren
   2   „he root node h—s the m—ximum v—lue
   3   gonst—ntEtimeX top@A
   4   snsertingGremoving — node ™—n ˜e done in y@log nA time
       without ˜re—king the he—p property




                  League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                       Common Problems
                        Parsing a problem
                Standard Template Library
                            Using Bitwise
                                 Problems

Heap


   1   gomplete ˜in—ry tree with the he—p propertyX
       v—lue of — node ≥ v—lues of its ™hildren
   2   „he root node h—s the m—ximum v—lue
   3   gonst—ntEtimeX top@A
   4   snsertingGremoving — node ™—n ˜e done in y@log nA time
       without ˜re—king the he—p property
   5   w—y need re—rr—ngement of some nodes




                  League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
              Common Problems
               Parsing a problem
       Standard Template Library
                   Using Bitwise
                        Problems

Heap




         League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                         Common Problems
                          Parsing a problem
                  Standard Template Library
                              Using Bitwise
                                   Problems

Heap


  snserting — xode
    1   w—ke — new node in the l—st levelD —s f—r left —s possi˜leF sf the
        l—st level is fullD m—ke — new one




                    League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                         Common Problems
                          Parsing a problem
                  Standard Template Library
                              Using Bitwise
                                   Problems

Heap


  snserting — xode
    1   w—ke — new node in the l—st levelD —s f—r left —s possi˜leF sf the
        l—st level is fullD m—ke — new one
    2   sf the new node ˜re—ks the he—p propertyD sw—p with its p—rent
        nodeF „he new node moves up the treeD whi™h m—y introdu™e
        —nother ™on)i™t




                    League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                         Common Problems
                          Parsing a problem
                  Standard Template Library
                              Using Bitwise
                                   Problems

Heap


  snserting — xode
    1   w—ke — new node in the l—st levelD —s f—r left —s possi˜leF sf the
        l—st level is fullD m—ke — new one
    2   sf the new node ˜re—ks the he—p propertyD sw—p with its p—rent
        nodeF „he new node moves up the treeD whi™h m—y introdu™e
        —nother ™on)i™t
    3   ‚epe—t P until —ll ™on)i™ts —re resolved




                    League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                         Common Problems
                          Parsing a problem
                  Standard Template Library
                              Using Bitwise
                                   Problems

Heap


  snserting — xode
    1   w—ke — new node in the l—st levelD —s f—r left —s possi˜leF sf the
        l—st level is fullD m—ke — new one
    2   sf the new node ˜re—ks the he—p propertyD sw—p with its p—rent
        nodeF „he new node moves up the treeD whi™h m—y introdu™e
        —nother ™on)i™t
    3   ‚epe—t P until —ll ™on)i™ts —re resolved
    4   ‚unning time a tree height a y@log nA




                    League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                       Common Problems
                        Parsing a problem
                Standard Template Library
                            Using Bitwise
                                 Problems

Heap


  heleting the ‚oot xode
   1   ‚emove the rootD —nd ˜ring the l—st node @rightmost node in
       the l—st levelA to the root




                  League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                        Common Problems
                         Parsing a problem
                 Standard Template Library
                             Using Bitwise
                                  Problems

Heap


  heleting the ‚oot xode
   1   ‚emove the rootD —nd ˜ring the l—st node @rightmost node in
       the l—st levelA to the root
   2   sf the root ˜re—ks the he—p propertyD look —t its ™hildren —nd
       sw—p it with the l—rger oneF ƒw—pping ™—n introdu™e —nother
       ™on)i™t




                   League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                        Common Problems
                         Parsing a problem
                 Standard Template Library
                             Using Bitwise
                                  Problems

Heap


  heleting the ‚oot xode
   1   ‚emove the rootD —nd ˜ring the l—st node @rightmost node in
       the l—st levelA to the root
   2   sf the root ˜re—ks the he—p propertyD look —t its ™hildren —nd
       sw—p it with the l—rger oneF ƒw—pping ™—n introdu™e —nother
       ™on)i™t
   3   ‚epe—t P until —ll ™on)i™ts —re resolved




                   League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                        Common Problems
                         Parsing a problem
                 Standard Template Library
                             Using Bitwise
                                  Problems

Heap


  heleting the ‚oot xode
   1   ‚emove the rootD —nd ˜ring the l—st node @rightmost node in
       the l—st levelA to the root
   2   sf the root ˜re—ks the he—p propertyD look —t its ™hildren —nd
       sw—p it with the l—rger oneF ƒw—pping ™—n introdu™e —nother
       ™on)i™t
   3   ‚epe—t P until —ll ™on)i™ts —re resolved
   4   ‚unning time a y@log nA




                   League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                        Common Problems
                         Parsing a problem
                 Standard Template Library
                             Using Bitwise
                                  Problems

Outline

  1   eim —nd gl—ri(™—tions

  2   gommon €ro˜lems

  3   €—rsing — pro˜lem

  4   ƒt—nd—rd „empl—te vi˜r—ry

  5   …sing fitwise

  6   €ro˜lems


                      League of Programmers   Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                        Common Problems
                         Parsing a problem
                 Standard Template Library
                             Using Bitwise
                                  Problems

Introduction to Bitwise Operators


    1   xum˜ers —re stored in ˜in—ry —nd pro™essing on ˜its is w—y
        f—sterF




                   League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                        Common Problems
                         Parsing a problem
                 Standard Template Library
                             Using Bitwise
                                  Problems

Introduction to Bitwise Operators


    1   xum˜ers —re stored in ˜in—ry —nd pro™essing on ˜its is w—y
        f—sterF
    2   yur we—ponsX
         @left shiftAY  @right shiftAY 8 @˜itwise —ndAY
        | @˜itwise orAY ¢ @˜itwise xorAY ∼ @˜itwise notA




                   League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                        Common Problems
                         Parsing a problem
                 Standard Template Library
                             Using Bitwise
                                  Problems

Introduction to Bitwise Operators


    1   xum˜ers —re stored in ˜in—ry —nd pro™essing on ˜its is w—y
        f—sterF
    2   yur we—ponsX
         @left shiftAY  @right shiftAY 8 @˜itwise —ndAY
        | @˜itwise orAY ¢ @˜itwise xorAY ∼ @˜itwise notA
    3   ƒpeed up the ™ode ˜y upto IHH timesF g—utionX try to use
        ˜itwise oper—tions on unsigned integers only




                   League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                          Common Problems
                           Parsing a problem
                   Standard Template Library
                               Using Bitwise
                                    Problems

Beauty of Bitwise
    1   ix—mpleX




                     League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                          Common Problems
                           Parsing a problem
                   Standard Template Library
                               Using Bitwise
                                    Problems

Beauty of Bitwise
    1   ix—mpleX
            Any subset of 0,1. . . 31 is a single int




                     League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                          Common Problems
                           Parsing a problem
                   Standard Template Library
                               Using Bitwise
                                    Problems

Beauty of Bitwise
    1   ix—mpleX
            Any subset of 0,1. . . 31 is a single int
            Do set union/intersection/complement in one operation
            increment/decrement all elements by x in one operation




                     League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                          Common Problems
                           Parsing a problem
                   Standard Template Library
                               Using Bitwise
                                    Problems

Beauty of Bitwise
    1   ix—mpleX
            Any subset of 0,1. . . 31 is a single int
            Do set union/intersection/complement in one operation
            increment/decrement all elements by x in one operation
    2   iven moreX




                     League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                          Common Problems
                           Parsing a problem
                   Standard Template Library
                               Using Bitwise
                                    Problems

Beauty of Bitwise
    1   ix—mpleX
            Any subset of 0,1. . . 31 is a single int
            Do set union/intersection/complement in one operation
            increment/decrement all elements by x in one operation
    2   iven moreX
            Find if x ∈ S .




                     League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                          Common Problems
                           Parsing a problem
                   Standard Template Library
                               Using Bitwise
                                    Problems

Beauty of Bitwise
    1   ix—mpleX
            Any subset of 0,1. . . 31 is a single int
            Do set union/intersection/complement in one operation
            increment/decrement all elements by x in one operation
    2   iven moreX
            Find if x ∈ S .
            Generate all subsets of S in 2|S | time




                     League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                          Common Problems
                           Parsing a problem
                   Standard Template Library
                               Using Bitwise
                                    Problems

Beauty of Bitwise
    1   ix—mpleX
            Any subset of 0,1. . . 31 is a single int
            Do set union/intersection/complement in one operation
            increment/decrement all elements by x in one operation
    2   iven moreX
            Find if x ∈ S .
            Generate all subsets of S in 2|S | time
            Generate all subsets of 1..n changing one bit at a time




                     League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                          Common Problems
                           Parsing a problem
                   Standard Template Library
                               Using Bitwise
                                    Problems

Beauty of Bitwise
    1   ix—mpleX
            Any subset of 0,1. . . 31 is a single int
            Do set union/intersection/complement in one operation
            increment/decrement all elements by x in one operation
    2   iven moreX
            Find if x ∈ S .
            Generate all subsets of S in 2|S | time
            Generate all subsets of 1..n changing one bit at a time
            Generate all subsets of S which have exactly t elements




                     League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                          Common Problems
                           Parsing a problem
                   Standard Template Library
                               Using Bitwise
                                    Problems

Beauty of Bitwise
    1   ix—mpleX
            Any subset of 0,1. . . 31 is a single int
            Do set union/intersection/complement in one operation
            increment/decrement all elements by x in one operation
    2   iven moreX
            Find if x ∈ S .
            Generate all subsets of S in 2|S | time
            Generate all subsets of 1..n changing one bit at a time
            Generate all subsets of S which have exactly t elements
            Count the number of elements of elements in a set S




                     League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                          Common Problems
                           Parsing a problem
                   Standard Template Library
                               Using Bitwise
                                    Problems

Beauty of Bitwise
    1   ix—mpleX
            Any subset of 0,1. . . 31 is a single int
            Do set union/intersection/complement in one operation
            increment/decrement all elements by x in one operation
    2   iven moreX
            Find if x ∈ S .
            Generate all subsets of S in 2|S | time
            Generate all subsets of 1..n changing one bit at a time
            Generate all subsets of S which have exactly t elements
            Count the number of elements of elements in a set S
            Remove smallest element from S



                     League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                          Common Problems
                           Parsing a problem
                   Standard Template Library
                               Using Bitwise
                                    Problems

Beauty of Bitwise
    1   ix—mpleX
            Any subset of 0,1. . . 31 is a single int
            Do set union/intersection/complement in one operation
            increment/decrement all elements by x in one operation
    2   iven moreX
            Find if x ∈ S .
            Generate all subsets of S in 2|S | time
            Generate all subsets of 1..n changing one bit at a time
            Generate all subsets of S which have exactly t elements
            Count the number of elements of elements in a set S
            Remove smallest element from S
            Check if |S| = 1


                     League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                          Common Problems
                           Parsing a problem
                   Standard Template Library
                               Using Bitwise
                                    Problems

Beauty of Bitwise
    1   ix—mpleX
            Any subset of 0,1. . . 31 is a single int
            Do set union/intersection/complement in one operation
            increment/decrement all elements by x in one operation
    2   iven moreX
            Find if x ∈ S .
            Generate all subsets of S in 2|S | time
            Generate all subsets of 1..n changing one bit at a time
            Generate all subsets of S which have exactly t elements
            Count the number of elements of elements in a set S
            Remove smallest element from S
            Check if |S| = 1
    3   xever multiply or divide or t—ke rem—inder modulo power of P
                     League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                        Common Problems
                         Parsing a problem
                 Standard Template Library
                             Using Bitwise
                                  Problems

Outline

  1   eim —nd gl—ri(™—tions

  2   gommon €ro˜lems

  3   €—rsing — pro˜lem

  4   ƒt—nd—rd „empl—te vi˜r—ry

  5   …sing fitwise

  6   €ro˜lems


                      League of Programmers   Introductory Lecture Topics: basics, resources, stl, bitwise
Aim and Clarications
                     Common Problems
                      Parsing a problem
              Standard Template Library
                          Using Bitwise
                               Problems

Problems
  edded on the ™ontest on †yg http://ahmed-aly.com/voc/
  gontest shX PSUV
  x—meX egeD ss„u vy€ HI
  euthorX pnkjjind—l
  vinksX
    1 http://spoj.pl/problems/WEIRDFN
    2 http://www.spoj.pl/problems/HOMO/
    3 http://spoj.pl/problems/HISTOGRA
    4 http://spoj.pl/problems/SUBSEQ
    5 http://www.spoj.pl/problems/NGM2/
    6 http://www.spoj.pl/problems/JOCHEF
    7 http://www.spoj.pl/problems/SWTHIN/
    8 http://www.spoj.pl/problems/LAZYPROG/

                League of Programmers     Introductory Lecture Topics: basics, resources, stl, bitwise

More Related Content

PDF
Effective stl notes
PDF
Advanced CPP Lecture 2- Summer School 2014 - ACA CSE IITK
PDF
05 graph
PDF
PDF
Advanced CPP Lecture 1- Summer School 2014 - ACA CSE IITK
PDF
JavaScript, the good parts + syntactic sugar = CoffeeScript
PPT
C++ Advanced
ODP
Talk on Standard Template Library
Effective stl notes
Advanced CPP Lecture 2- Summer School 2014 - ACA CSE IITK
05 graph
Advanced CPP Lecture 1- Summer School 2014 - ACA CSE IITK
JavaScript, the good parts + syntactic sugar = CoffeeScript
C++ Advanced
Talk on Standard Template Library

Viewers also liked (6)

PDF
04 maths
PDF
Front End Development - Beyond Javascript (Robin Cannon)
PDF
Top 10 things a fresh programmer should know - Dao Ngoc Khanh
PDF
02 greedy, d&c, binary search
PDF
Security in the Internet of Things
PDF
Becoming a Better Programmer
04 maths
Front End Development - Beyond Javascript (Robin Cannon)
Top 10 things a fresh programmer should know - Dao Ngoc Khanh
02 greedy, d&c, binary search
Security in the Internet of Things
Becoming a Better Programmer
Ad

Similar to 01 basics and stl (20)

PDF
Boost Your Base Bootcamp - [Online & Offline] In Bangla
PPTX
DSA unpluggedEventByGDGOncampusAtMedcaps.pptx
PDF
Os Lamothe
PDF
AIML Learning Path Cheat Sheet Essential Tools & Frameworks to Crack Your Int...
PDF
An introduction to Julia
PDF
Econometrics for python, how to deal with data
PPTX
Software Modeling and Artificial Intelligence: friends or foes?
PPTX
Education - Coding and Computational Thinking.pptx
PDF
ASE01.ppt
PDF
Foundation Models in Recommender Systems
PPTX
Basic Engineering Design (Part 7): Presenting the Solution
PDF
All in AI: LLM Landscape & RAG in 2024 with Mark Ryan (Google) & Jerry Liu (L...
PDF
“An Industry Standard Performance Benchmark Suite for Machine Learning,” a Pr...
PPT
Qualitative Data Analysis Using NVivo: An Introduction Workshop
DOCX
Basics of Python.docx
PPTX
Interview Preparation guide for DSA.pptx
PPTX
Presentation Making Guidelines
PPTX
Mastering_Prompt_Engineering_orompt.pptx
PDF
The View - 30 proven Lotuscript tips
PPTX
Formation au logiciel NVivo d'analyse de données qualitatives
Boost Your Base Bootcamp - [Online & Offline] In Bangla
DSA unpluggedEventByGDGOncampusAtMedcaps.pptx
Os Lamothe
AIML Learning Path Cheat Sheet Essential Tools & Frameworks to Crack Your Int...
An introduction to Julia
Econometrics for python, how to deal with data
Software Modeling and Artificial Intelligence: friends or foes?
Education - Coding and Computational Thinking.pptx
ASE01.ppt
Foundation Models in Recommender Systems
Basic Engineering Design (Part 7): Presenting the Solution
All in AI: LLM Landscape & RAG in 2024 with Mark Ryan (Google) & Jerry Liu (L...
“An Industry Standard Performance Benchmark Suite for Machine Learning,” a Pr...
Qualitative Data Analysis Using NVivo: An Introduction Workshop
Basics of Python.docx
Interview Preparation guide for DSA.pptx
Presentation Making Guidelines
Mastering_Prompt_Engineering_orompt.pptx
The View - 30 proven Lotuscript tips
Formation au logiciel NVivo d'analyse de données qualitatives
Ad

01 basics and stl

  • 1. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Introductory Lecture Topics: basics, resources, stl, bitwise tricks ve—gue of €rogr—mmers ACA, IIT Kanpur y™to˜er PID PHIP League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 2. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Outline 1 eim —nd gl—ri(™—tions 2 gommon €ro˜lems 3 €—rsing — pro˜lem 4 ƒt—nd—rd „empl—te vi˜r—ry 5 …sing fitwise 6 €ro˜lems League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 3. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Aim his™ussion ™—mp not — le™ture seriesF ‰ou need to show motiv—tionF League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 4. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Aim his™ussion ™—mp not — le™ture seriesF ‰ou need to show motiv—tionF „o help you introdu™e to the world of —lgorithms —nd ™ompetitive progr—mming League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 5. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Aim his™ussion ™—mp not — le™ture seriesF ‰ou need to show motiv—tionF „o help you introdu™e to the world of —lgorithms —nd ™ompetitive progr—mming w—ny useful —lgorithmsD m—them—ti™—l insights League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 6. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Aim his™ussion ™—mp not — le™ture seriesF ‰ou need to show motiv—tionF „o help you introdu™e to the world of —lgorithms —nd ™ompetitive progr—mming w—ny useful —lgorithmsD m—them—ti™—l insights …seful for —ny progr—mming ™ontest th—t you m—y en™ounter League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 7. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Aim his™ussion ™—mp not — le™ture seriesF ‰ou need to show motiv—tionF „o help you introdu™e to the world of —lgorithms —nd ™ompetitive progr—mming w—ny useful —lgorithmsD m—them—ti™—l insights …seful for —ny progr—mming ™ontest th—t you m—y en™ounter efter this you ™—n ro™k in jo˜Ginternship interviews League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 8. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Aim his™ussion ™—mp not — le™ture seriesF ‰ou need to show motiv—tionF „o help you introdu™e to the world of —lgorithms —nd ™ompetitive progr—mming w—ny useful —lgorithmsD m—them—ti™—l insights …seful for —ny progr—mming ™ontest th—t you m—y en™ounter efter this you ™—n ro™k in jo˜Ginternship interviews st9s fun too3 League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 9. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Aim his™ussion ™—mp not — le™ture seriesF ‰ou need to show motiv—tionF „o help you introdu™e to the world of —lgorithms —nd ™ompetitive progr—mming w—ny useful —lgorithmsD m—them—ti™—l insights …seful for —ny progr—mming ™ontest th—t you m—y en™ounter efter this you ™—n ro™k in jo˜Ginternship interviews st9s fun too3 „here —re h—ndsome rew—rds E prestigeD joy of le—rning new thingsD —nd yes lots of money3 League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 10. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Language specications v—ngu—ge we will stress uponX gD gCCD t—v— egwEsg€g y0™i—l l—ngu—gesF ellowed in —lmost every ™ontests League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 11. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Language specications v—ngu—ge we will stress uponX gD gCCD t—v— egwEsg€g y0™i—l l—ngu—gesF ellowed in —lmost every ™ontests futD t—v— is ™omp—r—tively very slowD so sometimes —n optim—l —lgorithm might time out on the judge League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 12. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Language specications v—ngu—ge we will stress uponX gD gCCD t—v— egwEsg€g y0™i—l l—ngu—gesF ellowed in —lmost every ™ontests futD t—v— is ™omp—r—tively very slowD so sometimes —n optim—l —lgorithm might time out on the judge g h—s too restri™tive —nd does not support stlGtempl—tes G™l—sses League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 13. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Language specications v—ngu—ge we will stress uponX gD gCCD t—v— egwEsg€g y0™i—l l—ngu—gesF ellowed in —lmost every ™ontests futD t—v— is ™omp—r—tively very slowD so sometimes —n optim—l —lgorithm might time out on the judge g h—s too restri™tive —nd does not support stlGtempl—tes G™l—sses …se vi˜r—ry fun™tions —nd h—t— ƒtru™tures inste—d of writing your own every time League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 14. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Programming competitions egwEsg€g League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 15. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Programming competitions egwEsg€g qoogle gode t—m E qoogle9s —nnu—l progr—mming ™ontest League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 16. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Programming competitions egwEsg€g qoogle gode t—m E qoogle9s —nnu—l progr—mming ™ontest p—™e˜ook r—™ker gup E —n e—sy g—tew—y to f—™e˜ook jo˜ League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 17. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Programming competitions egwEsg€g qoogle gode t—m E qoogle9s —nnu—l progr—mming ™ontest p—™e˜ook r—™ker gup E —n e—sy g—tew—y to f—™e˜ook jo˜ sy€g @ss„uAD ƒh——str— @ss„wAD fitwise @ss„ugpA League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 18. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Websites for practice gompete —g—inst sndi—n ™oders in live ™ontestsX gode™hef ƒhort €rogr—mming gontestsX godefor™esD „op™oder €ro˜lem set er™hivesX ƒ€ytD €roje™t iulerD live—r™hiveD —™mFsguFru —nd m—ny more League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 19. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Outline 1 eim —nd gl—ri(™—tions 2 gommon €ro˜lems 3 €—rsing — pro˜lem 4 ƒt—nd—rd „empl—te vi˜r—ry 5 …sing fitwise 6 €ro˜lems League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 20. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Overow #includestdio.h int main() { int a, b; scanf(%d %d, a, b); printf(%dn, a+b); return 0; } League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 21. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Overow #includestdio.h int main() { int a, b; scanf(%d %d, a, b); printf(%dn, a+b); return 0; } ‡h—t if the given num˜ers —re r…qic League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 22. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Overow #includestdio.h int main() { int a, b; scanf(%d %d, a, b); printf(%dn, a+b); return 0; } ‡h—t if the given num˜ers —re r…qic xot —ll the input ™onstr—ints —re expli™it League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 23. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Overow #includestdio.h int main() { int a, b; scanf(%d %d, a, b); printf(%dn, a+b); return 0; } ‡h—t if the given num˜ers —re r…qic xot —ll the input ™onstr—ints —re expli™it elw—ys think —˜out the worst ™—se s™en—rioD edge ™—sesD et™F League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 24. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Others gomp—ring dou˜les elw—ys keep — ™ushion of League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 25. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Others gomp—ring dou˜les elw—ys keep — ™ushion of double a, b; a==b, not a very good idea League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 26. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Others gomp—ring dou˜les elw—ys keep — ™ushion of double a, b; a==b, not a very good idea inste—dD do the following #define EPS 0.0000001 (a-EPSb and a+EPSb) League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 27. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Others gomp—ring dou˜les elw—ys keep — ™ushion of double a, b; a==b, not a very good idea inste—dD do the following #define EPS 0.0000001 (a-EPSb and a+EPSb) ƒegment—tion f—ult League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 28. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Others gomp—ring dou˜les elw—ys keep — ™ushion of double a, b; a==b, not a very good idea inste—dD do the following #define EPS 0.0000001 (a-EPSb and a+EPSb) ƒegment—tion f—ult Invalid memory reference Using too much memory than provided League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 29. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Outline 1 eim —nd gl—ri(™—tions 2 gommon €ro˜lems 3 €—rsing — pro˜lem 4 ƒt—nd—rd „empl—te vi˜r—ry 5 …sing fitwise 6 €ro˜lems League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 30. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Problem Solving Methodology …nderst—nd wh—t the progr—m is expe™ted to doF League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 31. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Problem Solving Methodology …nderst—nd wh—t the progr—m is expe™ted to doF …nderst—nd the snputGyutput form—t —nd use ex—™tly th—t form—t League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 32. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Problem Solving Methodology …nderst—nd wh—t the progr—m is expe™ted to doF …nderst—nd the snputGyutput form—t —nd use ex—™tly th—t form—t we—ning of ™onstr—ints League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 33. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Problem Solving Methodology …nderst—nd wh—t the progr—m is expe™ted to doF …nderst—nd the snputGyutput form—t —nd use ex—™tly th—t form—t we—ning of ™onstr—ints ‡h—t do time limit —nd memory limit me—ncc League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 34. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Problem Solving Methodology …nderst—nd wh—t the progr—m is expe™ted to doF …nderst—nd the snputGyutput form—t —nd use ex—™tly th—t form—t we—ning of ™onstr—ints ‡h—t do time limit —nd memory limit me—ncc €redi™t the order requirements of the given pro˜lem League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 35. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Problem Solving Methodology …nderst—nd wh—t the progr—m is expe™ted to doF …nderst—nd the snputGyutput form—t —nd use ex—™tly th—t form—t we—ning of ™onstr—ints ‡h—t do time limit —nd memory limit me—ncc €redi™t the order requirements of the given pro˜lem Isec ≈ (I − P) ∗ IH8 oper—tions League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 36. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Problem Solving Methodology …nderst—nd wh—t the progr—m is expe™ted to doF …nderst—nd the snputGyutput form—t —nd use ex—™tly th—t form—t we—ning of ™onstr—ints ‡h—t do time limit —nd memory limit me—ncc €redi™t the order requirements of the given pro˜lem Isec ≈ (I − P) ∗ IH8 oper—tions xMB ≈ x /R ∗ IH 6 sized int —rr—ys League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 37. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Problem Solving Methodology …nderst—nd wh—t the progr—m is expe™ted to doF …nderst—nd the snputGyutput form—t —nd use ex—™tly th—t form—t we—ning of ™onstr—ints ‡h—t do time limit —nd memory limit me—ncc €redi™t the order requirements of the given pro˜lem Isec ≈ (I − P) ∗ IH8 oper—tions xMB ≈ x /R ∗ IH 6 sized int —rr—ys por ex—mpleD IH test ™—ses with N = IHHHH me—ns O (N 2 ) is required League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 38. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Problem Solving Methodology 1 …nderst—nding the pro˜lemD m—them—ti™—l formul—tion of the pro˜lem League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 39. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Problem Solving Methodology 1 …nderst—nding the pro˜lemD m—them—ti™—l formul—tion of the pro˜lem 2 g—tegorizing the pro˜lem into one of the m—ny types known League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 40. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Problem Solving Methodology 1 …nderst—nding the pro˜lemD m—them—ti™—l formul—tion of the pro˜lem 2 g—tegorizing the pro˜lem into one of the m—ny types known 3 pormul—te — solution League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 41. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Problem Solving Methodology 1 …nderst—nding the pro˜lemD m—them—ti™—l formul—tion of the pro˜lem 2 g—tegorizing the pro˜lem into one of the m—ny types known 3 pormul—te — solution 4 †erify with the s—mple test ™—sesD m—ke sure your solution —tle—st works for them League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 42. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Problem Solving Methodology 1 …nderst—nding the pro˜lemD m—them—ti™—l formul—tion of the pro˜lem 2 g—tegorizing the pro˜lem into one of the m—ny types known 3 pormul—te — solution 4 †erify with the s—mple test ™—sesD m—ke sure your solution —tle—st works for them 5 qener—te some sm—ll test ™—ses of your ownD the s—mple test ™—ses m—y not ˜e in™lude some ˜ound—ry ™—sesF League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 43. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Problem Solving Methodology 1 …nderst—nding the pro˜lemD m—them—ti™—l formul—tion of the pro˜lem 2 g—tegorizing the pro˜lem into one of the m—ny types known 3 pormul—te — solution 4 †erify with the s—mple test ™—sesD m—ke sure your solution —tle—st works for them 5 qener—te some sm—ll test ™—ses of your ownD the s—mple test ™—ses m—y not ˜e in™lude some ˜ound—ry ™—sesF 6 goding the solution @the e—siest p—rt of —llA League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 44. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Problem Solving Methodology 1 …nderst—nding the pro˜lemD m—them—ti™—l formul—tion of the pro˜lem 2 g—tegorizing the pro˜lem into one of the m—ny types known 3 pormul—te — solution 4 †erify with the s—mple test ™—sesD m—ke sure your solution —tle—st works for them 5 qener—te some sm—ll test ™—ses of your ownD the s—mple test ™—ses m—y not ˜e in™lude some ˜ound—ry ™—sesF 6 goding the solution @the e—siest p—rt of —llA 7 he˜ugging („vi: time limit ex™eededD ‡e : in™orre™t solution et™.) League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 45. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Some optimizations xot —ll oper—tions —re equ—lly f—stX oper—tions on unsigned ints/long long —re f—ster ˜itwise oper—tors —nd shift oper—tors (ˆ | ) …sing too mu™h memory ( IHMB ) slows down progr—mmes League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 46. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Some optimizations xot —ll oper—tions —re equ—lly f—stX oper—tions on unsigned ints/long long —re f—ster ˜itwise oper—tors —nd shift oper—tors (ˆ | ) …sing too mu™h memory ( IHMB ) slows down progr—mmes vook —t other people9s ™ode for referen™e —nd optimis—tions League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 47. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Some optimizations xot —ll oper—tions —re equ—lly f—stX oper—tions on unsigned ints/long long —re f—ster ˜itwise oper—tors —nd shift oper—tors (ˆ | ) …sing too mu™h memory ( IHMB ) slows down progr—mmes vook —t other people9s ™ode for referen™e —nd optimis—tions ‚e—d thisX http://www.codeproject.com/KB/cpp/C___ Code_Optimization.aspx League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 48. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Some optimizations xot —ll oper—tions —re equ—lly f—stX oper—tions on unsigned ints/long long —re f—ster ˜itwise oper—tors —nd shift oper—tors (ˆ | ) …sing too mu™h memory ( IHMB ) slows down progr—mmes vook —t other people9s ™ode for referen™e —nd optimis—tions ‚e—d thisX http://www.codeproject.com/KB/cpp/C___ Code_Optimization.aspx sGyX do xy„ use ™inG™out for l—rge input output League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 49. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Some Standard paradigms ƒorting ƒe—r™hing €repro™essing hivideE—ndEgonquer hyn—mi™ €rogr—mming qreedy elgorithms qr—ph xetwork plow f—™ktr—™king gomput—tion—l qeometry €ure m—ths edEho™ pro˜lems League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 50. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Outline 1 eim —nd gl—ri(™—tions 2 gommon €ro˜lems 3 €—rsing — pro˜lem 4 ƒt—nd—rd „empl—te vi˜r—ry 5 …sing fitwise 6 €ro˜lems League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 51. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Standard template library ‡e˜site: http://www.cplusplus.com/reference 1 h—t— ƒtru™tures League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 52. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Standard template library ‡e˜site: http://www.cplusplus.com/reference 1 h—t— ƒtru™tures vector League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 53. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Standard template library ‡e˜site: http://www.cplusplus.com/reference 1 h—t— ƒtru™tures vector stack League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 54. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Standard template library ‡e˜site: http://www.cplusplus.com/reference 1 h—t— ƒtru™tures vector stack queue League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 55. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Standard template library ‡e˜site: http://www.cplusplus.com/reference 1 h—t— ƒtru™tures vector stack queue priority_queue League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 56. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Standard template library ‡e˜site: http://www.cplusplus.com/reference 1 h—t— ƒtru™tures vector stack queue priority_queue set League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 57. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Standard template library ‡e˜site: http://www.cplusplus.com/reference 1 h—t— ƒtru™tures vector stack queue priority_queue set map League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 58. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Standard template library ‡e˜site: http://www.cplusplus.com/reference 1 h—t— ƒtru™tures vector stack queue priority_queue set map 2 elgorithms League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 59. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Standard template library ‡e˜site: http://www.cplusplus.com/reference 1 h—t— ƒtru™tures vector stack queue priority_queue set map 2 elgorithms nd League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 60. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Standard template library ‡e˜site: http://www.cplusplus.com/reference 1 h—t— ƒtru™tures vector stack queue priority_queue set map 2 elgorithms nd max, min League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 61. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Standard template library ‡e˜site: http://www.cplusplus.com/reference 1 h—t— ƒtru™tures vector stack queue priority_queue set map 2 elgorithms nd max, min sort League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 62. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Standard template library ‡e˜site: http://www.cplusplus.com/reference 1 h—t— ƒtru™tures vector stack queue priority_queue set map 2 elgorithms nd max, min sort reverse League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 63. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Standard template library ‡e˜site: http://www.cplusplus.com/reference 1 h—t— ƒtru™tures vector stack queue priority_queue set map 2 elgorithms nd max, min sort reverse swap League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 64. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Stack 1 v—st inD (rst out @vspyA League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 65. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Stack 1 v—st inD (rst out @vspyA 2 ƒupports three ™onst—ntEtime oper—tions League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 66. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Stack 1 v—st inD (rst out @vspyA 2 ƒupports three ™onst—ntEtime oper—tions Push(x): inserts x into the stack League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 67. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Stack 1 v—st inD (rst out @vspyA 2 ƒupports three ™onst—ntEtime oper—tions Push(x): inserts x into the stack Pop(): removes the newest item League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 68. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Stack 1 v—st inD (rst out @vspyA 2 ƒupports three ™onst—ntEtime oper—tions Push(x): inserts x into the stack Pop(): removes the newest item Top(): returns the newest item League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 69. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Stack 1 v—st inD (rst out @vspyA 2 ƒupports three ™onst—ntEtime oper—tions Push(x): inserts x into the stack Pop(): removes the newest item Top(): returns the newest item 3 gCC —nd t—v— h—ve implement—tions of st—™k League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 70. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Queue 1 pirst inD (rst out @pspyA League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 71. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Queue 1 pirst inD (rst out @pspyA 2 ƒupports three ™onst—ntEtime oper—tions League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 72. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Queue 1 pirst inD (rst out @pspyA 2 ƒupports three ™onst—ntEtime oper—tions Enqueue(x): inserts x into the queue League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 73. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Queue 1 pirst inD (rst out @pspyA 2 ƒupports three ™onst—ntEtime oper—tions Enqueue(x): inserts x into the queue Dequeue(): removes the oldest item League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 74. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Queue 1 pirst inD (rst out @pspyA 2 ƒupports three ™onst—ntEtime oper—tions Enqueue(x): inserts x into the queue Dequeue(): removes the oldest item Front(): returns the oldest item League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 75. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Queue 1 pirst inD (rst out @pspyA 2 ƒupports three ™onst—ntEtime oper—tions Enqueue(x): inserts x into the queue Dequeue(): removes the oldest item Front(): returns the oldest item 3 gCC —nd t—v— h—ve implement—tions of queue League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 76. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Priority Queue 1 i—™h element in — € h—s — priority v—lue League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 77. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Priority Queue 1 i—™h element in — € h—s — priority v—lue 2 „hree oper—tionsX League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 78. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Priority Queue 1 i—™h element in — € h—s — priority v—lue 2 „hree oper—tionsX Insert(x, p): inserts x into the PQ, whose priority is p League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 79. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Priority Queue 1 i—™h element in — € h—s — priority v—lue 2 „hree oper—tionsX Insert(x, p): inserts x into the PQ, whose priority is p RemoveTop(): removes the element with the highest priority League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 80. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Priority Queue 1 i—™h element in — € h—s — priority v—lue 2 „hree oper—tionsX Insert(x, p): inserts x into the PQ, whose priority is p RemoveTop(): removes the element with the highest priority Top(): returns the element with the highest priority League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 81. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Priority Queue 1 i—™h element in — € h—s — priority v—lue 2 „hree oper—tionsX Insert(x, p): inserts x into the PQ, whose priority is p RemoveTop(): removes the element with the highest priority Top(): returns the element with the highest priority 3 ell oper—tions ™—n ˜e done qui™kly if implemented using — he—p League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 82. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Priority Queue 1 i—™h element in — € h—s — priority v—lue 2 „hree oper—tionsX Insert(x, p): inserts x into the PQ, whose priority is p RemoveTop(): removes the element with the highest priority Top(): returns the element with the highest priority 3 ell oper—tions ™—n ˜e done qui™kly if implemented using — he—p 4 gCC —nd t—v— h—ve implement—tions of priority queue League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 83. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Heap 1 gomplete ˜in—ry tree with the he—p propertyX v—lue of — node ≥ v—lues of its ™hildren League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 84. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Heap 1 gomplete ˜in—ry tree with the he—p propertyX v—lue of — node ≥ v—lues of its ™hildren 2 „he root node h—s the m—ximum v—lue League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 85. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Heap 1 gomplete ˜in—ry tree with the he—p propertyX v—lue of — node ≥ v—lues of its ™hildren 2 „he root node h—s the m—ximum v—lue 3 gonst—ntEtimeX top@A League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 86. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Heap 1 gomplete ˜in—ry tree with the he—p propertyX v—lue of — node ≥ v—lues of its ™hildren 2 „he root node h—s the m—ximum v—lue 3 gonst—ntEtimeX top@A 4 snsertingGremoving — node ™—n ˜e done in y@log nA time without ˜re—king the he—p property League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 87. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Heap 1 gomplete ˜in—ry tree with the he—p propertyX v—lue of — node ≥ v—lues of its ™hildren 2 „he root node h—s the m—ximum v—lue 3 gonst—ntEtimeX top@A 4 snsertingGremoving — node ™—n ˜e done in y@log nA time without ˜re—king the he—p property 5 w—y need re—rr—ngement of some nodes League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 88. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Heap League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 89. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Heap snserting — xode 1 w—ke — new node in the l—st levelD —s f—r left —s possi˜leF sf the l—st level is fullD m—ke — new one League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 90. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Heap snserting — xode 1 w—ke — new node in the l—st levelD —s f—r left —s possi˜leF sf the l—st level is fullD m—ke — new one 2 sf the new node ˜re—ks the he—p propertyD sw—p with its p—rent nodeF „he new node moves up the treeD whi™h m—y introdu™e —nother ™on)i™t League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 91. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Heap snserting — xode 1 w—ke — new node in the l—st levelD —s f—r left —s possi˜leF sf the l—st level is fullD m—ke — new one 2 sf the new node ˜re—ks the he—p propertyD sw—p with its p—rent nodeF „he new node moves up the treeD whi™h m—y introdu™e —nother ™on)i™t 3 ‚epe—t P until —ll ™on)i™ts —re resolved League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 92. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Heap snserting — xode 1 w—ke — new node in the l—st levelD —s f—r left —s possi˜leF sf the l—st level is fullD m—ke — new one 2 sf the new node ˜re—ks the he—p propertyD sw—p with its p—rent nodeF „he new node moves up the treeD whi™h m—y introdu™e —nother ™on)i™t 3 ‚epe—t P until —ll ™on)i™ts —re resolved 4 ‚unning time a tree height a y@log nA League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 93. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Heap heleting the ‚oot xode 1 ‚emove the rootD —nd ˜ring the l—st node @rightmost node in the l—st levelA to the root League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 94. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Heap heleting the ‚oot xode 1 ‚emove the rootD —nd ˜ring the l—st node @rightmost node in the l—st levelA to the root 2 sf the root ˜re—ks the he—p propertyD look —t its ™hildren —nd sw—p it with the l—rger oneF ƒw—pping ™—n introdu™e —nother ™on)i™t League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 95. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Heap heleting the ‚oot xode 1 ‚emove the rootD —nd ˜ring the l—st node @rightmost node in the l—st levelA to the root 2 sf the root ˜re—ks the he—p propertyD look —t its ™hildren —nd sw—p it with the l—rger oneF ƒw—pping ™—n introdu™e —nother ™on)i™t 3 ‚epe—t P until —ll ™on)i™ts —re resolved League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 96. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Heap heleting the ‚oot xode 1 ‚emove the rootD —nd ˜ring the l—st node @rightmost node in the l—st levelA to the root 2 sf the root ˜re—ks the he—p propertyD look —t its ™hildren —nd sw—p it with the l—rger oneF ƒw—pping ™—n introdu™e —nother ™on)i™t 3 ‚epe—t P until —ll ™on)i™ts —re resolved 4 ‚unning time a y@log nA League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 97. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Outline 1 eim —nd gl—ri(™—tions 2 gommon €ro˜lems 3 €—rsing — pro˜lem 4 ƒt—nd—rd „empl—te vi˜r—ry 5 …sing fitwise 6 €ro˜lems League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 98. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Introduction to Bitwise Operators 1 xum˜ers —re stored in ˜in—ry —nd pro™essing on ˜its is w—y f—sterF League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 99. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Introduction to Bitwise Operators 1 xum˜ers —re stored in ˜in—ry —nd pro™essing on ˜its is w—y f—sterF 2 yur we—ponsX @left shiftAY @right shiftAY 8 @˜itwise —ndAY | @˜itwise orAY ¢ @˜itwise xorAY ∼ @˜itwise notA League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 100. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Introduction to Bitwise Operators 1 xum˜ers —re stored in ˜in—ry —nd pro™essing on ˜its is w—y f—sterF 2 yur we—ponsX @left shiftAY @right shiftAY 8 @˜itwise —ndAY | @˜itwise orAY ¢ @˜itwise xorAY ∼ @˜itwise notA 3 ƒpeed up the ™ode ˜y upto IHH timesF g—utionX try to use ˜itwise oper—tions on unsigned integers only League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 101. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Beauty of Bitwise 1 ix—mpleX League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 102. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Beauty of Bitwise 1 ix—mpleX Any subset of 0,1. . . 31 is a single int League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 103. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Beauty of Bitwise 1 ix—mpleX Any subset of 0,1. . . 31 is a single int Do set union/intersection/complement in one operation increment/decrement all elements by x in one operation League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 104. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Beauty of Bitwise 1 ix—mpleX Any subset of 0,1. . . 31 is a single int Do set union/intersection/complement in one operation increment/decrement all elements by x in one operation 2 iven moreX League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 105. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Beauty of Bitwise 1 ix—mpleX Any subset of 0,1. . . 31 is a single int Do set union/intersection/complement in one operation increment/decrement all elements by x in one operation 2 iven moreX Find if x ∈ S . League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 106. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Beauty of Bitwise 1 ix—mpleX Any subset of 0,1. . . 31 is a single int Do set union/intersection/complement in one operation increment/decrement all elements by x in one operation 2 iven moreX Find if x ∈ S . Generate all subsets of S in 2|S | time League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 107. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Beauty of Bitwise 1 ix—mpleX Any subset of 0,1. . . 31 is a single int Do set union/intersection/complement in one operation increment/decrement all elements by x in one operation 2 iven moreX Find if x ∈ S . Generate all subsets of S in 2|S | time Generate all subsets of 1..n changing one bit at a time League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 108. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Beauty of Bitwise 1 ix—mpleX Any subset of 0,1. . . 31 is a single int Do set union/intersection/complement in one operation increment/decrement all elements by x in one operation 2 iven moreX Find if x ∈ S . Generate all subsets of S in 2|S | time Generate all subsets of 1..n changing one bit at a time Generate all subsets of S which have exactly t elements League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 109. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Beauty of Bitwise 1 ix—mpleX Any subset of 0,1. . . 31 is a single int Do set union/intersection/complement in one operation increment/decrement all elements by x in one operation 2 iven moreX Find if x ∈ S . Generate all subsets of S in 2|S | time Generate all subsets of 1..n changing one bit at a time Generate all subsets of S which have exactly t elements Count the number of elements of elements in a set S League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 110. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Beauty of Bitwise 1 ix—mpleX Any subset of 0,1. . . 31 is a single int Do set union/intersection/complement in one operation increment/decrement all elements by x in one operation 2 iven moreX Find if x ∈ S . Generate all subsets of S in 2|S | time Generate all subsets of 1..n changing one bit at a time Generate all subsets of S which have exactly t elements Count the number of elements of elements in a set S Remove smallest element from S League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 111. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Beauty of Bitwise 1 ix—mpleX Any subset of 0,1. . . 31 is a single int Do set union/intersection/complement in one operation increment/decrement all elements by x in one operation 2 iven moreX Find if x ∈ S . Generate all subsets of S in 2|S | time Generate all subsets of 1..n changing one bit at a time Generate all subsets of S which have exactly t elements Count the number of elements of elements in a set S Remove smallest element from S Check if |S| = 1 League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 112. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Beauty of Bitwise 1 ix—mpleX Any subset of 0,1. . . 31 is a single int Do set union/intersection/complement in one operation increment/decrement all elements by x in one operation 2 iven moreX Find if x ∈ S . Generate all subsets of S in 2|S | time Generate all subsets of 1..n changing one bit at a time Generate all subsets of S which have exactly t elements Count the number of elements of elements in a set S Remove smallest element from S Check if |S| = 1 3 xever multiply or divide or t—ke rem—inder modulo power of P League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 113. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Outline 1 eim —nd gl—ri(™—tions 2 gommon €ro˜lems 3 €—rsing — pro˜lem 4 ƒt—nd—rd „empl—te vi˜r—ry 5 …sing fitwise 6 €ro˜lems League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
  • 114. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Problems edded on the ™ontest on †yg http://ahmed-aly.com/voc/ gontest shX PSUV x—meX egeD ss„u vy€ HI euthorX pnkjjind—l vinksX 1 http://spoj.pl/problems/WEIRDFN 2 http://www.spoj.pl/problems/HOMO/ 3 http://spoj.pl/problems/HISTOGRA 4 http://spoj.pl/problems/SUBSEQ 5 http://www.spoj.pl/problems/NGM2/ 6 http://www.spoj.pl/problems/JOCHEF 7 http://www.spoj.pl/problems/SWTHIN/ 8 http://www.spoj.pl/problems/LAZYPROG/ League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise