ICPC Codes
ICPC Codes
VECTORs:
.push_back();
.pop_back();
.insert(v.begin+x, sth_to_insert) // x is the index
.erase(v.begin+x)
.size()
Lists:
.push_back();
.push_front();
.pop_back();
.insert(v.begin+x, sth_to_insert) // x is the index
.erase(v.begin+x)
.size()
To go throuth the list you must declare a pointer
first, for ex:
List<string>::iterator boi = l.begin();
While (boi != l.end()){
cout << *boi << endl;
}
STACK:
.push();
.pop();
.top(); returns the last element
.size();
Queue:
.push();
.pop(); removes first elment
.front(); returns the 1st element
.size();
.back(); returns the last element
Priority Queue:
Same as queue, but the larger is put on top
.push();
.pop(); removes first elment
.top(); returns the biggest element
.size();
SETs:
// right side is bigger, left side is smaller
// has no duplicates, and arranges stuff
// insert
// find
// clear
// print
// erase
set <int>::iterator it = st.begin();
while (it != st.end()){
cout << *it << endl;
it++;
}
// If you want to access it use pointer
MAPs:
// basically same as the python dict.
// If you want to access it use pointer
// to access key use ->first
// to access what’s inside use ->second
}
}
if (n == 2)
return true;
if(n <=1 || n %2 == 0)
return false;
return true;
}
if(i*i == n){
v.push_back(i);
}
return v;
}
************
return v;
return res;
}
****
long long comp(long long n, long long r){
if (n-r < r){
r = n-r;
}
long long res = 1;
for (long long i =1; i <=r; i++, n--){
res *=n;
res/=i;
}
return res;
prefix_sum
#include <iostream>
int main()
{
int n, q, r, arr[1005], cumu[1005], s ,e;
cin >> n >> q;
for(int i =1; i<=n; i++){
cin >> arr[i];
}
cumu[0] = 0;
cumu[1] = arr[1];
return 0;
}
prefix_sum 2d
// لو فهمت حاجة تبقى جامد
#include <bits/stdc++.h>
int main()
{
int n, q, r, arr[105][105], cumu[105][105], s ,e;
cumu[i][j] += cumu[i-1][j];
}
}