JCPC
JCPC
***********************************************************************************
*************************************
<vector>
#include<vector>
vector<int>v(5);
vector<int>v1={1,2,3,4,5};
vector<int>v2(5,100);
v.push_back(50);
v.pop_back();
v.swap(v2);
v.front();
v.back();
v.size();
v.empty();
v.emplace(v.begin() + 1, 51);
v.erase(v.begin());
v.erase(v.begin() + 1, v.end() - 1);
v.resize(5);
v.shrink_to_fit();
sort(v.begin(), v.end());
sort(v.rbegin(), v.rend());
reverse(v.begin(), v.end());
*min_element(v.begin(), v.end());
*max_element(v.begin(), v.end());
for (auto i : v)
cout << i << " ";
https://codeforces.com/contest/998/submission/171269790
***********************************************************************************
*************************************
<deque>
***********************************************************************************
*************************************
<list>
***********************************************************************************
*************************************
<forward_list>
#include<forward_list>
forward_list<int> FL={ 1,2,3 };
FL.assign({ 5,4,6 });
FL.push_front(9);
FL.pop_front();
FL.remove(4);
***********************************************************************************
*************************************
<pair>
#include<utility>
pair <int, int>P;
cin >> P.first >> P.second;
cout << P.first<<" "<<P.second;
pair<string, pair<int, bool>>PP;
PP.first = "Farooq";
PP.second.first = 123;
PP.second.second = true;
vector<pair<int, int>>VP;
VP.push_back({{ 123,321 });
cout << VP[0].first << " " << VP[0].second;
https://codeforces.com/contest/230/submission/171271549
***********************************************************************************
*************************************
<set>
#include<set>
set<int>S{ 2,1,0,5,2,1 }; // sort & uniqe
for (auto i : S)cout << i<<" "; //0 1 2 5
S.empty();
S.size();
S.insert(3); cout << endl; // 0 1 2 3 5
S.erase(1);
S.swap(s2);
S.clear();
S.count(5); // if S contain 5 return 1 else return 0
set<int,greater<int>>S{ 2,1,0,5,2,1 }; // 5 2 1 0
multiset<int>MS{ 5,9,3,5,6,2,5 }; // sort ONLY
for (auto i : MS)cout << i << " "; // 2 3 5 5 5 6
MS.count(5); // 3
***********************************************************************************
*************************************
<map>
#include<map>
map<int, string>M{ {12547,"FA"},{1234,"RA"},{1254,"QA"} };
M[5547] = "AH";
for (auto i : M)
cout << i.first << " " << i.second << endl; //sorted
M.count(1234); //1
M.insert({ 40,"sq" });
M.empty();
M.swap(M2);
M.clear();
M.size();
multimap<string, string>MM; // accept duplicate
MM.insert({ "Ahmad","SE" });
MM.insert({ "Ahmad","CS" });
MM.insert({ "Ahmad","CIS" });
MM.count("Ahmad");//3
https://codeforces.com/contest/785/my
https://codeforces.com/contest/499/my
***********************************************************************************
***********************************
//frequency array
map<int, int>m;
int n; cin >> n;
for (int i = 0; i < n; i++) {
int x; cin >> x;
m[x]++;
}
for (auto i : m)cout << i.first << " " << i.second << endl;
https://codeforces.com/contest/1025/my
*IMPORTANT*
https://codeforces.com/contest/227/submission/171617113
***********************************************************************************
***********************************
#include<unordered_set>
#include<unordered_map>
unordered_set<string>us;
unordered_multiset<string>uss;
unordered_map<int, int >um;
unordered_multimap<int, int >umm;*/
***********************************************************************************
***********************************
<stack>
// Last-in-first-out
#include <stack>
stack<string>s;
s.push("a");
s.push("b");
s.push("c");
s.push("d");
s.emplace("P");
s.pop();
//cout << s.top();
for (int i = 0; !s.empty(); i++) {
cout << s.top() << " ";
s.pop();
}
https://codeforces.com/contest/81/submission/172052151
***********************************************************************************
*************************************
<queue>
//first-in-first-out
#include<queue>
queue<int>q;
q.push(60);
q.push(50);
q.push(40);
cout << q.front(); // 60
cout << q.back(); // 40
q.pop();
cout << q.front(); // 50
while (!q.empty()) {
cout << q.front() << " ";
q.pop();
}
https://codeforces.com/contest/96/submission/172137303
***********************************************************************************
*************************************
<priority_queue>
#include<queue>
priority_queue<int>pq;
pq.push(50);
pq.push(70);
pq.push(80);
pq.push(60);
cout << pq.top(); // 80
pq.pop();
cout << pq.top(); // 70
while (pq.size() != 0) {
cout << pq.top() << " ";
pq.pop();
}
https://codeforces.com/contest/218/submission/172140933
***********************************************************************************
*************************************
<cumulative sum>
#include <bits/stdc++.h>
using namespace std;
int arr[105], cum[105];
int main() {
int n, m; cin >> n >> m; // 7 2
for (int i = 1; i <= n; i++) {
cin >> arr[i]; // 17 3 -1 5 2 11 -4
cum[i] = cum[i - 1] + arr[i];
cout << cum[i] << " "; // 17 20 19 24 26 37 33
}
cout << endl;
while (m--) {
int left, right; cin >> left >> right; // 2 4 // 1 5
cout << cum[right] - cum[left - 1] << endl; // 7 // 26
}
return 0;
}
https://codeforces.com/contest/18/submission/172290538
https://codeforces.com/contest/433/submission/171827988
https://codeforces.com/contest/313/submission/172292977
<Recursion>
int fact(int n) {
if (n == 0)return 1;
return n * fact(n - 1);
}
int fib(int n) {
if (n == 1 || n == 2) return 1;
return fib(n - 1) + fib(n - 2);
}
https://codeforces.com/contest/96/submission/172365215
https://codeforces.com/group/dfmvO0RN41/contest/227937/submission/172368378
https://codeforces.com/gym/100989/submission/172398983
https://codeforces.com/group/dfmvO0RN41/contest/227937/submission/172485078
***********************************************************************************
*************************************
-----------------------------------------------------------
***********************************************************************************
*************************************
#include<stdio.h>
***********************************************************************************
*************************************
https://codeforces.com/gym/101257/submission/172748001
https://codeforces.com/contest/670/problem/D2
-------------------------------------------------------
***********************************************************************************
*************************************
***********************************************************************************
*************************************
-Adjacency List
-Adjacency Matrix
*Graph representaion
https://codeforces.com/contest/580/submission/173086911
*DFS
https://codeforces.com/group/qAGblhphAA/contest/227610/submission/173089319
*Grid Traversing
https://codeforces.com/contest/378/submission/173234399
*BFS
https://codeforces.com/group/qAGblhphAA/contest/227610/submission/173237341
***********************************************************************************
*************************************