-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.cpp
More file actions
296 lines (253 loc) · 5.9 KB
/
Copy pathtemplate.cpp
File metadata and controls
296 lines (253 loc) · 5.9 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long int
#define ll long long int
#define pi 2*acos(0.0)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define ms(a,d) memset(a,d,sizeof(a))
#define popcount(i) __builtin_popcount(i) //count one. in long long use __builtin_popcountll(i)
#define parity(i) __builtin_parity(i) //evenparity 0 and odd parity 1------ parity bit means number of 1 // cout<<parity(0001110001111)<<endl;--->3 //cout<< parity(0011000) ; --->2
#define btz(a) __builtin_ctz(a) //count binary trailling zero // cout<<btz(101000)<<endl;---> 3 //btz(001000) ----> 5
#define pii pair < int, int>
#define pll pair < ll, ll>
#define pb(a) push_back(a)
#define mp make_pair
//upper bound and lower bound
#define LB(a,value) (lower_bound(all(a),value)-a.begin())
#define UB(a,value) (upper_bound(all(a),value)-a.begin())
//File input/output
#define input freopen("in.txt","r",stdin)
#define output freopen("out.txt","w",stdout)
typedef unsigned long long ull;
//reversing a string
void reverseStr(string &str)
{
int n = str.size();
for (int i = 0; i < n / 2; i++)
swap(str[i], str[n - i - 1]);
}
//checking palindrome
bool isPalindrome(string str)
{
int l = 0;
int h = str.size() - 1;
while (h > l)
{
if (str[l++] != str[h--])
{
cnt=l-1;
sp=h+2;
return false;
}
}
return true;
}
//lucky number
//---------------------------
const long long mx = 1e10;
vector <long long> a;
long long DP(long long x)
{
if (x<=mx)
{
a.push_back(x);
DP(x*10+4);
DP(x*10+7);
}
}
//----------------------------
ll SQRT(ll x)
{
ll res,a = sqrt(x*1.0);
for(ll i = max(a-2,0LL); i <= a+2; i++)
{
if(i*i<=x)
res = i;
}
return res;
}
ll CBRT(ll x)
{
ll res,a = cbrt(x*1.0);
for(ll i = max(a-2,0LL); i <= a+2; i++)
{
if(i*i*i<=x)
res = i;
}
return res;
}
/*
template <typename T>
string toString( T Number )
{
stringstream st;
st << Number;
return st.str();
}
*/
/*
int stringconvert(string s)
{
int p;
istringstream st(s);
st>>p ;
return p;
}
*/
/*
Cheking divisibility of any large number (may be 1000 digits) by a number // 1000000000000000000000000000000 is divisible by 4 or not
----------------------------------------------------------------------------
bool get_result1(string str)// str is the large number which is to be checked
{
ll n=0;
for(int i=0;str[i];i++){
n=( n*10+ (str[i]-'0') )% number_that_divide_str;
}
if(n==0)
return 0;//divisible
else
return 1;//not divisible
}
*/
/*
int arr[5000],i;
void stringconvert(string s)
{
int p;
istringstream g(s);
while(g>>p)
arr[i++]=p;
}
*/
/*
ll Bigmod(ll base, ll power, ll mod)
{
if(power==0)
return 1%mod;
if(power==1)
return base%mod;
ll x = Bigmod(base,power/2,mod);
x = (x*x)%mod;
if(power%2){
x = (x*(base%mod))%mod;
}
return x;
}
*/
/*
ll modInverse(ll a, ll m)
{
return bigmod(a,m-2,m);
}
*/
/*
FOR BIGMOD
----------
template <typename T>
T mmul(T a, T b, T m)
{
a %= m;
T result = 0;
while (b)
{
if (b % 2) result = (result + a) % m;
a = (a + a) % m;
b /= 2;
}
return result;
}
template <typename T>
T mpow(T a, T b, T m) // a-->base b--->power m--->mod
{
a %= m;
T result = 1;
while (b)
{
if (b % 2) result = mmul(result, a, m);
a = mmul(a, a, m);
b /= 2;
}
return result;
}
*/
/*
bool isPrime( ll val )
{
if( val == 2 )
return true ;
if( val % 2 == 0 || val == 1 )
return false ;
ll sqrt_N = (ll) ( ( double ) sqrt( val ) ) ;
for( ll i = 3 ; i <= sqrt_N ; i += 2 ){
if( val % i == 0 )
return false ;
}
return true ;
}
*/
/*bool cmp(pll a,pll b) //vector<pair<ll,ll>>v; i=0; while(i<n){ cin>>num; v.push_back(make_pair(num,num%M)); i++;} sort(v.begin(),v.end(),cmp);
{
-----------------
----------------
}
*/
/*
GCD
----
int gcd(int a,int b)
{
if(b == 0)
return a;
else
return gcd(b,a%b);
}
*/
/*
Sieve
------
unsigned long long int Prime[300000],nPrime;
unsigned long long mark[1000002];
void sieve(int n)
{
int i,j,limit=sqrt(n*1.0)+2;
mark[1]=1;
for(i=4;i<=n;i+=2)
mark[i]=1;
Prime[nPrime++]=2;
for(i=3;i<=n;i+=2)
{
if(!mark[i])
{
Prime[nPrime++]=i;
if(i<=limit)
{
for(j=i*i;j<=n;j+=(i*2))
mark[j]=1;
}
}
}
}
*/
/**
Ordered set
------------
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T> using orderset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
orderset<int> s ; //orderset<int>::iterator it ;
orderset<int> X; //X.insert(1); //X.insert(2); //X.insert(4); //X.insert(8); //X.insert(16);
cout<<*X.find_by_order(1)<<endl; // 2 //cout<<*X.find_by_order(2)<<endl; // 4 //cout<<*X.find_by_order(4)<<endl; // 16 //cout<<(end(X)==X.find_by_order(6))<<endl; // true
cout<<X.order_of_key(-5)<<endl; // 0 //cout<<X.order_of_key(1)<<endl; // 0 //cout<<X.order_of_key(3)<<endl; // 2 //cout<<X.order_of_key(4)<<endl; // 2 //cout<<X.order_of_key(400)<<endl; // 5
*/
////============ CONSTANT ===============////
#define inf 1<<30 //infinity value
#define eps 1e-9
#define mx 100009
#define mod 1000000007
////=====================================////
int main()
{
//DP(0);
return 0;
}