├── static
├── .nojekyll
└── img
│ ├── cl_logo.png
│ ├── favicon.ico
│ ├── logo.svg
│ ├── undraw_solution_mindset.svg
│ ├── undraw_coding.svg
│ ├── undraw_Process.svg
│ └── undraw_exams.svg
├── babel.config.js
├── .gitignore
├── src
├── pages
│ ├── styles.module.css
│ └── index.js
└── css
│ └── custom.css
├── docs
├── roadmap
│ ├── programming-techniques
│ │ ├── greedy-tutorials.md
│ │ ├── dynamic-programming-tutorials.md
│ │ └── programming-techniques-problems.md
│ ├── learn-cpp.md
│ ├── basics
│ │ ├── time-space-complexity.md
│ │ └── other-important-things.md
│ ├── stl
│ │ ├── implementation-and-regular-contests.md
│ │ ├── stl-tutorials.md
│ │ ├── stl-problems.md
│ │ └── stl-editorials.mdx
│ ├── number-theory
│ │ ├── number-theory-tutorials.md
│ │ └── number-theory-problems.md
│ ├── binary-search
│ │ ├── binary-search-tutorials.md
│ │ └── binary-search-problems.md
│ ├── advanced
│ │ ├── dp-on-graphs.md
│ │ └── dp-with-bitmasks.md
│ └── graphs
│ │ ├── graph-tutorials.md
│ │ └── graph-problems.md
├── tools.md
└── contests
│ └── 2020
│ └── number-theory-and-bs.mdx
├── package.json
├── sidebars.js
├── README.md
├── blog
├── 2020-09-22-learning-cpp-as-a-beginner.md
└── 2020-09-23-shifting-from-c-to-cpp.md
├── CONTRIBUTING.md
└── docusaurus.config.js
/static/.nojekyll:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/static/img/cl_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cyber-Labs/cp-roadmap/HEAD/static/img/cl_logo.png
--------------------------------------------------------------------------------
/static/img/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Cyber-Labs/cp-roadmap/HEAD/static/img/favicon.ico
--------------------------------------------------------------------------------
/babel.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | presets: [require.resolve('@docusaurus/core/lib/babel/preset')],
3 | };
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Dependencies
2 | /node_modules
3 |
4 | # Production
5 | /build
6 |
7 | # Generated files
8 | .docusaurus
9 | .cache-loader
10 |
11 | # Misc
12 | .DS_Store
13 | .env.local
14 | .env.development.local
15 | .env.test.local
16 | .env.production.local
17 |
18 | npm-debug.log*
19 | yarn-debug.log*
20 | yarn-error.log*
21 |
--------------------------------------------------------------------------------
/src/pages/styles.module.css:
--------------------------------------------------------------------------------
1 | /* stylelint-disable docusaurus/copyright-header */
2 |
3 | /**
4 | * CSS files with the .module.css suffix will be treated as CSS modules
5 | * and scoped locally.
6 | */
7 |
8 | .heroBanner {
9 | padding: 4rem 0;
10 | text-align: center;
11 | position: relative;
12 | overflow: hidden;
13 | }
14 |
15 | @media screen and (max-width: 966px) {
16 | .heroBanner {
17 | padding: 2rem;
18 | }
19 | }
20 |
21 | .buttons {
22 | display: flex;
23 | align-items: center;
24 | justify-content: center;
25 | }
26 |
27 | .features {
28 | display: flex;
29 | align-items: center;
30 | padding: 2rem 0;
31 | width: 100%;
32 | }
33 |
34 | .featureImage {
35 | height: 200px;
36 | width: 200px;
37 | }
38 |
--------------------------------------------------------------------------------
/docs/roadmap/programming-techniques/greedy-tutorials.md:
--------------------------------------------------------------------------------
1 | ---
2 | id: greedy-tutorials
3 | title: Greedy Tutorials
4 | sidebar_label: Greedy Tutorials
5 | description: Greedy tutorials by cyberlabs
6 | ---
7 |
8 | 1. Read [hackerearth article on greedy technique](https://www.hackerearth.com/practice/algorithms/greedy/basics-of-greedy-algorithms/tutorial/)
9 |
10 | 2. Whiteboard slides used during the session can be found [here](https://drive.google.com/file/d/1HxbBCIEPkT1dA2ljN6cGmhy40GcE7F1c/view)
11 |
12 |
13 | :::tip
14 |
15 | **Note**: Generally, greedy techniques are used to solve either Optimisation problems (Problems where we need to minimise or maximise something) or Yes/No problems (Problems where the answer to the problem is Yes or No).
16 |
17 | :::
--------------------------------------------------------------------------------
/docs/roadmap/learn-cpp.md:
--------------------------------------------------------------------------------
1 | ---
2 | id: learn-cpp
3 | title: Learn C++
4 | sidebar_label: Learn C++
5 | description: Best Resources for learning c++ (cpp), why is c++ important for competitive programming ?
6 | slug: ./
7 | ---
8 |
9 | ## Why C++
10 |
11 | - It is the language allowed by all companies and competitions
12 | - Much faster then JAVA or Python
13 | - The STL Library, which makes life a lot easier for competitive coders .
14 |
15 | ## Resources for C++
16 |
17 | - If you know C already, you can shift to C++ by [reading this short guide](../../blog/2020/09/23/shifting-from-c-to-cpp)
18 | - Otherwise, you can learn C++, as per [this blog](../../blog/2020/09/22/learning-cpp-as-a-beginner) or by watching [Saurabh Shukla C++ videos](https://www.youtube.com/watch?v=Iuo9PpGE04Y&list=PLLYz8uHU480j37APNXBdPz7YzAi4XlQUF)
19 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "cp-roadmap-v-2",
3 | "version": "0.0.0",
4 | "private": true,
5 | "scripts": {
6 | "docusaurus": "docusaurus",
7 | "start": "docusaurus start",
8 | "build": "docusaurus build",
9 | "swizzle": "docusaurus swizzle",
10 | "deploy": "docusaurus deploy",
11 | "serve": "docusaurus serve"
12 | },
13 | "dependencies": {
14 | "@docusaurus/core": "2.0.0-alpha.65",
15 | "@docusaurus/preset-classic": "2.0.0-alpha.65",
16 | "@mdx-js/react": "^1.5.8",
17 | "clsx": "^1.1.1",
18 | "react": "^16.8.4",
19 | "react-dom": "^16.8.4",
20 | "rehype-katex": "^4.0.0",
21 | "remark-math": "^3.0.1"
22 | },
23 | "browserslist": {
24 | "production": [
25 | ">0.2%",
26 | "not dead",
27 | "not op_mini all"
28 | ],
29 | "development": [
30 | "last 1 chrome version",
31 | "last 1 firefox version",
32 | "last 1 safari version"
33 | ]
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/docs/roadmap/basics/time-space-complexity.md:
--------------------------------------------------------------------------------
1 | ---
2 | id: time-space-complexity
3 | title: Time and Space Complexity
4 | sidebar_label: Time and Space Complexity
5 | description: Best Resources for time and space complexity, big oh, assymptotic analysis for competitive programming by cyberlabs
6 | ---
7 |
8 | ## Assymptotic Notations
9 |
10 | - To get an idea of notations like Big-Oh, Omega and Theta, it is recommended to [watch this video, by Abdul Bari](https://youtu.be/A03oI0znAoc).
11 |
12 | ## Finding the time complexity
13 |
14 | - You should be able to find out the time complexity of a given code snippet. You can [watch this video](https://www.youtube.com/watch?v=9TlHvipP5yA) for this.
15 |
16 | ## Checking whether your solution will pass the time limits
17 |
18 | - Go through [this tutorial on hackerearth](https://www.hackerearth.com/practice/basic-programming/complexity-analysis/time-and-space-complexity/tutorial/). You must be able to find out, if your solution is fast enough, to pass the time limit constraints.
19 |
20 | :::tip
21 |
22 | Approximately, 107-108 operations are performed in 1 second. Always use this information, to estimate whether your solution will be able to pass the time limits, before writing any code.
23 |
24 | :::
--------------------------------------------------------------------------------
/sidebars.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | roadmap: {
3 | Basics: [
4 | 'roadmap/learn-cpp',
5 | 'roadmap/basics/time-space-complexity',
6 | 'roadmap/basics/other-important-things',
7 | ],
8 | STL: [
9 | 'roadmap/stl/stl-tutorials',
10 | 'roadmap/stl/stl-problems',
11 | 'roadmap/stl/stl-editorials',
12 | 'roadmap/stl/implementation-and-regular-contests',
13 | ],
14 | 'Number Theory': [
15 | 'roadmap/number-theory/number-theory-tutorials',
16 | 'roadmap/number-theory/number-theory-problems',
17 | ],
18 | 'Binary Search': [
19 | 'roadmap/binary-search/binary-search-tutorials',
20 | 'roadmap/binary-search/binary-search-problems',
21 | ],
22 | 'Graph Theory': [
23 | 'roadmap/graphs/graph-tutorials',
24 | 'roadmap/graphs/graph-problems',
25 | ],
26 | 'Programming Techniques': [
27 | 'roadmap/programming-techniques/greedy-tutorials',
28 | 'roadmap/programming-techniques/dynamic-programming-tutorials',
29 | 'roadmap/programming-techniques/programming-techniques-problems',
30 | ],
31 | 'Advanced': [
32 | 'roadmap/advanced/dp-on-graphs',
33 | 'roadmap/advanced/dp-with-bitmasks',
34 | ],
35 | },
36 | contests: {
37 | 2020: ['contests/2020/number-theory-and-bs'],
38 | },
39 | }
40 |
--------------------------------------------------------------------------------
/docs/roadmap/stl/implementation-and-regular-contests.md:
--------------------------------------------------------------------------------
1 | ---
2 | id: implementation-and-regular-contests
3 | title: Implementation and Regular Contests
4 | sidebar_label: Implementation and Regular Contests
5 | description: Implementation and Regular Contests cyberlabs
6 | ---
7 |
8 | ## Hackerrank Implementation
9 |
10 | - Solve the implementation problems at least, until you get 5 or 6 star on hackerrank, in problem solving.
11 | - [Link to hackerrank implementation problems](https://www.hackerrank.com/domains/algorithms/implementation)
12 |
13 | ## Regular contests
14 |
15 | As, giving timed contests, helps to handle problems under pressure and boosts your time management skills. Give the contests on various online judges, regularly, as instructed below.
16 |
17 | :::note
18 | Try to **upsolve** 1 or 2 problems after every contest. This will help you to improve your problem solving skills, with every contest, at a faster pace. For tips on why upsolving is important and how to upsolve efficiently, watch [this short video](https://www.coursera.org/lecture/competitive-programming-core-skills/upsolving-8Mn6l)
19 | :::
20 |
21 | ### Codeforces
22 |
23 | - Give the Div. 2 and Div. 3 contests on codeforces, regularly
24 |
25 | ### Codechef
26 |
27 | - Give the monthly long challenge on codechef, regularly.
28 |
29 | ### Atcoder
30 |
31 | - Give the beginner contests on atcoder, regularly.
32 |
--------------------------------------------------------------------------------
/docs/roadmap/number-theory/number-theory-tutorials.md:
--------------------------------------------------------------------------------
1 | ---
2 | id: number-theory-tutorials
3 | title: Number Theory Tutorials
4 | sidebar_label: Number Theory Tutorials
5 | description: Number Theory Tutorials by cyberlabs
6 | ---
7 |
8 | Go through these tutorials, in order :
9 |
10 | 1. [Hackerearth tutorial for primes, composites, sieve of erasthones, segmented sieve](https://www.hackerearth.com/practice/math/number-theory/basic-number-theory-2/tutorial/)
11 |
12 | 2. [Read upto "pre-computed primes method", from this article on factorisation](https://cp-algorithms.com/algebra/factorization.html)
13 |
14 | 3. [Number of divisors and Sum of divisors](https://cp-algorithms.com/algebra/divisors.html)
15 |
16 | :::note
17 |
18 | Similarly, also remember the formula for **product of divisors** of a number $n$ :
19 |
20 | $n^{\frac{d(n)}{2}}$
21 |
22 | where $d(n)$ = number of divisors of $n$
23 | :::
24 |
25 | 4. [Hackerearth tutorial on modular arithmetic, GCD, modular exponentiation and Fermat's Theorem](https://www.hackerearth.com/practice/notes/number-theory-1/)
26 |
27 | 5. [CP-algorithms Tutorial for Euler Totient Function (ETF), its properties and applications](https://cp-algorithms.com/algebra/phi-function.html)
28 |
29 | 6. [Hackerearth tutorial for ETF](https://www.hackerearth.com/practice/math/number-theory/totient-function/tutorial/)
30 |
31 | ## Additional Resources
32 |
33 | - [Revise Permutations and Combinations](https://www.topcoder.com/community/competitive-programming/tutorials/basics-of-combinatorics/)
34 |
--------------------------------------------------------------------------------
/docs/roadmap/binary-search/binary-search-tutorials.md:
--------------------------------------------------------------------------------
1 | ---
2 | id: binary-search-tutorials
3 | title: Binary Search Tutorials
4 | sidebar_label: Binary Search Tutorials
5 | description: Binary Search Tutorials by cyberlabs
6 | ---
7 |
8 | ## Binary search
9 |
10 | 1. Watch [Binary search video by Errichto](https://youtu.be/GU7DpgHINWQ)
11 | 2. Read [Top Coder article for Binary search](https://www.topcoder.com/community/competitive-programming/tutorials/binary-search/)
12 |
13 | ## Ternary search
14 |
15 | 1. Read [CP-algorithms article on ternary search](https://cp-algorithms.com/num_methods/ternary_search.html)
16 | 2. Read [Hackerearth article on ternary search](https://www.hackerearth.com/practice/algorithms/searching/ternary-search/tutorial/)
17 |
18 | :::tip
19 |
20 | **Note**: Ternary search problems can also be solved using binary search, by considering the function `g(x) = f(x) > f(x-1)` as a monotonic function. See [this blog](https://codeforces.com/blog/entry/11497) for more details.
21 |
22 | :::
23 |
24 | ## Session slides
25 |
26 | - The whiteboard slides, used during the session on Binary search, are available [here](https://drive.google.com/file/d/1iMdFkRyPKw7YjXGNzCh002QbHWGM-VK9/view?usp=sharing)
27 |
28 | - The whiteboard slides, used during the session on Ternary search, are available [here](https://drive.google.com/file/d/18WOB_HSEK2nBZFlM0fsL46g_dRlbEFBa/view?usp=sharing)
29 |
30 | ## Additional resources
31 |
32 | - Watch [this series of 5 short lectures on Binary search](https://codeforces.com/edu/course/2/lesson/6) by codeforces
33 |
--------------------------------------------------------------------------------
/docs/roadmap/stl/stl-tutorials.md:
--------------------------------------------------------------------------------
1 | ---
2 | id: stl-tutorials
3 | title: STL Tutorials
4 | sidebar_label: STL Tutorials
5 | description: Best C++ STL tutorials by cyberlabs
6 | ---
7 |
8 | :::important
9 |
10 | STL provides the ready-made implementation of some frequently used data structures and algorithms. Don’t underestimate the power of STL !
11 |
12 | :::
13 |
14 | Go through these tutorials once, and do note the time complexities of each function :
15 |
16 | - [STL Part 1](https://www.topcoder.com/community/competitive-programming/tutorials/power-up-c-with-the-standard-template-library-part-1/)
17 | - [STL Part 2](https://www.topcoder.com/community/competitive-programming/tutorials/power-up-c-with-the-standard-template-library-part-2/)
18 |
19 | :::tip
20 |
21 | **Note:** Instead of including every header file, you may use :
22 |
23 | ```cpp
24 | #include
25 | ```
26 | This header file imports all other header files . Thus, saves time
27 | :::
28 |
29 | ## Session Slides
30 |
31 | - The slides, used during the session on STL, are available [here](https://docs.google.com/presentation/d/1bFEd_vXsWd75aALqKXSnHY2SGh7RsZJ_-ePCTcKUEIs/edit?usp=sharing)
32 |
33 | ## Additional Resources
34 |
35 | - [Hackerearth STL Tutorial](https://www.hackerearth.com/practice/notes/standard-template-library/)
36 | - [C++ STL : Policy based data structures](https://codeforces.com/blog/entry/11080)
37 | - [CPP Reference STL](https://www.cplusplus.com/reference/stl/)
38 | - [Geeks STL Reference](https://www.geeksforgeeks.org/the-c-standard-template-library-stl/)
39 |
--------------------------------------------------------------------------------
/docs/roadmap/basics/other-important-things.md:
--------------------------------------------------------------------------------
1 | ---
2 | id: other-important-things
3 | title: Some other important things
4 | sidebar_label: Some other important things
5 | description: Some important things to know, before starting competitive programming
6 | ---
7 |
8 | ## Fast Input/Output
9 |
10 | - In C++, for fast input / output, while using cin and cout, use these lines :
11 |
12 | ```cpp
13 | int main()
14 | {
15 | ios_base::sync_with_stdio(false);
16 | cin.tie(NULL);
17 | cout.tie(NULL);
18 | // all your code below this
19 | ….
20 | }
21 | ```
22 | - These above lines makes cin, cout work faster. It is advised to add these statements in all your codes.
23 |
24 | :::tip
25 |
26 | Also for fast output, **don’t use cout << endl**. Instead **use cout << ‘\n’ for a newline**. It works faster.
27 |
28 | :::
29 |
30 | ## Avoid common mistakes
31 |
32 | - You must become familiar with the following :
33 | - Common errors on online judges like TLE, MLE, Runtime error, Compile error and how to get rid of them
34 | - When does overflow occur ? How to prevent overflow ?
35 | - How to compare floating point values, like doubles ? (we can’t simply use == )
36 |
37 | - You may refer to [this great blog](https://www.hackerearth.com/practice/notes/getting-started-with-the-sport-of-programming/), to get familiar with these.
38 |
39 | :::tip
40 |
41 | To get rid of type-casting int to long long multiple times for preventing overflow, you may want to write this at the top:
42 | ```cpp
43 | #define int long long
44 | ```
45 | For this to work, also replace ```int main()``` by :
46 | ```cpp
47 | int32_t main()
48 | ```
49 | :::
50 |
51 | ## Session Slides
52 |
53 | - The whiteboard slides, used during the introduction session, are available [here](https://drive.google.com/file/d/1vaPTgV7WbH4jE3hh-0RNtfzyAZTDs-Sj/view?usp=sharing)
--------------------------------------------------------------------------------
/src/css/custom.css:
--------------------------------------------------------------------------------
1 | /* stylelint-disable docusaurus/copyright-header */
2 | /**
3 | * Any CSS included here will be global. The classic template
4 | * bundles Infima by default. Infima is a CSS framework designed to
5 | * work well for content-centric websites.
6 | */
7 |
8 | /* You can override the default Infima variables here. */
9 | :root{
10 | --ifm-color-primary-lightest: #e2e2fc;
11 | --ifm-color-primary-lighter: #b0b0f6;
12 | --ifm-color-primary-light: #a0a0f4;
13 | --ifm-color-primary: #7f7ff0;
14 | --ifm-color-primary-dark: #5e5eec ;
15 | --ifm-color-primary-darker: #4e4eea ;
16 | --ifm-color-primary-darkest: #1c1ce4 ;
17 | }
18 |
19 |
20 | .docusaurus-highlight-code-line {
21 | background-color: rgb(72, 77, 91);
22 | display: block;
23 | margin: 0 calc(-1 * var(--ifm-pre-padding));
24 | padding: 0 var(--ifm-pre-padding);
25 | }
26 |
27 | .header-github-link:before {
28 | content: "";
29 | width: 24px;
30 | height: 24px;
31 | display: flex;
32 | background: url(data:image/svg+xml;charset=utf-8,%3Csvg viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12'/%3E%3C/svg%3E) no-repeat;
33 | }
--------------------------------------------------------------------------------
/docs/roadmap/binary-search/binary-search-problems.md:
--------------------------------------------------------------------------------
1 | ---
2 | id: binary-search-problems
3 | title: Practice Problems for Binary Search
4 | sidebar_label: Practice Problems for Binary Search
5 | description: Binary Search practice problems by cyberlabs
6 | ---
7 |
8 | ## Binary search
9 |
10 | 1. [BSEARCH1 - Binary search](https://www.spoj.com/problems/BSEARCH1/)
11 | 2. [AGGRCOW - Aggressive cows](https://www.spoj.com/problems/AGGRCOW/)
12 | 3. [EKO - Eko](https://www.spoj.com/problems/EKO/)
13 | 4. [NOTATRI - Not a Triangle](https://www.spoj.com/problems/NOTATRI/)
14 | 5. [HACKRNDM - Hacking the random number generator](https://www.spoj.com/problems/HACKRNDM/)
15 | 6. [PIE - Pie](https://www.spoj.com/problems/PIE/)
16 | 7. [991/C - Candies](https://codeforces.com/problemset/problem/991/C)
17 | 8. [1119/B - Alyona and a Narrow Fridge](https://codeforces.com/problemset/problem/1119/B)
18 | 9. [Hackerland Radio Transmitters](https://www.hackerrank.com/challenges/hackerland-radio-transmitters/problem)
19 | 10. [760/B - Frodo and pillows](https://codeforces.com/problemset/problem/760/B)
20 | 11. [BOOKS1 - Copying Books](https://www.spoj.com/problems/BOOKS1/)
21 | 12. [1370/D - Odd-Even Subsequence](https://codeforces.com/contest/1370/problem/D)
22 | 13. [1195/B - Sport Mafia](https://codeforces.com/problemset/problem/1195/B)
23 | 14. [66/B - Energy Exchange](https://codeforces.com/problemset/problem/68/B)
24 | 15. [1166/C - A Tale of Two Lands](https://codeforces.com/problemset/problem/1166/C)
25 | 16. [448/D - Multiplication Table](https://codeforces.com/problemset/problem/448/D)
26 | 17. [779/D - String Game](https://codeforces.com/contest/779/problem/D)
27 | 18. [1029/F - Multicolored Markers](https://codeforces.com/contest/1029/problem/F)
28 | 19. [1409/E - Two Platforms](https://codeforces.com/problemset/problem/1409/E)
29 | 20. [1359/C - Mixing water](https://codeforces.com/problemset/problem/1359/C)
30 |
31 | ## Ternary search
32 |
33 | 1. [The exam](https://www.hackerearth.com/practice/algorithms/searching/ternary-search/practice-problems/algorithm/the-exam/description/)
34 | 2. [Is this JEE ?](https://www.codechef.com/problems/ICM2003)
35 |
--------------------------------------------------------------------------------
/docs/roadmap/advanced/dp-on-graphs.md:
--------------------------------------------------------------------------------
1 | ---
2 | id: dp-on-graphs
3 | title: DP on Graphs
4 | sidebar_label: DP on Graphs
5 | description: DP on graphs tutorials by cyberlabs
6 | ---
7 |
8 | ## DP on Graphs
9 |
10 | :::tip
11 |
12 | Make sure you know the basics of graphs, DFS, topological sorting, SCC and DP before moving towards this section.
13 |
14 | :::
15 |
16 | 1. Read the sections 16.2, 16.3, 16.4, 18.1 and 18.3 from [CPH book](https://usaco.guide/CPH.pdf#page=161) to understand DP on graphs, successor / functional graphs and binary lifting.
17 |
18 | 2. Go through the algorithm for finding LCA of two nodes in any tree using binary lifting and binary search from [here](https://cp-algorithms.com/graph/lca_binary_lifting.html)
19 |
20 | ## Session slides
21 |
22 | 1. [Day 1 - DP on graphs, DP on directed graph with cycles, successor/functional graphs, binary lifting, Floyd's cycle detection algorithm (Hare and tortoise algorithm) for successor graphs](https://docs.google.com/document/d/14w8FzqCl4kgYeOVxFoWsO3VkLKTIiUo9nvMz6JCQmmM/edit#heading=h.vf6ljt10081x)
23 |
24 | ## Additional Resource
25 |
26 | 1. If you want to learn more about DP on trees, through some problems, you can refer [this CF blog](https://codeforces.com/blog/entry/20935)
27 |
28 | ## Practice Problems
29 |
30 | 1. [CSES - Game Routes](https://cses.fi/problemset/task/1681)
31 | 2. [Codechef - Visiting Friends](https://www.codechef.com/problems/MCO16405)
32 | 3. [CSES - Planets Queries I](https://cses.fi/problemset/task/1750)
33 | 4. [CSES - Company Queries I](https://cses.fi/problemset/task/1687)
34 | 5. [CSES - Planets Cycles](https://cses.fi/problemset/task/1751)
35 | 6. [Hackerrank - Detect cycle in a linked list](https://www.hackerrank.com/challenges/detect-whether-a-linked-list-contains-a-cycle/problem)
36 | 7. [Leetcode - Linked list cycle II](https://leetcode.com/problems/linked-list-cycle-ii/)
37 | 8. [1020/B - Badge](https://codeforces.com/contest/1020/problem/B)
38 | 9. [SPOJ - DAGCNT2](https://www.spoj.com/problems/DAGCNT2/)
39 | 10. [918/D - MADMAX](https://codeforces.com/problemset/problem/918/D)
40 | 11. [CSES - Investigation](https://cses.fi/problemset/task/1202/)
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Competitive Programming Guide
2 |
3 | A complete roadmap for competitive programming
4 |
5 | View live at https://cp.cyberlabs.club
6 |
7 | [](https://app.netlify.com/sites/cp-cyberlabs/deploys)
8 |
9 | ## Want to contribute ?
10 |
11 | Refer our [CONTRIBUTING.md](https://github.com/Cyber-Labs/cp-roadmap/blob/master/CONTRIBUTING.md) for "How to contribute ?".
12 |
13 | ## Built With
14 |
15 | - [Docusaurus 2](https://v2.docusaurus.io/)
16 |
17 | ## Running
18 |
19 | 1. After cloning this repository, run the following command in your terminal :
20 |
21 | ```
22 | npm install
23 | ```
24 |
25 | 2. Then run `npm start` :
26 |
27 | ```
28 | npm start
29 | ```
30 |
31 | 3. The website will start running at http://localhost:3000/
32 |
33 | ## File Structure
34 |
35 | - [blog](#blog)
36 | - [docs](#docs)
37 | - `roadmap`
38 | - `contests`
39 | - `tools.md`
40 | - [src](#src)
41 | - `css`
42 | - `pages`
43 | - [static](#static)
44 | - `img`
45 | - `sidebars.js`
46 | - `docusaurus.config.js`
47 |
48 | ### Blog
49 |
50 | - The `blog` directory contains the blog files with names in the format `YYYY-MM-DD-my-blog-post-title.md`
51 | - For the format of content of a blog file, you may refer any of the blogs present already or refer [adding a blog post](https://v2.docusaurus.io/docs/blog/#adding-posts)
52 |
53 | ### Docs
54 |
55 | - The `docs` directory contains markdown files for content of the `roadmap`, `contests` and `tools` sections.
56 | - Every document has a unique `id`
57 | - For displaying mathematical expressions, [LaTeX](https://artofproblemsolving.com/wiki/index.php/LaTeX:Symbols) is used. Just write the latex expression inside `$` symbols. For eg. `$x = 3$`
58 | - For all the files, whose link should appear in the sidebar, the details should be added in the file `sidebars.js`. For more details, refer [sidebar object](https://v2.docusaurus.io/docs/docs-introduction#sidebar-object)
59 |
60 | ### Src
61 |
62 | - Contains the code in ReactJS for the home page and the styling of website.
63 |
64 | ### Static
65 |
66 | - All the static images, etc. used in the website are placed in the `static/img` directory.
67 |
--------------------------------------------------------------------------------
/blog/2020-09-22-learning-cpp-as-a-beginner.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Learning C++ as a beginner
3 | author: Chirag Jain
4 | author_title: Incoming SDE Intern @ Microsoft
5 | author_url: https://www.facebook.com/profile.php?id=100005981172975
6 | author_image_url: https://scontent.fbho1-2.fna.fbcdn.net/v/t1.0-9/118854839_1452819681594057_8968804622460589631_n.jpg?_nc_cat=103&_nc_sid=09cbfe&_nc_ohc=syNqJZRSahUAX_2msXL&_nc_ht=scontent.fbho1-2.fna&oh=41103a389ae68535c666033fe116301e&oe=5F931B46
7 | tags: [c++, beginner, learn from scratch]
8 | ---
9 |
10 | This blog, is for those who are not familiar with the C programming language and want to learn C++, mainly for competitive programming.
11 |
12 |
13 |
14 | ## Tutorial
15 |
16 | Read and try the various syntax given in the following sections, from [this tutorial](https://www.tutorialspoint.com/cplusplus/index.htm) :
17 | - C++ Basic syntax
18 | - C++ Comments
19 | - C++ Data Types
20 | - C++ Variable Types
21 | - C++ Operators
22 | - C++ Loop Types
23 | - C++ Decision Making
24 | - C++ Arrays
25 | - C++ Strings
26 | - C++ Functions
27 |
28 | If sufficient time is available, you may also want to read the following sections :
29 | - C++ Pointers
30 | - C++ References
31 | - C++ Structures
32 |
33 | ## Practise
34 |
35 | ### For windows users
36 |
37 | To practice writing programs in windows, we would suggest you to download **CodeBlocks IDE**. To learn how to download codeblocks, watch [this video](https://www.youtube.com/watch?v=aS5_jrIbKmA) ( Upto 4:30 minute )
38 |
39 | To learn to create, compile and run C++ files :
40 | 1. Open Codeblocks
41 | 2. File ⇒ New ⇒ Empty File.
42 | 3. Enter your code.
43 | 4. Save the file as "Hello.cpp" (or any other name) in your some directory.
44 | 5. Select "Build" menu ⇒ Build (or press Ctrl-F9).
45 | 6. Run: Select "Build" menu ⇒ Run (or press Ctrl-F10).
46 |
47 | ### For linux users
48 |
49 | To practice writing programs, we would suggest you to download **Geany IDE**. To learn how to download and setup geany, watch [this video](https://www.youtube.com/watch?v=ePZEkbbf3fc)
50 |
51 | To learn to create, compile and run C++ files :
52 | 1. Open Geany
53 | 2. File ⇒ New ⇒ Empty File.
54 | 3. Enter your code.
55 | 4. Save the file as "Hello.cpp" (or any other name) in your some directory.
56 | 5. Select "Build" menu ⇒ Build (or press Ctrl-F9).
57 | 6. Run: Select "Build" menu ⇒ Execute (or press Ctrl-F5).
58 |
--------------------------------------------------------------------------------
/docs/roadmap/stl/stl-problems.md:
--------------------------------------------------------------------------------
1 | ---
2 | id: stl-problems
3 | title: Practice Problems for STL
4 | sidebar_label: Practice Problems for STL
5 | description: STL practice problems by cyberlabs
6 | ---
7 |
8 | ## Hackerrank
9 |
10 | 1. [Hackerrank STL problems](https://www.hackerrank.com/domains/cpp/stl)
11 | 2. [Balanced brackets](https://www.hackerrank.com/challenges/balanced-brackets/problem)
12 | 3. [Queries with fixed length](https://www.hackerrank.com/challenges/queries-with-fixed-length/problem)
13 |
14 | ## SPOJ
15 |
16 | 1. [SANTA1 - Reindeer Games](https://www.spoj.com/problems/SANTA1/)
17 | 2. [ACMCEG2B - FIGUREFUL](https://www.spoj.com/problems/ACMCEG2B/)
18 | 3. [SORT2D - 2D-SORT](https://www.spoj.com/problems/SORT2D/)
19 | 4. [DOTAA2 - HELP NERUBAN](https://www.spoj.com/problems/DOTAA2/)
20 | 5. [AMR12G - The Glittering Caves of Aglarond](https://www.spoj.com/problems/AMR12G/)
21 | 6. [HOMO - Homo or Hetero](https://www.spoj.com/problems/HOMO/)
22 | 7. [BYTESM2 - Philosophers Stone](https://www.spoj.com/problems/BYTESM2/)
23 | 8. [HISTOGRA - Largest Rectangle in a Histogram](https://www.spoj.com/problems/HISTOGRA/)
24 | 9. [SBANK - Sorting Bank Accounts](https://www.spoj.com/problems/SBANK/)
25 | 10. [PQUEUE - Printer Queue](https://www.spoj.com/problems/PQUEUE/)
26 | 11. [PRO - Promotion](https://www.spoj.com/problems/PRO/)
27 | 12. [STPAR - Street Parade](https://www.spoj.com/problems/STPAR/)
28 |
29 | ## Codeforces
30 |
31 | 1. [782/A - Andryusha and Socks](https://codeforces.com/problemset/problem/782/A)
32 | 2. [22/A- Second Order Statistics](https://codeforces.com/problemset/problem/22/A)
33 | 3. [704/A - Thor](http://codeforces.com/problemset/problem/704/A)
34 | 4. [546/C - Soldier and Cards](https://codeforces.com/problemset/problem/546/C)
35 | 5. [799/B - T-shirt buying](https://codeforces.com/problemset/problem/799/B)
36 | 6. [1353/D - Constructing the Array](https://codeforces.com/contest/1353/problem/D)
37 | 7. [733/D - Kostya the Sculptor](https://codeforces.com/contest/733/problem/D)
38 | 8. [4/C - Registration system](http://codeforces.com/problemset/problem/4/C)
39 |
40 | ## Hackerearth
41 |
42 | [Code Monk STL Problems](https://www.hackerearth.com/challenges/competitive/code-monk-c-stl/problems/)
43 |
44 | ## Codechef
45 |
46 | 1. [ANUUND - Ups and Downs](https://www.codechef.com/problems/ANUUND)
47 | 2. [ANUMLA - Mahesh and his lost array](https://www.codechef.com/COOK51/problems/ANUMLA)
48 |
--------------------------------------------------------------------------------
/docs/tools.md:
--------------------------------------------------------------------------------
1 | ---
2 | id: tools
3 | title: Important Tools
4 | sidebar_label: Important Tools
5 | description: Important Tools for competitive programmers, by cyberlabs
6 | ---
7 |
8 | ## Coding Schedule
9 |
10 | It is recommended to install both, the browser extension in your PC, as well as the mobile app, from [here](https://codingschedule.gitlab.io/), to get the notifications of the ongoing contests, regularly.
11 |
12 | ## The On-Line Encyclopedia of Integer Sequences (OEIS)
13 |
14 | [OEIS](https://oeis.org/) has a very huge database of countless integer sequences and patterns. It also features a powerful search engine. Sometimes a seemingly difficult combinatorics problem could be equivalent to a simple integer sequence.
15 |
16 | ## CP Editor
17 |
18 | [CP Editor](https://cpeditor.org/) is specially designed for competitive programming. It helps you focus on your algorithms and automates compilation, execution and testing of your code. It even fetches test cases for you from different platforms and submits solutions to Codeforces!
19 |
20 | ## CSAcademy online IDE
21 |
22 | [CSAcademy online IDE](https://csacademy.com/workspace/) has all the features of an ideal IDE, along with a workspace which helps you to work on several files simultaneously and share your code online, easily. Very useful especially when you're trying to get someone else to look into your code.
23 |
24 | ## Difference Checkers
25 |
26 | **Stress testing** is a great way to find out a bug in an algorithm. Stress tests mean to generate a large set of random test cases and then, to check if the efficient algorithm and the brute force algorithm produce the same output. The tools that can be used for this are [CSAcademy Diffing Tool](https://csacademy.com/app/diffing_tool/) and [Diffchecker.com](https://www.diffchecker.com/)
27 |
28 | ## Algorithms Visualisation
29 |
30 | ### VisuAlgo
31 |
32 | [VisuAlgo](https://visualgo.net/en) is a website perfect for people trying to get an intuitive feel for algorithms. It features animations for the most common data structures and algorithms.
33 |
34 | ### Algorithm Visualizer
35 |
36 | [Algorithm Visualizer](https://algorithm-visualizer.org/) is another website to visualize algorithms, data strucutres and the operations we can do on those data structures. This contains visualisation of almost all the algorithms and data structures, that are generally used.
37 |
38 | ### Recursion Visualizer for any recursion written in JavaScript
39 | [Recursion](https://recursion.now.sh/) is a website where you can write a recursive code and see the recursion tree come alive. Make sure to try it out, especially to better understand dp and backtracking problems.
40 |
--------------------------------------------------------------------------------
/docs/roadmap/advanced/dp-with-bitmasks.md:
--------------------------------------------------------------------------------
1 | ---
2 | id: dp-with-bitmasks
3 | title: DP with Bitmasks
4 | sidebar_label: DP with Bitmasks
5 | description: DP with bitmasks tutorials by cyberlabs
6 | ---
7 |
8 | ## Bitwise operations and Bitmasks
9 |
10 | ### Tutorials
11 |
12 | 1. Go through [this CF blog](https://codeforces.com/blog/entry/73490) for an idea of the bitwise operations and the concept of bitmasks.
13 |
14 | 2. Go through [this CF blog](https://codeforces.com/blog/entry/73558) for understanding __builtin_popcount() function and bitsets
15 |
16 | ### Session slides
17 |
18 | 1. [Part 1 - Bitwise Operations and their applications, preventing overflows when using left shift, Bitmasks](https://docs.google.com/document/d/1kRRmdmZlmzplvmasmbYtr_79qc1EfOOJmqm1VHaBZkc/edit#). The youtube stream in which these topics were discussed can be found [here](https://www.youtube.com/watch?v=95o1lWeV7fY)
19 |
20 | ### Practice problems
21 |
22 | 1. [Hackerrank - Counter Game](https://www.hackerrank.com/challenges/counter-game/problem)
23 | 2. [Hackerrank - Lovely Integer](https://www.hackerrank.com/challenges/lonely-integer/problem)
24 | 3. [Hackerrank - XOR Sequence](https://www.hackerrank.com/challenges/xor-se/problem)
25 | 4. [Hackerrank AND product](https://www.hackerrank.com/challenges/and-product/problem)
26 | 5. [Hackerrank - SUM vs XOR](https://www.hackerrank.com/challenges/sum-vs-xor/problem)
27 | 6. [Hackerrank - Flipping Bits](https://www.hackerrank.com/challenges/flipping-bits/problem)
28 | 7. [Hackerrank - Sansa and XOR](https://www.hackerrank.com/challenges/sansa-and-xor/problem)
29 | 8. [1097/B - Petr and a Combination Lock](https://codeforces.com/problemset/problem/1097/B)
30 |
31 | ## DP with bitmasking
32 |
33 | ### Tutorials
34 |
35 | 1. Learn the algorithm for iterating through all the submasks of a mask from [this article of cp-algorithms](https://cp-algorithms.com/algebra/all-submasks.html)
36 |
37 | 2. Go through [this article on hackerearth](https://www.hackerearth.com/practice/algorithms/dynamic-programming/bit-masking/tutorial/) for understanding DP with bitmasks.
38 |
39 | ### Session slides
40 |
41 | 1. [Part 2 - DP with bitmasks](https://docs.google.com/document/d/1kRRmdmZlmzplvmasmbYtr_79qc1EfOOJmqm1VHaBZkc/edit#). The youtube stream in which these topics were discussed can be found [here](https://www.youtube.com/watch?v=8HOIj0RgcCU)
42 |
43 | ### Practice problems
44 |
45 | 1. [SPOJ - ASSIGN](https://www.spoj.com/problems/ASSIGN/)
46 | 2. [Atcoder DP - U (Grouping)](https://atcoder.jp/contests/dp/tasks/dp_u)
47 | 3. [Hackerearth - Mehta and tricky triplets](https://www.hackerearth.com/practice/algorithms/dynamic-programming/bit-masking/practice-problems/algorithm/mehta-and-the-tricky-triplets/)
48 | 4. [Leetcode - Number of ways to wear different hats to each other](https://leetcode.com/problems/number-of-ways-to-wear-different-hats-to-each-other/)
49 | 5. [Hackerrank - Synchronous shopping](https://www.hackerrank.com/challenges/synchronous-shopping)
50 | 6. [1043/F - Make It One](https://codeforces.com/contest/1043/problem/F)
--------------------------------------------------------------------------------
/docs/roadmap/programming-techniques/dynamic-programming-tutorials.md:
--------------------------------------------------------------------------------
1 | ---
2 | id: dynamic-programming-tutorials
3 | title: DP Tutorials
4 | sidebar_label: DP Tutorials
5 | description: DP (dynamic programming) Tutorials by cyberlabs
6 | ---
7 |
8 | ## Basic Dynamic Programming
9 |
10 | 1. Watch [DP video by Errichto](https://www.youtube.com/watch?v=YBSt1jYwVfU)
11 | 2. Read [hackerearth article for DP](https://www.hackerearth.com/practice/algorithms/dynamic-programming/introduction-to-dynamic-programming-1/tutorial/)
12 |
13 | :::tip
14 |
15 | **Note**: For visualising recursion tree of common problems like finding Fibonacci number, coin change problem, etc. you may use [Recursion Tree Visualisation](https://recursion.now.sh/). Observe that DP can be applied only when there are **overlapping subproblems**.
16 |
17 | :::
18 |
19 | ## 2-D Dynamic Programming
20 |
21 | 1. Read [hackerearth article on 2-D Dynamic Programming](https://www.hackerearth.com/practice/algorithms/dynamic-programming/2-dimensional/tutorial/)
22 | 2. Watch [Video on "Coin change" (double counting) problem by Errichto](https://www.youtube.com/watch?v=1mtvm2ubHCY)
23 | 3. Watch [Video on "Line of wines" problem by Errichto](https://www.youtube.com/watch?v=pwpOC1dph6U)
24 |
25 | ## State Space Reduction
26 |
27 | 1. Read [hackerearth article on state space reduction](https://www.hackerearth.com/practice/algorithms/dynamic-programming/state-space-reduction/tutorial/)
28 |
29 | :::tip
30 |
31 | You must take care of time limit and especially memory limit while using DP. Often problems are framed in such a way that it wants you to use your memory smartly.
32 |
33 | :::
34 |
35 | ## Session slides
36 |
37 | 1. [Day 1 - Intuition for DP, Minimum coins, Fibonacci number, Longest Increasing Subsequence(LIS), Coin Change, Subset Sum Problem](https://docs.google.com/document/d/1l_dbQAeIqfNJtV0KH4aEPdbcgJvg-H2i0YHAKw2x0qo/)
38 |
39 | 1. [Day 2 - Staircase climbing problem and its variations, Basics of PnC, Wildcard Matching Problem](https://docs.google.com/document/d/1CBUGWT-kswx_9u2EfharkHmiBURRDXMuGV87l26v2po/)
40 |
41 | ## Additional Resources
42 |
43 | 1. You can also learn from Digit DP, a technique used to solve problems from [this article](https://www.hackerrank.com/topics/digit-dp)
44 |
45 | 2. You can also go through this [hackerrank article](https://www.hackerrank.com/topics/dynamic-programming) for many standard DP problems.
46 |
47 | 3. A great lecture series of MIT for some standard problems of dynamic programming :
48 |
49 | [Lecture 1 - Fibonacci and shortest paths](https://www.youtube.com/watch?v=OQ5jsbhAv_M&index=1&list=PLfMspJ0TLR5HRFu2kLh3U4mvStMO8QURm)
50 |
51 | [Lecture 2 - Text Justification, Blackjack](https://www.youtube.com/watch?v=ENyox7kNKeY&index=2&list=PLfMspJ0TLR5HRFu2kLh3U4mvStMO8QURm)
52 |
53 | [Lecture 3 - Parenthesization, Edit Distance, Knapsack](https://www.youtube.com/watch?v=ocZMDMZwhCY)
54 |
55 | [Lecture 4 - Guitar Fingering, Tetris, Super Mario Bros](https://www.youtube.com/watch?v=tp4_UXaVyx8&list=PLfMspJ0TLR5HRFu2kLh3U4mvStMO8QURm&index=4)
56 |
--------------------------------------------------------------------------------
/docs/roadmap/number-theory/number-theory-problems.md:
--------------------------------------------------------------------------------
1 | ---
2 | id: number-theory-problems
3 | title: Practice Problems for Number Theory
4 | sidebar_label: Practice Problems for Number Theory
5 | description: Number Theory practice problems by cyberlabs
6 | ---
7 |
8 | ## Primes and factorisation
9 |
10 | 1. [TDPRIMES - Printing some primes](https://www.spoj.com/problems/TDPRIMES/)
11 | 2. [BREAKING - Number Breaking](https://www.spoj.com/problems/BREAKING/)
12 | 3. [1165/D - Almost All Divisors](https://codeforces.com/problemset/problem/1165/D)
13 | 4. [230/B - T-primes](https://codeforces.com/problemset/problem/230/B)
14 | 5. [59/B - Fortune Telling](https://codeforces.com/problemset/problem/59/B)
15 | 6. [CDRSANJ - CODER FIRST PROBLEM](https://www.spoj.com/problems/CDRSANJ/)
16 | 7. [PRIME1 - Prime Generator](https://www.spoj.com/problems/PRIME1/)
17 | 8. [26/A - Almost Prime](https://codeforces.com/problemset/problem/26/A)
18 | 9. [VECTAR8 - Primal Fear](https://www.spoj.com/problems/VECTAR8/)
19 | 10. [776/B - Sherlock and his girlfriend](https://codeforces.com/problemset/problem/776/B)
20 | 11. [HS08PAUL - A conjecture of Paul Erdős](https://www.spoj.com/problems/HS08PAUL/)
21 | 12. [NGIRL - Namit In Trouble](https://www.spoj.com/problems/NGIRL/)
22 | 13. [DCEPC505 - Bazinga!](https://www.spoj.com/problems/DCEPC505/)
23 | 14. [Project Euler #134: Prime pair connection](https://www.hackerrank.com/contests/projecteuler/challenges/euler134/problem)
24 |
25 | ## MOD and GCD
26 |
27 | 1. [John and GCD List](https://www.hackerrank.com/challenges/john-and-gcd-list/problem)
28 | 2. [Maximise GCD](https://www.hackerearth.com/problem/algorithm/maximise-gcd-4126af7b/)
29 | 3. [Sherlock and GCD](https://www.hackerrank.com/challenges/sherlock-and-gcd/problem)
30 | 4. [1203/C - Common Divisors](https://codeforces.com/contest/1203/problem/C)
31 | 5. [1245/A - Good ol' Numbers Coloring](https://codeforces.com/problemset/problem/1245/A)
32 | 6. [Rearrange array using only O(1) extra space](https://practice.geeksforgeeks.org/problems/rearrange-an-array-with-o1-extra-space/0)
33 | 7. [GCDMOD](https://www.codechef.com/problems/GCDMOD)
34 | 8. [582/A - GCD Table](https://codeforces.com/problemset/problem/582/A)
35 | 9. [1285/C - Fadi and LCM](https://codeforces.com/problemset/problem/1285/C)
36 | 10. [1266/C - Diverse Matrix](https://codeforces.com/problemset/problem/1266/C)
37 |
38 | ## Binary Exponentiation, Fermat’s Theorem and ETF
39 |
40 | 1. [LASTDIG - The last digit](https://www.spoj.com/problems/LASTDIG/)
41 | 2. [ETF - Euler Totient Function](https://www.spoj.com/problems/ETF/)
42 | 3. [1295/D - Same GCDs](https://codeforces.com/contest/1295/problem/D)
43 | 4. [COZIE](https://www.codechef.com/problems/COZIE)
44 | 5. [SMPLSUM](https://www.codechef.com/problems/SMPLSUM)
45 | 6. [LCMSUM - LCM Sum](https://www.spoj.com/problems/LCMSUM/)
46 | 7. [Find a^(b^c) mod (10^9+7)](https://cses.fi/problemset/task/1712)
47 |
48 | ## Combinatorics Problems
49 |
50 | 1. [Sherlock and Pairs](https://www.hackerrank.com/challenges/sherlock-and-pairs)
51 | 2. [294/C - Shaass and Lights](https://codeforces.com/problemset/problem/294/C)
52 | 3. [1236/B - Alice and the List of Presents](https://codeforces.com/problemset/problem/1236/B)
53 | 4. [459/B - Pashmak and Flowers](https://codeforces.com/problemset/problem/459/B)
54 | 5. [1272/C - Yet Another Broken Keyboard](https://codeforces.com/problemset/problem/1272/C)
55 | 6. [Atcode beginner 172 - E (NEQ)](https://atcoder.jp/contests/abc172/tasks/abc172_e)
--------------------------------------------------------------------------------
/docs/roadmap/programming-techniques/programming-techniques-problems.md:
--------------------------------------------------------------------------------
1 | ---
2 | id: programming-techniques-problems
3 | title: Practice Problems
4 | sidebar_label: Practice Problems
5 | description: DP (dynamic programming) and greedy practice problems by cyberlabs
6 | ---
7 |
8 | ## Atcoder DP contest
9 |
10 | Try to solve at least problems A to K from [Atcoder DP contest](https://atcoder.jp/contests/dp/tasks/)
11 |
12 | ## Hackerrank Greedy problems
13 |
14 | Solve the easy and medium greedy problems from [hackerrank](https://www.hackerrank.com/domains/algorithms?filters%5Bsubdomains%5D%5B%5D=greedy&filters%5Bdifficulty%5D%5B%5D=easy&filters%5Bdifficulty%5D%5B%5D=medium)
15 |
16 | ## Easy
17 |
18 | 1. [Kickstart - Allocation](https://codingcompetitions.withgoogle.com/kickstart/round/000000000019ffc7/00000000001d3f56)
19 | 2. [1245/C - Constanze's machine](https://codeforces.com/problemset/problem/1245/C)
20 | 3. [SPOJ - Bytelandian gold coins](https://www.spoj.com/problems/COINS/)
21 | 4. [628/B - New Skateboard](https://codeforces.com/problemset/problem/628/B)
22 | 5. [455/A - Boredom](https://codeforces.com/problemset/problem/455/A%7C)
23 | 6. [Hackerrank - Coin change problem](https://www.hackerrank.com/challenges/coin-change/problem)
24 | 7. [Hackerrank - LIS](https://www.hackerrank.com/challenges/longest-increasing-subsequent/problem)
25 | 8. [SPOJ - Subset Sum](https://www.spoj.com/problems/MAIN72/)
26 | 9. [Hackerrank- LCS](https://www.hackerrank.com/challenges/dynamic-programming-classics-the-longest-common-subsequence/problem)
27 | 10. [SPOJ - EINST](https://www.spoj.com/problems/EINST/)
28 | 11. [SPOJ - ROCK](https://www.spoj.com/problems/ROCK/)
29 | 12. [166/E - Tetrahedron](https://codeforces.com/problemset/problem/166/E)
30 | 13. [Codechef - PLUSMUL](https://www.codechef.com/problems/PLUSMUL/)
31 | 14. [Atcoder - Typical Stairs](https://atcoder.jp/contests/abc129/tasks/abc129_c)
32 | 15. [1195/C - Basketball Excercise](https://codeforces.com/problemset/problem/1195/C)
33 | 16. [474/D - Flowers](https://codeforces.com/problemset/problem/474/D)
34 | 17. [Hackerrank - Wildcard Matching](https://www.hackerrank.com/contests/placement-preparation-1/challenges/string-matching-with-wildcards)
35 | 18. [SPOJ - Edit Distance](https://www.spoj.com/problems/EDIST/)
36 | 19. [Atcoder - Slimes](https://atcoder.jp/contests/dp/tasks/dp_n)
37 |
38 | ## Medium
39 |
40 | 1. [SPOJ - Magic Grid](https://www.spoj.com/problems/AMR11A/)
41 | 2. [Codechef - ALTARAY](https://www.codechef.com/problems/ALTARAY)
42 | 3. [Codechef - DELISH](https://www.codechef.com/problems/DELISH)
43 | 4. [Codechef - DBOY](https://www.codechef.com/problems/DBOY)
44 | 5. [Codechef - XORSUB](https://www.codechef.com/problems/XORSUB)
45 | 6. [Codechef - GRID](https://www.codechef.com/problems/GRID)
46 | 7. [Codechef - TADELIVE](https://www.codechef.com/problems/TADELIVE)
47 | 8. [Codechef - FROGV](https://www.codechef.com/problems/FROGV)
48 | 9. [SPOJ - MDOLLS](http://www.spoj.com/problems/MDOLLS/)
49 | 10. [SPOJ - MSTICK](http://www.spoj.com/problems/MSTICK/)
50 | 11. [SPOJ - MCARDS](http://www.spoj.com/problems/MCARDS/)
51 | 12. [SPOJ - MIXTURES](http://www.spoj.com/problems/MIXTURES/)
52 | 13. [SPOJ SAMER08D](https://www.spoj.com/problems/SAMER08D/)
53 | 14. [SPOJ AIBOHP](https://www.spoj.com/problems/AIBOHP/)
54 | 15. [Codechef MATRIX2](https://www.codechef.com/problems/MATRIX2)
55 | 16. [Codechef AMSGAME2](https://www.codechef.com/problems/AMSGAME2)
56 | 17. [1287/C - Garland](https://codeforces.com/contest/1287/problem/C)
57 |
--------------------------------------------------------------------------------
/docs/roadmap/graphs/graph-tutorials.md:
--------------------------------------------------------------------------------
1 | ---
2 | id: graph-tutorials
3 | title: Graph Theory Tutorials
4 | sidebar_label: Graph Theory Tutorials
5 | description: Best Resources for graph theory by cyberlabs
6 | ---
7 |
8 | ## Basics of Graph and Graph Traversals
9 |
10 | 1. Read [hackerearth article for basic terminology and graph representation](https://www.hackerearth.com/practice/algorithms/graphs/graph-representation/tutorial/)
11 |
12 | 2. Read the following articles for Breadth First Search (BFS) :
13 | (i) [Hackerearth article on BFS](https://www.hackerearth.com/practice/algorithms/graphs/breadth-first-search/tutorial/)
14 | (ii) [CP-Algorithms article on BFS and its applications](https://cp-algorithms.com/graph/breadth-first-search.html)
15 |
16 | 3. Read the following articles for Depth First Search (DFS) :
17 | (i) [Hackerearth article on DFS](https://www.hackerearth.com/practice/algorithms/graphs/depth-first-search/tutorial/)
18 | (ii) [CP-Algorithms article on DFS and its applications](https://cp-algorithms.com/graph/depth-first-search.html)
19 | (iii) [DFS using standard color coding and calculating discovery and finish times](https://www.gatevidyalay.com/depth-first-search-dfs-algorithm/)
20 |
21 | 4. For better understanding of DFS and BFS, [try DFS and BFS visualisation on VisuAlgo](https://visualgo.net/en/dfsbfs)
22 |
23 | ## Topological Sort
24 |
25 | 1. Go through [the hackerearth article](https://www.hackerearth.com/practice/algorithms/graphs/topological-sort/tutorial/) or [CP-Algorithms article](https://cp-algorithms.com/graph/topological-sort.html) for topological sort
26 |
27 | ## Strongly Connected Components (SCC)
28 |
29 | 1. Go through [this article](https://www.hackerearth.com/practice/algorithms/graphs/strongly-connected-components/tutorial/) for Kosaraju's algorithm to find SCC
30 | 2. For C++ implementation of the algorithm to find SCC, refer [this article](https://cp-algorithms.com/graph/strongly-connected-components.html)
31 |
32 | ## Disjoint Set Union (DSU)
33 |
34 | 1. Go through [this article](https://www.hackerearth.com/practice/notes/disjoint-set-union-union-find/) for DSU and its implementation.
35 | 2. For more applications of DSU, refer [this article](https://cp-algorithms.com/data_structures/disjoint_set_union.html)
36 |
37 | ## Shortest Path Algorithms
38 |
39 | - Read [this article](https://www.hackerearth.com/practice/algorithms/graphs/shortest-path-algorithms/tutorial/) for the implementation of the standard shortest path algorithms - Dijkstra, Bellman Ford and Floyd Warshall.
40 |
41 | :::tip
42 | Do note the time and space complexities and the limitations of each method.
43 | :::
44 |
45 | ## Minimum Spanning Tree (MST)
46 |
47 | - Go through [this article](https://www.hackerearth.com/practice/algorithms/graphs/minimum-spanning-tree/tutorial/) for both Kruskal's and Prim's algorithm.
48 |
49 | ## Session slides
50 |
51 | - Slides for basics of graph, graph representation and BFS, are available [here](https://drive.google.com/file/d/18WOB_HSEK2nBZFlM0fsL46g_dRlbEFBa/view)
52 |
53 | - Slides for topological sort and SCC are available [here](https://drive.google.com/file/d/1rk-IvUknpE4RCj8J6S6iL09Y8egV58gA/view?usp=sharing)
54 |
55 | - Slides for shortest-path algo, graph modeling and MST are available [here](https://drive.google.com/file/d/1BuhFA3AqVv7tyH4RG8cxlIhyReTkOPtW/view?usp=sharing)
56 |
57 | ## Additional Resource
58 |
59 | - Sometimes, in problems, it is required to construct a state graph out of the given graphs and then, apply any standard algorithm, to solve the problem. This technique is known as **Graph Modelling**. Refer [this blog](https://codeforces.com/blog/entry/45897) for more about it and some solved example problems.
60 |
--------------------------------------------------------------------------------
/src/pages/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import clsx from 'clsx';
3 | import Layout from '@theme/Layout';
4 | import Link from '@docusaurus/Link';
5 | import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
6 | import useBaseUrl from '@docusaurus/useBaseUrl';
7 | import styles from './styles.module.css';
8 |
9 | const features = [
10 | {
11 | title: 'Understanding algorithms',
12 | imageUrl: 'img/undraw_solution_mindset.svg',
13 | description: (
14 | <>
15 | Understand all the algorithms and data structures well. You should be
16 | able to figure out when to use a particular data structure or algorithm.
17 | It's rightly said that "You don't have to be great to start, but you
18 | have to start to be great."
19 | >
20 | ),
21 | },
22 | {
23 | title: 'Practice',
24 | imageUrl: 'img/undraw_Process.svg',
25 | description: (
26 | <>
27 | Practice the set of questions given to you, after each session. Make
28 | sure, you try them, by yourself. You should look at the editorial,
29 | hints, etc. only when you have given enough time to a question and
30 | still, you are not able to figure out the correct approach. Never say "I
31 | can't" because you can and you will, it takes practice to become
32 | perfect.
33 | >
34 | ),
35 | },
36 | {
37 | title: 'Regular contests',
38 | imageUrl: 'img/undraw_exams.svg',
39 | description: (
40 | <>
41 | As, giving timed contests, helps to handle problems under pressure and
42 | boosts your time management skills. Give the contests on various online
43 | judges, regularly, as instructed here. Try to upsolve 1
44 | or 2 problems after every contest.
45 | >
46 | ),
47 | },
48 | ];
49 |
50 | function Feature({imageUrl, title, description}) {
51 | const imgUrl = useBaseUrl(imageUrl);
52 | return (
53 |
77 |
78 | **Pre-requisite** : Set / Map
79 | **Explanation** : Our task is here to check weather a sock of same type is already on the table or not, and note the no of socks on it and output maximum of all our readings of no socks.
80 | Here it is given that the index of sock is ≤100000 thus you can also make an zero array and each time check if it zero or not (i.e checking weather a socks is on table or not.)
81 | But if index very large or something else as string ,char etc then it better to use set here.
82 |
83 |
84 |
85 |
86 | 2. [22/A- Second Order Statistics](https://codeforces.com/problemset/problem/22/A)
87 | Editorial
88 |
99 |
100 | **Prerequisite** : STL queue, map
101 | **Explanation** :
102 |
103 | Consider a queue e for every application and also a queue Q for the notification bar.
104 |
105 | i. When an event of the first type happens, increase the number of unread notifications by 1 and push pair (i, x) to Q where i is the index of this event among events of the first type, and also push number i to queue e[x].
106 |
107 | ii. When a second type event happens, mark all numbers in queue e[x] as visited,clear this queue and decrease the number of unread notifications by the number of elements in this queue before clearing.
108 |
109 | iii. When a third type query happens, do the following -
110 |
111 | ```python
112 | while Q is not empty and Q.front().first<=t:
113 | i = Q.front().first
114 | x= Q.front().second
115 | Q.pop()
116 | if mark[i] is false:
117 | Mark[i] = true
118 | e[v].pop()
119 | ans = ans - 1
120 | ```
121 |
122 |
129 |
130 | **Pre-requisite** : Vector / Map
131 | **Explanation** : Firstly let's count a number of different states that we can have in the game. Cards can be arranged in any one of n! ways. In every of this combination, we must separate first soldier's cards from the second one's. We can separate it in n + 1 places .
132 |
133 | So war has (n + 1)! states. If we'd do (n + 1)! "fights" and we have not finished the game yes, then we'll be sure that there is a state, that we passed at least twice. That means that we have a cycle, and game won't end. Otherwise , the game would end simply with one soldier having empty set.
134 | Since , n is very small one can use the above brute force method , so the time complexity will be O(n*(n+1)!). The other n is used by map to check the repetition of the states.
135 |
136 | One can use vectors to represent states of the soldiers. In every fight do as said in the problem and store the states . Also keep the count of no. of fights. If any of the state gets repeated , then the game would end in an infinite loop, hence print -1 and end the game. If at any instant either of the vectors is empty , the other soldier wins .
137 |
138 | To keep count of the states, one can use stl::map of a pair of vectors , where the first vector would represent the set of cards of soldier 1 and the second vector for soldier 2. One can map the pair of vector with bool values which represent whether that state is already visited or not.
139 |
140 |
147 |
148 | **Explanation** :
149 | Let the colour of T-shirt which buyer wants be x. So our task is to find the T-shirt having that colour on any of back or front side and remove it from our available collection of T-shirts.
150 |
151 | Here as our collection of data from which we want to select minimum is dynamic( i.e it is updating after removing each T-shirt) ,so we will use priority_queue that have both update and query(for minimum) in O(log(n)) time complexity;
152 |
153 | We can use priority_queue of pair `````` , as by default the ordering is on the basis of first element and we can use index of T-shirt to remove it from collection.
154 |
155 |
162 |
163 | **Prerequisite** : Priority queue or Set , Creating your own comparator functions
164 | **Explanation** :
165 | Create a priority queue to store segments, such that the segment having the greatest length is always at the top of priority queue. (If 2 segments have same length, the one with leftmost starting point will be at the top, as per given question)
166 | Now, perform the sequence of operations, as given in the problem.
167 | **Time Complexity** : O(N log N), where N = size of array
168 | [ Since, insertion and deletion in priority queue takes only O( log N ) ]
169 | **Code** : [https://codeforces.com/contest/1353/submission/80121041](https://codeforces.com/contest/1353/submission/80121041)
170 |
171 |
202 |
203 | **Pre-requisite** : Map
204 | **Explanation** : We can clearly see than n ≤ 10^5, that is a naive approach of O(n^2) will not pass. We need a better solution.
205 | Here using STL map will make our task easy.
206 | We can make a map of string and int where string will contain the name of person while int will contain the count.
207 | We know that by default map are initialized with zero.
208 | So if the count of a string is zero print OK and increase its counter by 1 else print the string and the count of string and increase its counter by 1.
209 |
210 |
233 |
--------------------------------------------------------------------------------
/docs/contests/2020/number-theory-and-bs.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | id: number-theory-and-bs
3 | title: Number Theory and Binary Search
4 | sidebar_label: 1. Number Theory and Binary Search
5 | description: Number Theory and Binary Search practice contest by cyberlabs
6 | ---
7 |
8 | import Tabs from '@theme/Tabs'
9 | import TabItem from '@theme/TabItem'
10 |
11 | ## Description
12 |
13 | - Topics : Number Theory, Binary Search
14 | - [Link to the contest](https://codeforces.com/contestInvitation/403be2a30c3c4a27382791b091ff1592f23209f9)
15 |
16 | ## Editorial
17 |
18 | :::caution
19 |
20 | Don’t read the editorial, if you have not attempted or read the problems. It would hamper your thinking capability, if you do so.
21 |
22 | :::
23 |
24 | ### A. [Find $x^{F(n)}$ mod m](https://codeforces.com/gym/298635/problem/A)
25 |
26 |
34 |
35 |
36 |
37 | Given 3 positive integers - $x$, $n$ and $m$. Find value of $x^{F(n)}$ mod $m$ .
38 | The function $F(n)$ is defined as the product of square of primes up to $n$ (inclusive).
39 | For eg. $F(5) = 2^2 \cdot 3^2 \cdot 5^2 = 900$ .
40 | **Constraints**
41 |
42 | - $1 \leq x,m \leq 10^9$
43 | - $2 \leq n \leq 10^6$
44 |
45 |
46 |
47 |
48 |
49 | Since $n \leq 10^6$, we need to use sieve of Erasthoneses to find out all the prime numbers from 1 to $n$ in $O(n\cdot\log(\log n))$.
50 | Also, one could easily observe that the value of $F(n)$ would definitely overflow for larger values of $n$. So, we can't find $F(n)$ directly.
51 | Here, we can use the property $a^{b \cdot c} = {(a^b)}^c$ . For finding ${a^b} \bmod m$ , use binary exponentation, which works in $O(\log_2 b)$ .
52 |
53 | **Final time complexity**: $O(n \log_2 n)$
54 |
55 |
56 |
57 |
58 |
59 | ```cpp
60 | #include
61 | #define int long long
62 |
63 | using namespace std;
64 |
65 | const int MAX = 1e6;
66 |
67 | int modulo(int a, int b, int n) {
68 | // Binar exponentation to calculate a^b in O(log b)
69 | int x = 1, y = a;
70 | while (b > 0) {
71 | if (b % 2 == 1) {
72 | x = (x * y) % n;
73 | }
74 | y = (y * y) % n;
75 | b /= 2;
76 | }
77 | return x % n;
78 | }
79 |
80 | vector is_prime(MAX + 1, 1);
81 | void sieve() {
82 | is_prime[0] = is_prime[1] = false;
83 | int i, j;
84 | for (i = 2; i * i <= MAX; i++) {
85 | if (is_prime[i]) {
86 | for (j = i * i; j <= MAX; j = j + i) is_prime[j] = false;
87 | }
88 | }
89 | }
90 |
91 | int32_t main() {
92 | int x, n, m;
93 | cin >> x >> n >> m;
94 | sieve(); // pre-compute all the primes
95 |
96 | int prod = x; // final answer would be stored in prod
97 |
98 | for (int i = 2; i <= n; i++) {
99 | if (is_prime[i]) {
100 | prod = modulo(prod, i, m);
101 | prod = modulo(prod, i, m);
102 | // Use the property (a^b)^c = a^(b*c).
103 | // Since, directly calculating F(n) first will overflow
104 | }
105 | }
106 | cout << prod;
107 | return 0;
108 | }
109 | ```
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 | ### B. [Simple Maths](https://codeforces.com/gym/298635/problem/B)
118 |
119 |
126 |
127 |
128 |
129 | You will be given 5 number $n$ ,$m$ , $a$ , $b$ , $c$ . You will make 3 more numbers $A$ , $B$ , $C$ from it.
130 | $A = a \cdot m$
131 | $B = A \cdot (b + c)$
132 | $C = 5 \cdot B + A \cdot (floor(\log_{10}{(b \cdot c)}))$
133 | You task is to computer $f(n)$ % $m$ where
134 | $f(i) = (A \cdot i^9 + i^i \cdot (B \cdot i!+1) + C \cdot i^{i^i}) \cdot f(i-1)$
135 | Note : $f(0) = 1$
136 |
137 | **Constraints**
138 |
139 | - $1 \leq n \leq 10^{18}$
140 | - $1 \leq m \leq 10^6$
141 | - $1 \leq a,b,c \leq 10^{12}$
142 |
143 |
144 |
145 |
146 | Since A, B and C all are multiples of m, we can say that :
147 |
148 |
149 | $A \bmod m = B \bmod m = C \bmod m = 0$
150 |
151 | Thus, applying the properties of modulo arithmetic, we get :
152 |
153 | $f(i) \bmod m = (i^i \cdot f(i-1)) \bmod m$
154 |
155 | Also note one thing, when $n >= m$ , $f(n)$ would be a multiple of m. So, in this case, $f(n) \bmod m = 0$
156 |
157 | Only remains is the case when when $n
158 |
159 | For finding ${n^n} \bmod m$ , use binary exponentation, which works in $O(\log_2 n)$.
160 |
161 | **Final time complexity**: $O(m \log_2 m)$
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 | ```cpp
170 | #include
171 | #define int long long
172 | #define fastio \
173 | ios_base::sync_with_stdio(false); \
174 | cin.tie(0); \
175 | cout.tie(0);
176 | #define die(x) return cout << x << '\n', 0;
177 |
178 | using namespace std;
179 |
180 | typedef long long ll;
181 |
182 | ll modulo(ll a, ll b, ll n) {
183 | ll x = 1, y = a;
184 | while (b > 0) {
185 | if (b % 2 == 1) {
186 | x = (x * y) % n; // multiplying with base
187 | }
188 | y = (y * y) % n; // squaring the base
189 | b /= 2;
190 | }
191 | return x % n;
192 | }
193 |
194 | int32_t main() {
195 | fastio;
196 | int n, m, a, b, c;
197 | cin >> n >> m >> a >> b >> c;
198 | if (n > m) {
199 | cout<<0<<'\n';
200 | } else {
201 | int ans = 1;
202 | for (int i = 1; i <= n; i++) {
203 | ans = (ans * modulo(i, i, m)) % m;
204 | }
205 | cout<
212 |
213 |
214 |
215 |
216 |
217 | ### C. [Candy Distribution](https://codeforces.com/gym/298635/problem/C)
218 |
219 |
226 |
227 |
228 |
229 | In the Town of Candyland, there are $K$ candy vendors who need to distribute candies to the kids of the town. Candyland can be represented as the x-axis where kids are standing at different $x$ coordinates, which are given to you. A vendor can only serve kids which are in his range, for example, if a vendor is placed at $X$ and his range is $E$ then all kids in the range $[X-E,X+E]$ can get candies from him. All the vendors have an equal range $E$.
230 | Since the vendors are lazy so they want you to find the minimum range $E$ such that all the kids in Candyland can get candies.
231 |
232 | **Constraints**
233 |
234 | - $1 \leq n,k \leq 10^4$
235 | - $10^{-9} \leq X_i \leq 10^{9}$
236 |
237 |
238 |
239 |
240 |
241 | Clearly, if for a range $E = x$, all the kids are able to get candies, then for all ranges $E > x$, all the kids will be able to get candies. This forms a monotonic function. Thus, we can apply binary search to find the minimum value of $E$, for which all the kids are able to get candies.
242 | The lower-limit for $E$ would be 0 and upper-limit for $E$ can be taken as the difference of the highest and the lowest x-coordinates.
243 | Sort the array of x-coordinates at the beginning once. Now, in the predicate function, it becomes very easy to check whether for a given value of range $E = x$, is it possible that all kids can get candies ?
244 |
245 |
246 |
247 |
248 |
249 | ```cpp
250 | #include
251 | using namespace std;
252 |
253 | #define int long long
254 |
255 | #define eps 0.000001
256 | typedef long double ld;
257 |
258 | int n,k;
259 | vector a;
260 |
261 | bool eval(ld x)
262 | {
263 | // returns true, if with range x, all kids can get candies
264 | // returns false, otherwise
265 |
266 | int y = 1;
267 |
268 | ld z = a[0] + 2*x;
269 |
270 | for(int i = 0; i< n; i++)
271 | {
272 | if ( a[i] > z )
273 | {
274 | y++;
275 | z = a[i] + 2*x;
276 | }
277 | }
278 |
279 | return y<=k;
280 | }
281 |
282 | int32_t main()
283 | {
284 | // For fast i/o
285 | ios_base::sync_with_stdio(false);
286 | cin.tie(0);
287 | cout.tie(0);
288 |
289 | cin>>n>>k;
290 |
291 | a.clear();
292 | a.resize(n);
293 | for(int i =0; i>a[i];
294 |
295 | sort(a.begin(),a.end());
296 |
297 | // binary search on range E
298 |
299 | ld l,h,ans;
300 |
301 | l = 0; // lower limit for E
302 | h = a[n-1] - a[0]; // upper limit for E
303 |
304 | while( l + eps < h )
305 | {
306 | ld mid = l + (h-l)/2;
307 | if ( eval(mid) ) { ans = mid; h = mid; }
308 | else l = mid;
309 | }
310 | cout<
318 |
319 |
320 |
321 | ### D. [Seems to be easy xD](https://codeforces.com/gym/298635/problem/D)
322 |
323 |
330 |
331 |
332 |
333 | Given an array $A$ (having the values of all elements in range [0,2000] ) of length $N$. Each index $i ∈ [1,N]$ has an initial weight of $W_i$ units. You have to perform $Q$ queries. The queries can be of 2 types:
334 |
335 | Type $1$: $1$ $X$
336 | Type $2$: $2$ $V$ $L$ $R$
337 | Type $1$ queries ask you to increase the weight of all indices by $X$ units.
338 |
339 | Type $2$ queries ask you to calculate the total weight contributed by elements having value $V$ in the index range $[L,R]$
340 |
341 | **Constraints**
342 |
343 | - $1 \leq N,Q \leq 5 \cdot 10^5$
344 | - $1 \leq A_i,V \leq 2000$
345 | - $0 \leq W_i, X \leq 100$
346 | - $1 \leq L \leq R \leq N$
347 |
348 |
349 |
350 |
351 |
352 | Maintain a variable, say $extra$ to keep track of total increment. For type $1$ queries, simply add $X$ to $extra$ .
353 |
354 | For each $i \in [0,2001]$ , maintain $2$ arrays, one array should contain the positions of elements having value $i$ and other array should contain the prefix sum of weights corresponding to the saved positions.
355 |
356 | For each query of type $2$, use binary search to get the range of indices of favourable positions in the array maintained for value $V$,
357 | print the difference of prefix sums for new range of $indices+count\cdot extra$ , where $count$ = count of indices in the new range.
358 |
359 |
360 |
361 |
362 |
363 | ```cpp
364 | #include
365 | using namespace std;
366 | typedef long long ll;
367 | typedef vector vll;
368 | #define pb push_back
369 | #define all(vec) vec.begin(),vec.end()
370 |
371 | int main()
372 | {
373 | ios_base::sync_with_stdio(0);
374 | cin.tie(0);
375 | cout.tie(0);
376 |
377 | ll T;
378 | cin>>T;
379 |
380 | while(T--)
381 | {
382 | vector pos(2001,vll(1,0)), pre(2001,vll(1,0));
383 |
384 | ll extra=0,n,q,i,type;
385 | cin>>n>>q;
386 | ll a[n],w[n];
387 |
388 | for(ll& i:a) cin>>i; //Input array A
389 | for(ll& i:w) cin>>i; //Input weights
390 |
391 | for(i=0;i>type;
401 |
402 | //Type 1 Queries
403 | if(type==1)
404 | {
405 | ll x;
406 | cin>>x;
407 | extra+=x;
408 | continue;
409 | }
410 |
411 | //Type 2 Queries
412 | ll v,l,r;
413 | cin>>v>>l>>r;
414 | auto lt=lower_bound(all(pos[v]),l);
415 | auto rt=upper_bound(all(pos[v]),r);
416 | --lt,--rt;
417 | l=lt-pos[v].begin();
418 | r=rt-pos[v].begin();
419 | cout<
427 |
428 |
429 |
430 | ### E. [Rahul and his set](https://codeforces.com/gym/298635/problem/E)
431 |
432 |
439 |
440 |
441 |
442 | Rahul has a set $S$ consisting of the first $N$ natural numbers.
443 |
444 | He thinks that 'wellness' of a subset $M$ ⊆ $S$ is equal to the maximum of $gcd(a,b)$ over all pairs $(a,b)$ such that both $a$ and $b$ are in $M$ and $a \neq b$.
445 |
446 | Rahul is an organized guy and for each $k$ ∈ {$2,3,…,N$} he wants to find a subset that has the smallest wellness among all subsets in $S$ of size $k$. There can be more than one subset with the smallest wellness and the same size, but you don't need to worry about it. Rahul wants to find all the subsets himself, but he needs your help to find the smallest possible wellness for each size $k$, will name it $I_k$.
447 |
448 | Please, help Rahul to find $I_2, I_3, ..., I_n$.
449 |
450 | **Constraints**
451 |
452 | - $2 \leq N \leq 5 \cdot 10^5$
453 |
454 |
455 |
456 |
457 |
458 | Let $A=$ {$a_1,a_2,...,a_k$} be one of the possible subsets with smallest wellness.
459 |
460 | If for any number $a_i$ in $A$ not all of its divisors contained in $A$ then we can replace $a_i$ with one of its divisor.
461 | The size of the subset does not change and wellness may only decrease. Then we can assume that for any $a_i$ all of its divisors contained in $A$.
462 |
463 | Let $d(n)$ be the greatest divisor of $n$ exclude $n$ ($d(1)=1$). Since $A$ contains element with its divisors then smallest gcd of pair of an elements not less than maximum of $d(a_i)$ over elements of $A$ (because $A$ contains $a_i$ with $d(a_i)$). And for any element $a_i$ there is no element $a_jd(a_i)$ (because $d(a_i)$ is the greatest divisor). Then wellness of $A$ is equal to greatest $d(a_i)$ over elements of $A$.
464 |
465 | After this observation we can just sort elements {$1,...,n$} by theirs $d(∗)$ and take smallest $k$ for every $2\leq k \leq n$. You can calculate $d(∗)$ using the sieve of Eratosthenes.
466 |
467 | **Final time complexity**: $O(n \cdot log(n))$
468 |
469 |
470 |
471 |
472 |
473 | ```cpp
474 | #include
475 | using namespace std;
476 | #define ll long long int
477 | #define mp map
478 | #define pb push_back
479 | #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
480 |
481 | int32_t main(){
482 |
483 | fast;
484 |
485 | ll n;
486 | cin>>n;
487 | vector primes;
488 | ll lpf[n+1];
489 | for(ll i=0;i<=n;i++)
490 | lpf[i] = i;
491 |
492 | ll prime[n+1];
493 | memset(prime,0,sizeof(prime));
494 | prime[0] = prime[1] = 1;
495 | for (ll i = 2; i < n+1; i++) {
496 | if (prime[i] == 0) {
497 | for (ll j = i * i; j < n+1; j += i) {
498 | if (prime[j] == 0) {
499 | prime[j] = i; }
500 | lpf[j] = min(lpf[j],lpf[i]);
501 | }
502 | }
503 | }
504 |
505 |
506 | for (ll i = 2; i < n+1; i++) {
507 | if (prime[i] == 0) {
508 | prime[i] = i;
509 | primes.pb(i);
510 | }
511 | }
512 |
513 | mp m;
514 | for(ll i=2;i<=n;i++)
515 | {
516 | m[i/lpf[i]]++;
517 | }
518 |
519 | for(auto i:m)
520 | {
521 | for(ll j=0;j
530 |
531 |
532 |
--------------------------------------------------------------------------------
/static/img/undraw_exams.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------