Skip to content

Commit d6f375b

Browse files
committed
Updated
1 parent 296fd40 commit d6f375b

File tree

6 files changed

+28
-30
lines changed

6 files changed

+28
-30
lines changed

check.cpp

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
//The below contains the brute force code for any solution
2-
//It helps me to check the answers or find a pattern in question
3-
41
#include <bits/stdc++.h>
52
using namespace std;
63

@@ -9,27 +6,32 @@ typedef long double LD;
96

107
const int MAX = 1e5 + 5;
118
const int LIM = 3e5 + 5;
9+
const int MOD = 1e9 + 7;
1210
const LD EPS = 1e-10;
1311
const double PI = acos(-1.0);
1412

1513
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
1614
#define Assert(x) {if(!(x)){cerr<<"Assertion failed at line "<<__LINE__<<": "<<#x<<" = "<<(x)<<"\n";exit(1);}}
15+
#define inchar getchar//_unlocked
16+
#define outchar(x) putchar(x)//_unlocked(x)
1717
#define unique(a) sort((a).begin(), a.end()), (a).erase(unique((a).begin(), (a).end()),(a).end())
1818

1919
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
2020
template <typename Arg1>void __f(const char* name, Arg1&& arg1){cout<<name<<" : "<<arg1<<"\n";}
2121
template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args){const char* comma=strchr(names+1,',');cout.write(names,comma-names)<<" : "<<arg1<<" , ";__f(comma+1, args...);}
2222

2323
double tick(){static clock_t oldt;clock_t newt=clock();double diff=1.0*(newt-oldt)/CLOCKS_PER_SEC;oldt = newt;return diff;}
24-
int ilog2(int n){return 31 - __builtin_clz(n);}
25-
int ilog2(LL n){return 63 - __builtin_clzll(n);}
24+
template<typename T> void inPos(T &x){x=0;register T c=inchar();while(((c<48)||(c>57))&&(c!='-'))c=inchar();bool neg=false;if(c=='-')neg=true;for(;c<48||c>57;c=inchar());for(;c>47&&c<58;c=inchar())x=(x<<3)+(x<<1)+(c&15);if(neg)x=-x;}
25+
template<typename T> void outPos(T n){if(n<0){outchar('-');n*=-1;}char snum[65];int i=0;do {snum[i++]=n%10+'0';n/=10;}while(n);i=i-1;while(i>=0)outchar(snum[i--]);outchar('\n');}
26+
inline void inStr(char *str){register char c=0;register int i=0;while(c<33)c=inchar();while (c!='\n'&&c!=' '&&c!=EOF){str[i]=c;c=inchar();++i;}str[i]='\0';}
2627
template<typename T> T gcd(T a, T b){return (b?__gcd(a,b):a);}
2728
template<typename T> T lcm(T a, T b){return (a*(b/gcd(a,b)));}
2829
template<typename T> T mod(T a, T b) {return (a<b ? a : a%b);}
29-
template<typename T> T mod_neg(T a, T b) {return ((a%b)+b)%b;}
30+
template<typename T> T add(T a, T b, T c){T x=a+b;return (x>=c ? x-c : x);}
31+
template<typename T> T mod_neg(T a, T b) {a=mod(a, b);if(a<0){a+=b;}return a;}
3032
LL mulmod(LL a,LL b, LL m){LL q=(LL)(((LD)a*(LD)b)/(LD)m);LL r=a*b-q*m;if(r>m)r%=m;if(r<0)r+=m;return r;}
3133
template<typename T> T expo(T e, T n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
32-
template<typename T> T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mod(x*p,m);p=mod(p*p,m);n>>=1;}return x;}
34+
template<typename T> T power(T e, T n, T m){T x=1%m,p=e;while(n){if(n&1)x=mod(x*p,m);p=mod(p*p,m);n>>=1;}return x;}
3335
template<typename T> T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
3436
template<typename T> T mod_inverse(T a, T n){T x,y;T d = extended_euclid(a, n, x, y);return (d>1?-1:mod_neg(x,n));}
3537

@@ -39,8 +41,7 @@ int main() {
3941
freopen("res.txt", "w", stdout);
4042
#endif
4143

42-
// Brute force code goes below
44+
// Brute force code or some Accepted code goes below
4345

44-
// cerr<<tick();
4546
return 0;
4647
}

