Lightoj 1070 – Algebraic Problem

Lightoj 1070 – Algebraic Problem

Problem Link Solution :- Algebraic Problem C++ /****************************************************************** *** Problem : *** *** Author : Shipu Ahamed (Psycho Timekiller) *** *** E-mail : shipuahamed01@gmail.com *** *** University : BUBT,Dept. of CSE *** *** My Blog : http://shipuahamed.blogspot.com *** *** Facebook : http://www.facebook.com/DeesheharaShipu *** ******************************************************************/ #include <stdio.h> #include <math.h> #include <stdlib.h> #include <string.h> #include <stack> #include <queue> #include <vector> #include <utility> #include <string> #include <sstream> #include <iostream> #include <set> #include <map> #include <algorithm> #include <memory.h> #include <functional> #include <numeric> #include <bits/stdc++.h> using namespace std; #define pi 2*acos(0.0) #define all(v) v.begin(),v.end() //input #define si(t) scanf("%d",&t) #define sl(t) scanf("%lld",&t) #define sf(t) scanf("%f",&t) #define sd(t) scanf("%lf",&t) #define sc(c) scanf("%c",&c) #define sii(a,b) scanf("%d%d",&a,&b) #define sll(a,b) scanf("%lld%lld",&a,&b) //Output #define P(a) printf("%dn",a) #define PL(a) printf("%lldn",a) #define PF(a) printf("%fn",a) #define PD(a) printf("%lfn",a) #define PS(a) printf("%sn",a) #define PSN(a) printf("%s ",a) #define PN(a) printf("%d ",a) #define PLN(a) printf("%lld ",a) #define PFN(a) printf("%f ",a) #define PDN(a) printf("%lf ",a) #define PP(a,b) printf("%d %dn",a,b) #define PPN(a,b) printf("%d %d ",a,b) #define PPL(a,b) printf("%lld %lldn",a,b) #define PPLN(a,b) printf("%lld %lld ",a,b) #define CP(a) cout<<a<<endl #define CPN(a) cout<<a<<" " #define ff first #define se second #define pb push_back #define ST(v) sort(all(v)) #define sz(x) (int)x.size() #define gcd(a,b) __gcd(a,b) #define lcm(a,b) (a*(b/gcd(a,b))) #define max3(a,b,c) max(a,max(b,c)) #define min3(a,b,c) min(a,min(b,c)) #define maxall(v) *max_element(all(v)) #define minall(v) *min_element(all(v)) #define sqr(a) ((a)*(a)) #define abs(x) (((x)<0)?-(x):(x)) #define cover(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 #define btz(a) __builtin_ctz(a) //count binary trailling zero #define un(v) ST(v), (v).erase(unique(all(v)),v.end()) #define common(a,b) ST(a), ST(b), a.erase(set_intersection(all(a),all(b),a.begin()),a.end()) #define uncommon(a,b) ST(a), ST(b), a.erase(set_symmetric_difference(all(a),all(b),a.begin()),a.end()) typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vll; typedef...
Lightoj 1183 – Computing Fast Average

Lightoj 1183 – Computing Fast Average

