-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImportant.txt
More file actions
34 lines (28 loc) · 2.05 KB
/
Important.txt
File metadata and controls
34 lines (28 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
1->compiler can perform 10^7 calculation in 1 sec!
2->To optmise the time of a solution in most of the cases we have to increase the sapace;
3->We use 0 based indexing in prefix sum because codeforce question works on position not index;
4->unique(begin,end)-removes the same elements present together like 1 1 2 2, change to 1,2,*,*;
5->handle the negitive mod -((a - b) % MOD + MOD) % MOD;
6->fill(all(vec), 1); to fill the vector with the 1;
7->iota(numbers.begin(), numbers.end(), 1); used to fill vector consecutive like 1,2,3..size must remember to define the size of the vector during insilise;
8->binary_search(all(vec), key)- find the element in sort array;
9->map in made by red black trees and unordered map is made by hashing table uorderd map can't store pair and other ds because it can't compare diff datastructures by hashing
10->use mulitset instead of priority queue
11->lower_bound return the iterator of element if present and if not then its greater one!
12-> upper_bound return the iterator of the elemen with is greatere then it;
13->int set/map we use upper and lower bound diff as set.upper_bound(3); in vector upper_bound(v.begin(),v.end(),target);because working in vector is BS and in set its tree
14->int sum=accumulate(v.begin(),v.end(),0(initial sum value)); to get sum of vector;
15-> transform(s.begin(), s.end(), s.begin(), ::tolower); to make string lower ;
sweepline adhoc
16->s.erase(unique(s.begin(), s.end()), s.end()); to remove all duplicates of string or vector;
18->xor of l to r range is even number of ele then twice xor is ==0;
19->if (all_of(foo.begin(), foo.end(), [](int i){return i%2;}) )cout <<"sare odd h"<<endl;
else cout<<"sare odd nhi h "
20->sum of first k odd elements =k^2
21-> to solve a%x=b%x so x=abs(a-b);
22->The Chicken McNugget Theorem states that for any two relatively prime positive integers m,n gcd(a,b)==1;
the greatest integer that cannot be written in the form am+bn
for nonnegative integers a,b
is mn−m−n
CONCEPTS
1.to find the value of the base of x eg 345 formula is 3*(base^2) + 4*(base^1) + 5*(base^0)