Upcoming SlideShare
×

# 01 basics and stl

349 views

Published on

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
349
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
16
0
Likes
0
Embeds 0
No embeds

No notes for slide

### 01 basics and stl

1. 1. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise Problems Introductory LectureTopics: 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. 2. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsOutline 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. 3. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsAim hisussion mp not  leture seriesF ou need to show motivtionF League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
4. 4. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsAim 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. 5. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsAim 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. 6. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsAim 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. 7. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsAim 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. 8. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsAim 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. 9. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsAim 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. 10. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsLanguage 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. 11. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsLanguage 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. 12. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsLanguage 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. 13. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsLanguage 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. 14. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsProgramming competitions egwEsgg League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
15. 15. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsProgramming 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. 16. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsProgramming 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. 17. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsProgramming 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. 18. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsWebsites 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. 19. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsOutline 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. 20. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsOverow #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. 21. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsOverow #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. 22. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsOverow #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. 23. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsOverow #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. 24. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsOthers gompring doules elwys keep  ushion of League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
25. 25. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsOthers 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. 26. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsOthers 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. 27. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsOthers 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. 28. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsOthers 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. 29. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsOutline 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. 30. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsProblem 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. 31. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsProblem 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. 32. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsProblem 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. 33. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsProblem 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. 34. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsProblem 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. 35. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsProblem 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. 36. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsProblem 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. 37. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsProblem 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. 38. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsProblem 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. 39. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsProblem 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. 40. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsProblem 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. 41. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsProblem 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. 42. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsProblem 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. 43. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsProblem 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. 44. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsProblem 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. 45. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsSome 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. 46. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsSome 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. 47. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsSome 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. 48. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsSome 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. 49. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsSome 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. 50. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsOutline 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. 51. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsStandard 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. 52. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsStandard 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. 53. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsStandard 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. 54. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsStandard 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. 55. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsStandard 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. 56. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsStandard 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. 57. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsStandard 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. 58. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsStandard 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. 59. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsStandard 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. 60. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsStandard 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. 61. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsStandard 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. 62. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsStandard 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. 63. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsStandard 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. 64. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsStack 1 vst inD (rst out @vspyA League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
65. 65. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsStack 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. 66. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsStack 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. 67. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsStack 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. 68. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsStack 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. 69. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsStack 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. 70. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsQueue 1 pirst inD (rst out @pspyA League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
71. 71. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsQueue 1 pirst inD (rst out @pspyA 2 upports three onstntEtime opertions League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
72. 72. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsQueue 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. 73. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsQueue 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. 74. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsQueue 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. 75. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsQueue 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. 76. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsPriority Queue 1 ih element in   hs  priority vlue League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
77. 77. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsPriority 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. 78. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsPriority 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. 79. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsPriority 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. 80. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsPriority 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. 81. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsPriority 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. 82. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsPriority 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. 83. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsHeap 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. 84. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsHeap 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. 85. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsHeap 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. 86. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsHeap 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. 87. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsHeap 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. 88. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsHeap League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
89. 89. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsHeap 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. 90. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsHeap 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. 91. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsHeap 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. 92. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsHeap 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. 93. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsHeap 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. 94. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsHeap 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. 95. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsHeap 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. 96. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsHeap 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. 97. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsOutline 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. 98. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsIntroduction 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. 99. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsIntroduction 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. 100. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsIntroduction 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. 101. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsBeauty of Bitwise 1 ixmpleX League of Programmers Introductory Lecture Topics: basics, resources, stl, bitwise
102. 102. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsBeauty 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. 103. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsBeauty 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. 104. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsBeauty 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. 105. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsBeauty 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. 106. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsBeauty 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. 107. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsBeauty 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. 108. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsBeauty 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. 109. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsBeauty 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. 110. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsBeauty 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. 111. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsBeauty 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. 112. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsBeauty 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. 113. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsOutline 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. 114. Aim and Clarications Common Problems Parsing a problem Standard Template Library Using Bitwise ProblemsProblems 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