Problem Link Solution :- Computing Fast Average C++ #include <bits/stdc++.h> using namespace std; #define pi 2*acos(0.0) #define all(v) v.begin(),v.end() #define coff ios_base::sync_with_stdio(0); #define ff first #define se second #define pb push_back #define sz(a) ((int)a.size()) #define ST(v) sort(all(v)) #define gcd(a,b) __gcd(a,b) #define lcm(a,b) (a*(b/gcd(a,b))) #define max3(a,b,c) max(a,max(b,c)) #define min3(a,b,c) min(a,min(b,c)) #define cover(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 #define btz(a) __builtin_ctz(a) //count binary trailling zero #define un(v) ST(v), (v).erase(unique(all(v)),v.end()) #define common(a,b) ST(a), ST(b), a.erase(set_intersection(all(a),all(b),a.begin()),a.end()) #define uncommon(a,b) ST(a), ST(b), a.erase(set_symmetric_difference(all(a),all(b),a.begin()),a.end()) typedef long long ll; typedef unsigned long long ull; 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;} //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()) //Debug #define dbg(x) cout<<#x<<'='<<x<<endl; #define dbgarr(i,a) cout<<#a<<"["<<i<<"] = "<<a[i]<<" "<<endl; #define nl puts("") //File input/output #define input freopen("in.txt","r",stdin) #define output freopen("out.txt","w",stdout) ll bigmod(ll a,ll b, ll m) { ll res = 1; while(b) { if(b & 1) { res = ( (res % m) * (a % m) ) %m ; } a= ((a%m) * (a%m)) %m; b >>= 1; } return res; } ll modInverse(ll a, ll m){return bigmod(a,m-2,m);} ////============ CONSTANT ===============//// #define inf 1<<30 //infinity value #define eps 1e-9 #define mx 100009 #define mod 1000000007 ////=====================================//// struct info { int lazy,sum; info() : lazy(-1), sum(0) {} }tree[4*mx]; void update_lazy(int node, int st, int en, int val) { tree[node].lazy = val; tree[node].sum = (en-st+1)*val; } void update_node(int node, int st, int en) { int left=node<<1; int right=left+1; int mid = (st+en)>>1; tree[left].lazy=tree[right].lazy=tree[node].lazy; tree[left].sum= (mid-st+1)*tree[left].lazy; tree[right].sum= (en-mid)*tree[right].lazy;...
Lightoj 1164 – Horrible Queries

Lightoj 1164 – Horrible Queries

Problem Link Solution :- Horrible Queries C++ #include <bits/stdc++.h> using namespace std; #define pi 2*acos(0.0) #define all(v) v.begin(),v.end() #define coff ios_base::sync_with_stdio(0); #define ff first #define se second #define pb push_back #define sz(a) ((int)a.size()) #define ST(v) sort(all(v)) #define gcd(a,b) __gcd(a,b) #define lcm(a,b) (a*(b/gcd(a,b))) #define max3(a,b,c) max(a,max(b,c)) #define min3(a,b,c) min(a,min(b,c)) #define cover(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 #define btz(a) __builtin_ctz(a) //count binary trailling zero #define un(v) ST(v), (v).erase(unique(all(v)),v.end()) #define common(a,b) ST(a), ST(b), a.erase(set_intersection(all(a),all(b),a.begin()),a.end()) #define uncommon(a,b) ST(a), ST(b), a.erase(set_symmetric_difference(all(a),all(b),a.begin()),a.end()) typedef long long ll; typedef unsigned long long ull; 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;} //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()) //Debug #define dbg(x) cout<<#x<<'='<<x<<endl; #define dbgarr(i,a) cout<<#a<<"["<<i<<"] = "<<a[i]<<" "<<endl; #define nl puts("") //File input/output #define input freopen("in.txt","r",stdin) #define output freopen("out.txt","w",stdout) ll bigmod(ll a,ll b, ll m) { ll res = 1; while(b) { if(b & 1) { res = ( (res % m) * (a % m) ) %m ; } a= ((a%m) * (a%m)) %m; b >>= 1; } return res; } ll modInverse(ll a, ll m){return bigmod(a,m-2,m);} ////============ CONSTANT ===============//// #define inf 1<<30 //infinity value #define eps 1e-9 #define mx 100009 #define mod 1000000007 ////=====================================//// struct info { ll lazy,sum; }tree[4*mx]; void update_lazy(int node, int st, int en, int val) { tree[node].lazy += val; tree[node].sum += (en-st+1)*val; } void update_node(int node, int st, int en,int val) { tree[node].sum+=(en-st+1)*val; } void marge(int node,int st,int en) { int left=node<<1; tree[node].sum= tree[left].sum + tree[left+1].sum; } void update(int node,...
Lightoj 1087 – Diablo

