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) {...