From 0e28f294584e1cb91976038ce753ec582f01b7ee Mon Sep 17 00:00:00 2001 From: vasanthnaik <76811492+vasanthnaik@users.noreply.github.com> Date: Sat, 2 Oct 2021 15:51:29 +0530 Subject: [PATCH] added cpp template this cpp template is really useful for a lot of programmers as itsave time and push your ranking --- cpp template.txt | 295 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 295 insertions(+) create mode 100644 cpp template.txt diff --git a/cpp template.txt b/cpp template.txt new file mode 100644 index 0000000..0524751 --- /dev/null +++ b/cpp template.txt @@ -0,0 +1,295 @@ +// -------------------------Solution by Aditya Raj------------------------- // + //--------------------------// +#pragma GCC optimize("Ofast") +#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma") +#pragma GCC optimize("unroll-loops") +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +typedef long long ll; +typedef long double ld; +typedef pair p32; +typedef pair p64; +typedef pair pdd; +typedef vector v64; +typedef vector v32; +typedef vector > vv32; +typedef vector > vv64; +typedef vector > vvp64; +typedef vector vp64; +typedef vector vp32; +double eps = 1e-12; +ll MOD = 998244353; +ll mod = 1000000007; +#define forn(i,e) for(ll i = 0; i < e; i++) +#define forsn(i,s,e) for(ll i = s; i < e; i++) +#define rforn(i,s) for(ll i = s; i >= 0; i--) +#define rforsn(i,s,e) for(ll i = s; i >= e; i--) +#define nl "\n" +#define dbg(x) cout<<#x<<" = "<= mod ? res - mod : res); +} + +int multiply(int x, int y) +{ + int res = x * y; + return(res >= mod ? res % mod : res); +} + +int subtract(int x, int y) +{ + int res = x - y; + return(res < 0 ? res + mod : res); +} + +int power(long long x, unsigned int y, int p) +{ + int res = 1; + + x = x % p; + + if (x == 0) return 0; + + while (y > 0) + { + if (y & 1) + res = (res*x) % p; + + y = y>>1; // y = y/2 + x = (x*x) % p; + } + return res; +} + +// -------------------Sieve of Erastothenes------------------- // + +bool sieve_of_eratosthenes(int n) +{ + vector is_prime(n+1, true); + is_prime[0] = is_prime[1] = false; + for (int i = 2; i <= n; i++) { + if (is_prime[i] && (long long)i * i <= n) { + for (int j = i * i; j <= n; j += i) + is_prime[j] = false; + } + } + return is_prime[n]; +} + +// -------------------Number of Divisors------------------- // + +int NODiv(int n) +{ + int cnt = 0; + for(int i = 1;i * i <= n;i++) + { + if(i * i == n) + { + cnt++; + continue; + } + cnt += 2; + } + return cnt; +} + +// -------------------nCr(Binomial)------------------- // + +int nCr(int n, int k) +{ + if(n < k) + { + return 0; + } + if(k == 0) + { + return 1; + } + int res = 1; + for (int i = n - k + 1; i <= n; ++i) + res *= i; + for (int i = 2; i <= k; ++i) + res /= i; + return res; +} + +// -------------------Checking Prime (O(root(n))------------------- // + +bool isPrime(int x) { + for (int d = 2; d * d <= x; d++) { + if (x % d == 0) + return false; + } + return true; +} +// -------------------Adding Egdes to the Graph------------------- // + +vector>adj; +void addEdge(int x, int y) +{ + adj[x].push_back(y); + adj[y].push_back(x); +} + +// -------------------DFS------------------- // + +// vectorvisited; // resize in the solve() with n + 1 +// void dfs(int v) +// { +// visited[v] = true; +// for(auto i:adj[v]) +// { +// if(!visited[i]) +// { +// dfs(i); +// } +// } +// } + +// -------------------DIJKSTRA------------------- // + +// vectord; +// vectorp; + +// void dijkstra(int s) +// { +// int n = adj.size(); +// d.assign(n, INF); +// p.assign(n, -1); +// d[s] = 0; +// using pii = pair; +// priority_queue, greater>q; +// q.push({0, s}); +// while(!q.empty()) +// { +// int v = q.top().second; +// int d_v = q.top().first; +// q.pop(); +// if(d_v != d[v]) +// { +// continue; +// } +// for (auto edge : adj[v]) +// { +// int to = edge.first; +// int len = edge.second; +// if (d[v] + len < d[to]) +// { +// d[to] = d[v] + len; +// p[to] = v; +// q.push({d[to], to}); +// } +// } +// } +// } + +// -------------------RESTORING SHORTEST PATH------------------- // + +// vectorpath; + +// void restore_path(int s, int t) +// { +// for(int v = t;v != s;v = p[v]) +// { +// path.push_back(v); +// } +// path.push_back(s); +// reverse(path.begin(), path.end()); +// } + +// -------------------Important Notes------------------- // + +// For Interactive Problems remember to remove multi test cases condition // + +// (int)log2(x) + 1 -> to calculate number of bits of a number +// s.erase(0, min(s.find_first_not_of('0'), s.size()-1)); //for removing leading zero's +// (int index = str.find(substr, pos)) != string::npos // for checking substring 'substr' in string 'str' + +// -----------------------Solve------------------------ // +// #define REP for(int i = 0;i < n;i++) +void solve(){ + int n; + cin >> n; + vector a1(n); + vector b(n); + for(int i = 0;i < n;i++){ + cin>>a1[i]; + } + for(int i = 0;i < n;i++){ + cin>>b[i]; + } + ll z=a1[n-1]; + ll count=1; + for(ll i=n-2;i>=0;i--){ + ll z1=z+a1[i]; + a1[i]=count*a1[i]-z; + z=z1; + count++; + } + z=b[n-1]; + count =1; + for(ll i=n-2;i>=0;i--){ + ll z1=z+b[i]; + b[i]=count*b[i]-z; + z=z1; + count++; + } + ll answer=0; + a1[n-1]=0; + b[n-1]=0; + for(ll i=0;i> t; + int k = 1; + while(t--) { + // cout<<"Case #"<