Lightoj 1087 – Diablo

Problem Link Solution :- Diablo C++ #include <bits/stdc++.h> using namespace std; #define pi 2*acos(0.0) #define all(v) v.begin(),v.end() #define coff ios_base::sync_with_stdio(0); #define ff first #define se second #define pb push_back #define sz(a) ((int)a.size()) #define ST(v) sort(all(v)) #define gcd(a,b) __gcd(a,b) #define lcm(a,b) (a*(b/gcd(a,b))) #define max3(a,b,c) max(a,max(b,c)) #define min3(a,b,c) min(a,min(b,c)) #define cover(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 #define btz(a) __builtin_ctz(a) //count binary trailling zero #define un(v) ST(v), (v).erase(unique(all(v)),v.end()) #define common(a,b) ST(a), ST(b), a.erase(set_intersection(all(a),all(b),a.begin()),a.end()) #define uncommon(a,b) ST(a), ST(b), a.erase(set_symmetric_difference(all(a),all(b),a.begin()),a.end()) typedef long long ll; typedef unsigned long long ull; 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;} //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()) //Debug #define dbg(x) cout<<#x<<'='<<x<<endl; #define dbgarr(i,a) cout<<#a<<"["<<i<<"] = "<<a[i]<<" "<<endl; #define nl puts("") //File input/output #define input freopen("in.txt","r",stdin) #define output freopen("out.txt","w",stdout) ll bigmod(ll a,ll b, ll m) { ll res = 1; while(b) { if(b & 1) { res = ( (res % m) * (a % m) ) %m ; } a= ((a%m) * (a%m)) %m; b >>= 1; } return res; } ll modInverse(ll a, ll m){return bigmod(a,m-2,m);} ////============ CONSTANT ===============//// #define inf 1<<30 //infinity value #define eps 1e-9 #define mx 100009 #define mod 1000000007 ////=====================================//// struct info //for combine single update segment tree and range update segment tree { int sum,value,pos; info() : sum(0),value(0),pos(0){} }tree[6*mx]; int limit; void update_node(int node, int i, int val,int visibility) { tree[node].pos = i; tree[node].value = val; tree[node].sum = visibility; } void marge(int node, int left, int right) { tree[node].sum= tree[left].sum...
Lightoj 1135 – Count the Multiples of 3

Lightoj 1135 – Count the Multiples of 3

Problem Link Solution :- Count the Multiples of 3 C++ #include <bits/stdc++.h> using namespace std; #define pi 2*acos(0.0) #define all(v) v.begin(),v.end() #define coff ios_base::sync_with_stdio(0); #define ff first #define se second #define pb push_back #define sz(a) ((int)a.size()) #define ST(v) sort(all(v)) #define gcd(a,b) __gcd(a,b) #define lcm(a,b) (a*(b/gcd(a,b))) #define max3(a,b,c) max(a,max(b,c)) #define min3(a,b,c) min(a,min(b,c)) #define cover(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 #define btz(a) __builtin_ctz(a) //count binary trailling zero #define un(v) ST(v), (v).erase(unique(all(v)),v.end()) #define common(a,b) ST(a), ST(b), a.erase(set_intersection(all(a),all(b),a.begin()),a.end()) #define uncommon(a,b) ST(a), ST(b), a.erase(set_symmetric_difference(all(a),all(b),a.begin()),a.end()) typedef long long ll; typedef unsigned long long ull; 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;} //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()) //Debug #define dbg(x) cout<<#x<<'='<<x<<endl; #define dbgarr(i,a) cout<<#a<<"["<<i<<"] = "<<a[i]<<" "<<endl; #define nl puts("") //File input/output #define input freopen("in.txt","r",stdin) #define output freopen("out.txt","w",stdout) ll bigmod(ll a,ll b, ll m) { ll res = 1; while(b) { if(b & 1) { res = ( (res % m) * (a % m) ) %m ; } a= ((a%m) * (a%m)) %m; b >>= 1; } return res; } ll modInverse(ll a, ll m){return bigmod(a,m-2,m);} ////============ CONSTANT ===============//// #define inf 1<<30 //infinity value #define eps 1e-9 #define mx 100009 #define mod 1000000007 ////=====================================//// struct info //for combine single update segment tree and range update segment tree { int zero,one,two,lazy; }tree[6*mx]; void update_lazy(int node) { int temp = tree[node].zero; tree[node].zero=tree[node].two; tree[node].two=tree[node].one; tree[node].one=temp; } void update_node(int node,int left) { tree[left].lazy += tree[node].lazy; tree[left+1].lazy += tree[node].lazy; tree[node].lazy%=3; int shift = tree[node].lazy; while(shift) {...
Lightoj 1255 – Substring Frequency

