From 81446f523e29989b3ed4f8f4173a8823c7c01f91 Mon Sep 17 00:00:00 2001 From: Anshul Garg <56505525+anshul07123@users.noreply.github.com> Date: Tue, 26 Oct 2021 14:58:36 +0530 Subject: [PATCH 1/8] Digit DP --- b.cpp | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 b.cpp diff --git a/b.cpp b/b.cpp new file mode 100644 index 0000000..ae17e8d --- /dev/null +++ b/b.cpp @@ -0,0 +1,89 @@ +#include +using namespace std; + +#define int long long +#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); +#define pb push_back +#define ff first +#define ss second +#define endl '\n' +#define mod 1000000007 + +int bin(int x, int n){ + int res=1; x%=mod; + while(n){ + if(n&1) res=(res*x)%mod; + x=(x*x)%mod; + n>>=1; + } + return res; +} + +int dp[19][2][75][2]; + +vector v; +int k; + +int fun(int ind, int f, int p, int sum, int f1){ + if(p > k) return 0; + if(ind == v.size()){return 1;} + if(dp[ind][f][sum][f1] != -1) return dp[ind][f][sum][f1]; + int ans = 0; + if(f == 0){ + if(f1){ + for(int i = 0; i < v[ind]; i++){ + ans += fun(ind + 1, 1, p * i, sum + i, 1); + } + ans += fun(ind + 1, 0, p * v[ind], sum + v[ind], 1); + } + else{ + for(int idx = 0; idx < v[ind]; idx++){ + if(idx == 0){ + ans += fun(ind + 1, 1, 1, sum + idx, 0); + } + else ans += fun(ind + 1, 1, p * idx, sum + idx, 1); + } + if(v[ind] != 0) ans += fun(ind + 1, 0, p * v[ind], sum + v[ind], 1); + else ans += fun(ind + 1, 0, 1, sum + v[ind], 0); + } + } + else{ + if(f1){ + for(int i = 0; i <= 9; i++){ + ans += fun(ind + 1, 1, p * i, sum + i, 1); + } + } + else{ + for(int i = 0; i <= 9; i++){ + if(i == 0){ + ans += fun(ind + 1, 1, 1, sum + i, 0); + } + else ans += fun(ind + 1, 1, p * i, sum + i, 1); + } + if(v[ind]) ans += fun(ind + 1, 1, p * v[ind], sum + v[ind], 1); + else (ans += fun(ind + 1, 1, 1, sum + v[ind], 0)); + } + } + return dp[ind][f][sum][f1] = ans; +} + +void solve(){ + int n; cin >> n >> k; + memset(dp, -1, sizeof(dp)); + int t = n; + while(t){ + v.pb(t % 10); + t /= 10; + } + reverse(v.begin(), v.end()); + cout << fun(0, 0, 1, 0, 0) - 1; +} + +signed main(){ + fast + int t = 1; + // cin >> t; + for(int i = 1; i <= t; i++){ + solve(); + } +} \ No newline at end of file From 41aa6a49aa1355d5bbb7ca5320f8b0f84c2592c1 Mon Sep 17 00:00:00 2001 From: Anshul Garg <56505525+anshul07123@users.noreply.github.com> Date: Tue, 26 Oct 2021 15:01:56 +0530 Subject: [PATCH 2/8] Add files via upload --- ab.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 ab.cpp diff --git a/ab.cpp b/ab.cpp new file mode 100644 index 0000000..998cb6c --- /dev/null +++ b/ab.cpp @@ -0,0 +1,35 @@ +#include +using namespace std; + +#define int long long +#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); +#define pb push_back +#define ff first +#define ss second +#define endl '\n' +#define mod 1000000007 +#define pi 3.14159265358979323846 + +int bin(int x, int n){ + int res = 1; x %= mod; + while(n){ + if(n&1) res = (res*x) % mod; + x = (x*x) % mod; + n >>= 1; + } + return res; +} + +void solve(){ + +} + +signed main(){ + fast + int t = 1; + // cin >> t; + for(int i = 1; i <= t; i++){ + // cout << "Case #" << i << ": "; + solve(); + } +} \ No newline at end of file From c7206727f712b2f49dec7d4ee3b7fdb5485d1a69 Mon Sep 17 00:00:00 2001 From: Anshul Garg <56505525+anshul07123@users.noreply.github.com> Date: Tue, 26 Oct 2021 15:03:08 +0530 Subject: [PATCH 3/8] Add files via upload --- q.cpp | 153 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 q.cpp diff --git a/q.cpp b/q.cpp new file mode 100644 index 0000000..a89899a --- /dev/null +++ b/q.cpp @@ -0,0 +1,153 @@ +#include +using namespace std; +#define int long long +#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); +#define pb push_back +#define ff first +#define ss second +#define rep(i,a,b) for(int i = a; i < b; i++) +#define repp(i,a,b) for(int i = a; i <= b; i++) +#define endl '\n' +#define all(v) v.begin(), v.end() +#define rall(v) v.rbegin(), v.rend() +#define mod 998244353 +#define mod_in(a) bin(a, mod - 2) +#define fact(n) rep(i, 1, n+1) ft.pb((ft[i-1] * i) % mod) +#define ncr(n, r) (n >= r ? ((ft[n] * mod_in((ft[r] * ft[(n)-(r)]) % mod)) % mod) : 0LL) +#define pi 3.14159265358979323 +#define INF 1e15 +#define lb(v, a) lower_bound(v.begin(), v.end(), a) +#define ub(v, a) upper_bound(v.begin(), v.end(), a) +#define deb(x) cerr<<#x<<" "< +// #include +// using namespace __gnu_pbds; +// template +// using ordered_set = tree,rb_tree_tag,tree_order_statistics_node_update>; +// template +// using ordered_multiset = tree,rb_tree_tag,tree_order_statistics_node_update>; +// #define os_find(k) find_by_order(k) +// #define os_order(k) order_of_key(k) +// //(**FOR USING ORDERED SET CHANGE INT**) + + +int power(int x, int n){ + int res=1; + while(n>0){ + if(n&1) + res=res*x; + x*=x; + n>>=1; + } + return res; +} + +int bin(int x, int n){ + int res=1; x%=mod; + while(n){ + if(n&1) res=(res*x)%mod; + x=(x*x)%mod; + n>>=1; + } + return res; +} + +bool prime(int n){ + if(n==3)return 1; + repp(i,2,sqrt(n)){ + if(n%i==0)return 0; + } + return 1; +} + +//DSU +void make_set(int u){ + par[u] = u; + sz[u] = 1; +} + +int find_set(int u){ + if(u == par[u]) return u; + return par[u] = find_set(par[u]); +} + +void union_set(int u, int v){ + int a = find_set(u); + int b = find_set(v); + if(a == b) return; + if(sz[a] < sz[b]) swap(a, b); + par[b] = a; + sz[a] += sz[b]; +} + +// Sieve +vector pr(1000005, 1); + +void sieve(int n){ + pr[1] = 0; pr[0] = 0; + for(int p = 2; p <= n; p++){ + if(pr[p] == 1){ + for(int i = p * p; i <= n; i += p){ + pr[i] = 0; + } + } + } +} + +int arr[200001], p[200001], h[200001], ans[200001], val[200001]; +int dp[200001][100]; +vector adj[200001]; + +void dfs(int n, int l, int p){ + h[n] = l; + dp[n][0] = p; + for(auto i : adj[n]){ + if(i != p){ + dfs(i, l + 1, n); + } + } +} + +void lca1(int n, int k){ + repp(i, 1, k){ + rep(j, 2, n + 1){ + if(dp[j][i-1] != -1) dp[j][i] = dp[dp[j][i-1]][i-1]; + } + } +} + +int lca(int x, int y, int k){ + if(h[x] > h[y]) swap(x, y); + int d = h[y] - h[x]; + while(d){ + int f = log2(d); + y = dp[y][f]; + d -= (1 << f); + } + if(y == x) return y; + for(int i = k; i >= 0; i--){ + if(dp[x][i] != -1 && (dp[x][i] != dp[y][i])) x = dp[x][i], y = dp[y][i]; + } + return dp[x][0]; +} + +void solve(){ + int n, q, c = 0;; cin >> n >> q; + memset(dp, -1, sizeof(dp)); + rep(i, 0, n - 1){ + int x, y; cin >> x >> y; + adj[x].pb(y); + adj[y].pb(x); + } + dfs(1, 0, -1); + int k = log2(n); + lca1(n, k); + while(q--){ + int x, y; cin >> x >> y; + int node = lca(x, y, k); + if(node == x or node == y) cout << abs(h[x] - h[y]) << endl; + else cout << h[x] + h[y] - 2 * h[node] << endl; + } +} From 954f0a4204cab14dd0efeae22cffdf6b50b12064 Mon Sep 17 00:00:00 2001 From: Anshul Garg <56505525+anshul07123@users.noreply.github.com> Date: Tue, 26 Oct 2021 15:04:43 +0530 Subject: [PATCH 4/8] Add files via upload From 1a3b9a0959397f3e4b2095f0d9d269bffdbb1984 Mon Sep 17 00:00:00 2001 From: Anshul Garg <56505525+anshul07123@users.noreply.github.com> Date: Tue, 26 Oct 2021 15:15:17 +0530 Subject: [PATCH 5/8] Uploading Q.cpp Pseudocode --- Global Round 11/q.cpp | 153 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 Global Round 11/q.cpp diff --git a/Global Round 11/q.cpp b/Global Round 11/q.cpp new file mode 100644 index 0000000..a89899a --- /dev/null +++ b/Global Round 11/q.cpp @@ -0,0 +1,153 @@ +#include +using namespace std; +#define int long long +#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); +#define pb push_back +#define ff first +#define ss second +#define rep(i,a,b) for(int i = a; i < b; i++) +#define repp(i,a,b) for(int i = a; i <= b; i++) +#define endl '\n' +#define all(v) v.begin(), v.end() +#define rall(v) v.rbegin(), v.rend() +#define mod 998244353 +#define mod_in(a) bin(a, mod - 2) +#define fact(n) rep(i, 1, n+1) ft.pb((ft[i-1] * i) % mod) +#define ncr(n, r) (n >= r ? ((ft[n] * mod_in((ft[r] * ft[(n)-(r)]) % mod)) % mod) : 0LL) +#define pi 3.14159265358979323 +#define INF 1e15 +#define lb(v, a) lower_bound(v.begin(), v.end(), a) +#define ub(v, a) upper_bound(v.begin(), v.end(), a) +#define deb(x) cerr<<#x<<" "< +// #include +// using namespace __gnu_pbds; +// template +// using ordered_set = tree,rb_tree_tag,tree_order_statistics_node_update>; +// template +// using ordered_multiset = tree,rb_tree_tag,tree_order_statistics_node_update>; +// #define os_find(k) find_by_order(k) +// #define os_order(k) order_of_key(k) +// //(**FOR USING ORDERED SET CHANGE INT**) + + +int power(int x, int n){ + int res=1; + while(n>0){ + if(n&1) + res=res*x; + x*=x; + n>>=1; + } + return res; +} + +int bin(int x, int n){ + int res=1; x%=mod; + while(n){ + if(n&1) res=(res*x)%mod; + x=(x*x)%mod; + n>>=1; + } + return res; +} + +bool prime(int n){ + if(n==3)return 1; + repp(i,2,sqrt(n)){ + if(n%i==0)return 0; + } + return 1; +} + +//DSU +void make_set(int u){ + par[u] = u; + sz[u] = 1; +} + +int find_set(int u){ + if(u == par[u]) return u; + return par[u] = find_set(par[u]); +} + +void union_set(int u, int v){ + int a = find_set(u); + int b = find_set(v); + if(a == b) return; + if(sz[a] < sz[b]) swap(a, b); + par[b] = a; + sz[a] += sz[b]; +} + +// Sieve +vector pr(1000005, 1); + +void sieve(int n){ + pr[1] = 0; pr[0] = 0; + for(int p = 2; p <= n; p++){ + if(pr[p] == 1){ + for(int i = p * p; i <= n; i += p){ + pr[i] = 0; + } + } + } +} + +int arr[200001], p[200001], h[200001], ans[200001], val[200001]; +int dp[200001][100]; +vector adj[200001]; + +void dfs(int n, int l, int p){ + h[n] = l; + dp[n][0] = p; + for(auto i : adj[n]){ + if(i != p){ + dfs(i, l + 1, n); + } + } +} + +void lca1(int n, int k){ + repp(i, 1, k){ + rep(j, 2, n + 1){ + if(dp[j][i-1] != -1) dp[j][i] = dp[dp[j][i-1]][i-1]; + } + } +} + +int lca(int x, int y, int k){ + if(h[x] > h[y]) swap(x, y); + int d = h[y] - h[x]; + while(d){ + int f = log2(d); + y = dp[y][f]; + d -= (1 << f); + } + if(y == x) return y; + for(int i = k; i >= 0; i--){ + if(dp[x][i] != -1 && (dp[x][i] != dp[y][i])) x = dp[x][i], y = dp[y][i]; + } + return dp[x][0]; +} + +void solve(){ + int n, q, c = 0;; cin >> n >> q; + memset(dp, -1, sizeof(dp)); + rep(i, 0, n - 1){ + int x, y; cin >> x >> y; + adj[x].pb(y); + adj[y].pb(x); + } + dfs(1, 0, -1); + int k = log2(n); + lca1(n, k); + while(q--){ + int x, y; cin >> x >> y; + int node = lca(x, y, k); + if(node == x or node == y) cout << abs(h[x] - h[y]) << endl; + else cout << h[x] + h[y] - 2 * h[node] << endl; + } +} From b4c4916b9d37d60b9e4d6a9eecd3a0f0d9b53b3e Mon Sep 17 00:00:00 2001 From: Anshul Garg <56505525+anshul07123@users.noreply.github.com> Date: Tue, 26 Oct 2021 15:17:01 +0530 Subject: [PATCH 6/8] ab.cpp --- Global Round 11/ab.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Global Round 11/ab.cpp diff --git a/Global Round 11/ab.cpp b/Global Round 11/ab.cpp new file mode 100644 index 0000000..998cb6c --- /dev/null +++ b/Global Round 11/ab.cpp @@ -0,0 +1,35 @@ +#include +using namespace std; + +#define int long long +#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); +#define pb push_back +#define ff first +#define ss second +#define endl '\n' +#define mod 1000000007 +#define pi 3.14159265358979323846 + +int bin(int x, int n){ + int res = 1; x %= mod; + while(n){ + if(n&1) res = (res*x) % mod; + x = (x*x) % mod; + n >>= 1; + } + return res; +} + +void solve(){ + +} + +signed main(){ + fast + int t = 1; + // cin >> t; + for(int i = 1; i <= t; i++){ + // cout << "Case #" << i << ": "; + solve(); + } +} \ No newline at end of file From e1ac23160058802205ae23d2af0c6b24fd4627f6 Mon Sep 17 00:00:00 2001 From: Anshul Garg <56505525+anshul07123@users.noreply.github.com> Date: Tue, 26 Oct 2021 15:30:27 +0530 Subject: [PATCH 7/8] C++ File --- c++.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 c++.cpp diff --git a/c++.cpp b/c++.cpp new file mode 100644 index 0000000..21344d1 --- /dev/null +++ b/c++.cpp @@ -0,0 +1,51 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +typedef long long ll; +using namespace std; + +const int INF = int(1e9); + +int main() { + ios_base::sync_with_stdio(false); + cin.tie(0); cout.tie(0); + + //ifstream fin; fin.open("input.txt"); + //ofstream fout; fout.open("output.txt"); + + ll a, b, c, d, ans = 0; + cin >> a >> b >> c >> d; + for (ll z = a; z <= b; ++z) { + int miii = max(d-z+1, c); + if (miii > c) + miii = 0; + else + miii = c - miii + 1; + ans += (b - a + 1)*miii; + for (ll y = b; y <= min(z - a, c); ++y) { + // z < x + y + // z - x > y + // - x > y - z + // x > z - y + ll minx = z - y + 1; // минимальная сторона + minx = max(minx, a); + if (minx > b) + minx = 0; + else + minx = b - minx + 1; + ans += minx; + } + } + cout << ans; + return 0; +} \ No newline at end of file From 34ca8e490b3687eecfa362693ed315280a81dd94 Mon Sep 17 00:00:00 2001 From: Anshul Garg <56505525+anshul07123@users.noreply.github.com> Date: Tue, 26 Oct 2021 15:31:57 +0530 Subject: [PATCH 8/8] abc.cpp Solution Code. --- abc.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 abc.cpp diff --git a/abc.cpp b/abc.cpp new file mode 100644 index 0000000..2da9a77 --- /dev/null +++ b/abc.cpp @@ -0,0 +1,44 @@ +////////////////////////////////////////////////////// +// .-. // +// |_:_| // +// /(_Y_)\ // +//. ( \/M\/ ) // +// '. _.'-/'-'\-'._ // +// ': _/.--'[[[[]'--.\_ // +// ': /_' : |::"| : '.\ // +// ': // ./ |oUU| \.' :\ // +// ': _:'..' \_|___|_/ : :| // +// ':. .' |_[___]_| :.':\ // +// [::\ | : | | : ; : \ // +// '-' \/'.| |.' \ .;.' | // +// |\_ \ '-' : | // +// | \ \ .: : | | // +// | \ | '. : \ | // +// / \ :. .; | // +// / | | :__/ : \\ // +// | | | \: | \ | || // +// / \ : : |: / |__| /| // +// | : : :_/_| /'._\ '--|_\ // +// /___.-/_|-' \ \ // +// '-' // +////////////////////////////////////////////////////// + + +#include + +using namespace std; + +#define int long long +#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); +#define pb push_back +#define ff first +#define ss second +#define rep(i,a,b) for(int i=a;i