code_template.cpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//Below is the template in C++ which I used for Programming Competitions
2-
31
/******************************************
42
* AUTHOR: BHUVNESH JAIN *
53
* INSTITUITION: BITS PILANI, PILANI *
@@ -12,11 +10,12 @@ typedef long double LD;
1210

1311
const int MAX = 1e5 + 5;
1412
const int LIM = 3e5 + 5;
13+
const int MOD = 1e9 + 7;
1514
const LD EPS = 1e-10;
1615
const double PI = acos(-1.0);
1716

1817
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
19-
#define Assert(x) {if(!(x)){cerr<<"Assertion failed at line "<<__LINE__<<": "<<#x<<" = "<<(x)<<"\n";exit(1);}}
18+
#define Assert(x) {if(!(x)){cerr<<"Assertion failed at line "<<__LINE__<<": "<<#x<<" = "<<(x)<<"\n";exit(1);}}
2019
#define inchar getchar//_unlocked
2120
#define outchar(x) putchar(x)//_unlocked(x)
2221
#define unique(a) sort((a).begin(), a.end()), (a).erase(unique((a).begin(), (a).end()),(a).end())
@@ -29,15 +28,14 @@ double tick(){static clock_t oldt;clock_t newt=clock();double diff=1.0*(newt-old
2928
template<typename T> void inPos(T &x){x=0;register T c=inchar();while(((c<48)||(c>57))&&(c!='-'))c=inchar();bool neg=false;if(c=='-')neg=true;for(;c<48||c>57;c=inchar());for(;c>47&&c<58;c=inchar())x=(x<<3)+(x<<1)+(c&15);if(neg)x=-x;}
3029
template<typename T> void outPos(T n){if(n<0){outchar('-');n*=-1;}char snum[65];int i=0;do {snum[i++]=n%10+'0';n/=10;}while(n);i=i-1;while(i>=0)outchar(snum[i--]);outchar('\n');}
3130
inline void inStr(char *str){register char c=0;register int i=0;while(c<33)c=inchar();while (c!='\n'&&c!=' '&&c!=EOF){str[i]=c;c=inchar();++i;}str[i]='\0';}
32-
int ilog2(int n){return 31 - __builtin_clz(n);}
33-
int ilog2(LL n){return 63 - __builtin_clzll(n);}
3431
template<typename T> T gcd(T a, T b){return (b?__gcd(a,b):a);}
3532
template<typename T> T lcm(T a, T b){return (a*(b/gcd(a,b)));}
3633
template<typename T> T mod(T a, T b) {return (a<b ? a : a%b);}
37-
template<typename T> T mod_neg(T a, T b) {return ((a%b)+b)%b;}
34+
template<typename T> T add(T a, T b, T c){T x=a+b;return (x>=c ? x-c : x);}
35+
template<typename T> T mod_neg(T a, T b) {a=mod(a, b);if(a<0){a+=b;}return a;}
3836
LL mulmod(LL a,LL b, LL m){LL q=(LL)(((LD)a*(LD)b)/(LD)m);LL r=a*b-q*m;if(r>m)r%=m;if(r<0)r+=m;return r;}
3937
template<typename T> T expo(T e, T n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
40-
template<typename T> T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mod(x*p,m);p=mod(p*p,m);n>>=1;}return x;}
38+
template<typename T> T power(T e, T n, T m){T x=1%m,p=e;while(n){if(n&1)x=mod(x*p,m);p=mod(p*p,m);n>>=1;}return x;}
4139
template<typename T> T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
4240
template<typename T> T mod_inverse(T a, T n){T x,y;T d = extended_euclid(a, n, x, y);return (d>1?-1:mod_neg(x,n));}
4341

inp_generator.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//Below code is used to generate some random test cases
2-
31
#include <iostream>
42
#include <cstdio>
53
#include <cmath>
@@ -15,6 +13,10 @@ const int mod = 1e2;
1513
const int mod2 = 10;
1614
const LL modl = 1e18;
1715

16+
//Sample program to generate 1000 random integers
17+
//For generating some specific test case as per problems, you can refer to
18+
// https://github.com/likecs/Test-case-generators
19+
1820
int main() {
1921
#ifndef ONLINE_JUDGE
2022
freopen("inp.txt", "w", stdout);
@@ -24,12 +26,9 @@ int main() {
2426
t = 1000;
2527
printf("%d\n", t);
2628
while (t--) {
27-
int n, q, x, y, l, r;
29+
int n;
2830
n = rand()%mod + 1;
2931
printf("%d\n", n);
30-
31-
// LL n;
32-
// n = (LL)rand() * (LL)rand() % modl + 1;
3332
}
3433
return 0;
3534
}

precision_checker.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <algorithm>
66
using namespace std;
77

8+
//Set the precision limit you want for comparing the 2 output files
89
const double EPS = 1e-7;
910

1011
int main() {

timer.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ int main() {
1414
//write your code below
1515

1616
//include this at the end of your code to get the time
17-
cerr<<tick();
17+
cerr << tick(); //Prints execution time on error screen
18+
1819
return 0;
1920
}

work.cpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
//Below contains the workspace for my coding
2-
//This is the file which I upload on Online Judges
3-
41
/******************************************
52
* AUTHOR: BHUVNESH JAIN *
63
* INSTITUITION: BITS PILANI, PILANI *
@@ -13,6 +10,7 @@ typedef long double LD;
1310

1411
const int MAX = 1e5 + 5;
1512
const int LIM = 3e5 + 5;
13+
const int MOD = 1e9 + 7;
1614
const LD EPS = 1e-10;
1715
const double PI = acos(-1.0);
1816

@@ -30,21 +28,21 @@ double tick(){static clock_t oldt;clock_t newt=clock();double diff=1.0*(newt-old
3028
template<typename T> void inPos(T &x){x=0;register T c=inchar();while(((c<48)||(c>57))&&(c!='-'))c=inchar();bool neg=false;if(c=='-')neg=true;for(;c<48||c>57;c=inchar());for(;c>47&&c<58;c=inchar())x=(x<<3)+(x<<1)+(c&15);if(neg)x=-x;}
3129
template<typename T> void outPos(T n){if(n<0){outchar('-');n*=-1;}char snum[65];int i=0;do {snum[i++]=n%10+'0';n/=10;}while(n);i=i-1;while(i>=0)outchar(snum[i--]);outchar('\n');}
3230
inline void inStr(char *str){register char c=0;register int i=0;while(c<33)c=inchar();while (c!='\n'&&c!=' '&&c!=EOF){str[i]=c;c=inchar();++i;}str[i]='\0';}
33-
int ilog2(int n){return 31 - __builtin_clz(n);}
34-
int ilog2(LL n){return 63 - __builtin_clzll(n);}
3531
template<typename T> T gcd(T a, T b){return (b?__gcd(a,b):a);}
3632
template<typename T> T lcm(T a, T b){return (a*(b/gcd(a,b)));}
3733
template<typename T> T mod(T a, T b) {return (a<b ? a : a%b);}
38-
template<typename T> T mod_neg(T a, T b) {return ((a%b)+b)%b;}
34+
template<typename T> T add(T a, T b, T c){T x=a+b;return (x>=c ? x-c : x);}
35+
template<typename T> T mod_neg(T a, T b) {a=mod(a, b);if(a<0){a+=b;}return a;}
3936
LL mulmod(LL a,LL b, LL m){LL q=(LL)(((LD)a*(LD)b)/(LD)m);LL r=a*b-q*m;if(r>m)r%=m;if(r<0)r+=m;return r;}
4037
template<typename T> T expo(T e, T n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
41-
template<typename T> T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mod(x*p,m);p=mod(p*p,m);n>>=1;}return x;}
38+
template<typename T> T power(T e, T n, T m){T x=1%m,p=e;while(n){if(n&1)x=mod(x*p,m);p=mod(p*p,m);n>>=1;}return x;}
4239
template<typename T> T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
4340
template<typename T> T mod_inverse(T a, T n){T x,y;T d = extended_euclid(a, n, x, y);return (d>1?-1:mod_neg(x,n));}
4441

4542
int main() {
4643
#ifndef ONLINE_JUDGE
4744
freopen("inp.txt", "r", stdin);
45+
freopen("out.txt", "w", stdout);
4846
#endif
4947

5048

0 commit comments

Comments
 (0)