Lightoj 1255 – Substring Frequency

Problem Link Solution :- Substring Frequency C++ /****************************************************************** *** Problem : *** *** Author : Shipu Ahamed (Psycho Timekiller) *** *** E-mail : shipuahamed01@gmail.com *** *** University : BUBT,Dept. of CSE *** *** Team : BUBT_Psycho *** *** My Blog : http://shipuahamed.blogspot.com *** *** Facebook : http://www.facebook.com/DeesheharaShipu *** ******************************************************************/ #include <stdio.h> #include <math.h> #include <stdlib.h> #include <string.h> #include <stack> #include <queue> #include <vector> #include <utility> #include <string> #include <sstream> #include <iostream> #include <set> #include <map> #include <algorithm> #include <memory.h> #include <functional> #include <numeric> #include <bits/stdc++.h> using namespace std; #define pi 2*acos(0.0) #define all(v) v.begin(),v.end() #define CP(a) cout<<a<<endl #define CPN(a) cout<<a<<" " #define ff first #define se second #define pb push_back #define ST(v) sort(all(v)) #define sz(x) (int)x.size() #define gcd(a,b) __gcd(a,b) #define lcm(a,b) (a*(b/gcd(a,b))) #define max3(a,b,c) max(a,max(b,c)) #define min3(a,b,c) min(a,min(b,c)) #define maxall(v) *max_element(all(v)) #define minall(v) *min_element(all(v)) #define sqr(a) ((a)*(a)) #define abs(x) (((x)<0)?-(x):(x)) #define cover(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 #define btz(a) __builtin_ctz(a) //count binary trailling zero #define un(v) ST(v), (v).erase(unique(all(v)),v.end()) #define common(a,b) ST(a), ST(b), a.erase(set_intersection(all(a),all(b),a.begin()),a.end()) #define uncommon(a,b) ST(a), ST(b), a.erase(set_symmetric_difference(all(a),all(b),a.begin()),a.end()) typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<string> vs; typedef set<int> si; typedef set<string> ss; typedef map<int,int> mii; typedef map<ll,ll> mll; typedef map<string,int> msi; typedef map<char,int> mci; template <typename T>string toString( T Number ){stringstream st;st << Number;return st.str();} template <typename T> T SOD(T n) {__typeof(n) sum=0;for(__typeof(n) i=1;i*i<=n;i++)sum+=(n%i)?0:((i*i==n)?i:i+n/i);return sum;} //For Define #define forab(i,a,b) for(__typeof(b) i=(a);i<=(b);i++) #define for0(i,n) forab(i,0,(n)-1) #define for1(i,n) forab(i,1,n) #define rforab(i,b,a) for(__typeof(b) i=(b);i>=(a);i--) #define rfor0(i,n) rforab(i,(n)-1,0) #define rfor1(i,n) rforab(i,n,1) #define forstl(i,s) for(__typeof((s).end()) i=(s).begin(); i != (s).end(); i++)...