diff --git a/CodeForces_Live_Contest/Educational_Round/150_Div_2/q1/.cph/.1.cpp_4cc8020798e185e8872469deee48d6d6.prob b/CodeForces_Live_Contest/Educational_Round/150_Div_2/q1/.cph/.1.cpp_4cc8020798e185e8872469deee48d6d6.prob new file mode 100644 index 0000000..dc6805b --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/150_Div_2/q1/.cph/.1.cpp_4cc8020798e185e8872469deee48d6d6.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\150_Div_2\\q1\\1.cpp","tests":[{"id":1686580888240,"input":"2\n3\n6","output":"Bob\nAlice"},{"id":1686585353383,"input":"2\n10\n11","output":""}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\150_Div_2\\q1\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/150_Div_2/q1/1.bin b/CodeForces_Live_Contest/Educational_Round/150_Div_2/q1/1.bin new file mode 100644 index 0000000..8bcc187 Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/150_Div_2/q1/1.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/150_Div_2/q1/1.cpp b/CodeForces_Live_Contest/Educational_Round/150_Div_2/q1/1.cpp new file mode 100644 index 0000000..fb6e601 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/150_Div_2/q1/1.cpp @@ -0,0 +1,109 @@ +#include +using namespace std; + +// Policy based data structures(PBDS) C++ STL +// order_of_key(k): returns count of elements strictly smaller than k +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +template using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; +template using ordered_map = tree, rb_tree_tag, tree_order_statistics_node_update>; + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + +void _print(long long t) {cerr << t;} +void _print(string t) {cerr << t;} +void _print(char t) {cerr << t;} +void _print(long double t) {cerr << t;} + +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#define ll long long +#define int ll +#define ld long double +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << endl; +#define no cout << "NO" << endl; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< isPrime(N , 1) ; +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) ; // a random number generator (RNG) using the Mersenne Twister algorithm, specifically the mt19937 engine. The purpose of an RNG is to generate a sequence of random numbers. + +int gcd(int a, int b){if(b == 0){return a;} return gcd(b, a % b);} +int lcm(int a, int b){return (a / gcd(a, b) * b) ;} +bool comparatorfunction(pair &a, pair &b){if(a.S != b.S){return a.S < b.S ;}return a.F > b.F ;} +int power(int x, int y){int res = 1 ; while(y > 0) {if(y & 1) res = (res * x) ; x = (x * x) ; y = y >> 1 ;} return res ;} +int powermod(int x, int y){int res = 1; x = x % mod97; while(y > 0){if(y&1) res = (res * x) % mod97; y = y >> 1; x = (x * x) % mod97 ;}return res ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +void prime(){isPrime[0]=isPrime[1]=false;for(int i = 2; i <= N; ++i){if(isPrime[i] == true){for(int j = 2*i; j <= N; j += i){isPrime[j] = false;}}}} +void spf(){for(int i = 0; i <= N; ++i) SPF[i] = i; for(int i = 2; i <= N; ++i) if(SPF[i] == i) for(int j = i; j <= N; j += i) if(SPF[j] == j) SPF[j] = i;} // SPF is the smallest prime number that divides a given number without leaving a remainder +int isqrt(int n){long long x = sqrtl(n);while (x*x>n){--x;} while((x+1) * (x+1)<=n){++x;}return x;} +int sqrtprecision(int l,int r,int target){while(r-l>EPS){int mid=(l+(r-l)/2);if(mid*mid&a,int target){int ans=-1; while(l <= r){int mid=(l+(r-l)/2); if(a[mid]==target){ans=mid;return ans;}if(a[mid](l, r)(rng);} + +bool solve(){ + int n ; + cin >> n ; + if(n <= 4) cout << "Bob" << nl ; + else cout << "Alice" << nl ; + return true ; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t; + cin >> t; + //int count = 1; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++; + }else{ + // cout << "NO" << endl; + } + } + return 0; +} + + + + +// Think twice, code once. \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/150_Div_2/q2/.cph/.1.cpp_40eaebb32b2fb283c0bacdf10d46fc0a.prob b/CodeForces_Live_Contest/Educational_Round/150_Div_2/q2/.cph/.1.cpp_40eaebb32b2fb283c0bacdf10d46fc0a.prob new file mode 100644 index 0000000..ab3a2f3 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/150_Div_2/q2/.cph/.1.cpp_40eaebb32b2fb283c0bacdf10d46fc0a.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\150_Div_2\\q2\\1.cpp","tests":[{"id":1686581132006,"input":"3\n9\n3 7 7 9 2 4 6 3 4\n5\n1 1 1 1 1\n5\n3 2 1 2 3","output":"111110010\n11111\n11011"},{"id":1686590145448,"input":"1\n8\n3 2 3 4 1 3 2 2","output":""},{"id":1686590507470,"input":"1\n19\n0 4 15 18 4 10 12 8 13 8 15 0 14 12 10 12 10 14 13","output":""}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\150_Div_2\\q2\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/150_Div_2/q2/1.bin b/CodeForces_Live_Contest/Educational_Round/150_Div_2/q2/1.bin new file mode 100644 index 0000000..1520304 Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/150_Div_2/q2/1.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/150_Div_2/q2/1.cpp b/CodeForces_Live_Contest/Educational_Round/150_Div_2/q2/1.cpp new file mode 100644 index 0000000..ceff0ee --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/150_Div_2/q2/1.cpp @@ -0,0 +1,129 @@ +#include +using namespace std; + +// Policy based data structures(PBDS) C++ STL +// order_of_key(k): returns count of elements strictly smaller than k +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +template using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; +template using ordered_map = tree, rb_tree_tag, tree_order_statistics_node_update>; + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + +void _print(long long t) {cerr << t;} +void _print(string t) {cerr << t;} +void _print(char t) {cerr << t;} +void _print(long double t) {cerr << t;} + +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#define ll long long +#define int ll +#define ld long double +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << endl; +#define no cout << "NO" << endl; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< isPrime(N , 1) ; +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) ; // a random number generator (RNG) using the Mersenne Twister algorithm, specifically the mt19937 engine. The purpose of an RNG is to generate a sequence of random numbers. + +int gcd(int a, int b){if(b == 0){return a;} return gcd(b, a % b);} +int lcm(int a, int b){return (a / gcd(a, b) * b) ;} +bool comparatorfunction(pair &a, pair &b){if(a.S != b.S){return a.S < b.S ;}return a.F > b.F ;} +int power(int x, int y){int res = 1 ; while(y > 0) {if(y & 1) res = (res * x) ; x = (x * x) ; y = y >> 1 ;} return res ;} +int powermod(int x, int y){int res = 1; x = x % mod97; while(y > 0){if(y&1) res = (res * x) % mod97; y = y >> 1; x = (x * x) % mod97 ;}return res ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +void prime(){isPrime[0]=isPrime[1]=false;for(int i = 2; i <= N; ++i){if(isPrime[i] == true){for(int j = 2*i; j <= N; j += i){isPrime[j] = false;}}}} +void spf(){for(int i = 0; i <= N; ++i) SPF[i] = i; for(int i = 2; i <= N; ++i) if(SPF[i] == i) for(int j = i; j <= N; j += i) if(SPF[j] == j) SPF[j] = i;} // SPF is the smallest prime number that divides a given number without leaving a remainder +int isqrt(int n){long long x = sqrtl(n);while (x*x>n){--x;} while((x+1) * (x+1)<=n){++x;}return x;} +int sqrtprecision(int l,int r,int target){while(r-l>EPS){int mid=(l+(r-l)/2);if(mid*mid&a,int target){int ans=-1; while(l <= r){int mid=(l+(r-l)/2); if(a[mid]==target){ans=mid;return ans;}if(a[mid](l, r)(rng);} + +bool solve(){ + int n ; + cin >> n ; + iv(v , n) + int up = 1 ; + int down = 1 ; + vector vis(n , 0) ; + int tt = 1e15 ; + int com = 0 ; + for(int i = 0 ; i < n ; ++i){ + if(com <= v[i] && up && down){ + vis[i] = 1 ; + com = v[i] ; + } + else if(v[i] < com && v[0] >= v[i] && up){ + up = 0 ; + down = 0 ; + vis[i] = 1 ; + com = v[i] ; + }else if(up == 0 && v[i] >= com && v[0] >= v[i]){ + com = v[i] ; + vis[i] = 1 ; + } + } + check1(vis) + return true; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t; + cin >> t; + //int count = 1; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++; + }else{ + // cout << "NO" << endl; + } + } + return 0; +} + + + + +// Think twice, code once. // kismat ka khel sara \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/150_Div_2/q3/.cph/.1.cpp_bfca928856a5958c6687539859257b3d.prob b/CodeForces_Live_Contest/Educational_Round/150_Div_2/q3/.cph/.1.cpp_bfca928856a5958c6687539859257b3d.prob new file mode 100644 index 0000000..af81e6f --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/150_Div_2/q3/.cph/.1.cpp_bfca928856a5958c6687539859257b3d.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\150_Div_2\\q3\\1.cpp","tests":[{"id":1686581836044,"input":"4\nDAAABDCA\nAB\nABCDEEDCBA\nDDDDAAADDABECD\n","output":"11088\n10010\n31000\n15886\n"},{"id":1686583083380,"input":"1\nAAAAEEBBCD","output":""}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\150_Div_2\\q3\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/150_Div_2/q3/1.bin b/CodeForces_Live_Contest/Educational_Round/150_Div_2/q3/1.bin new file mode 100644 index 0000000..903b586 Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/150_Div_2/q3/1.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/150_Div_2/q3/1.cpp b/CodeForces_Live_Contest/Educational_Round/150_Div_2/q3/1.cpp new file mode 100644 index 0000000..335a5e1 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/150_Div_2/q3/1.cpp @@ -0,0 +1,153 @@ +#include +using namespace std; + +// Policy based data structures(PBDS) C++ STL +// order_of_key(k): returns count of elements strictly smaller than k +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +template using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; +template using ordered_map = tree, rb_tree_tag, tree_order_statistics_node_update>; + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + +void _print(long long t) {cerr << t;} +void _print(string t) {cerr << t;} +void _print(char t) {cerr << t;} +void _print(long double t) {cerr << t;} + +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#define ll long long +#define int ll +#define ld long double +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << endl; +#define no cout << "NO" << endl; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< isPrime(N , 1) ; +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) ; // a random number generator (RNG) using the Mersenne Twister algorithm, specifically the mt19937 engine. The purpose of an RNG is to generate a sequence of random numbers. + +int gcd(int a, int b){if(b == 0){return a;} return gcd(b, a % b);} +int lcm(int a, int b){return (a / gcd(a, b) * b) ;} +bool comparatorfunction(pair &a, pair &b){if(a.S != b.S){return a.S < b.S ;}return a.F > b.F ;} +int power(int x, int y){int res = 1 ; while(y > 0) {if(y & 1) res = (res * x) ; x = (x * x) ; y = y >> 1 ;} return res ;} +int powermod(int x, int y){int res = 1; x = x % mod97; while(y > 0){if(y&1) res = (res * x) % mod97; y = y >> 1; x = (x * x) % mod97 ;}return res ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +void prime(){isPrime[0]=isPrime[1]=false;for(int i = 2; i <= N; ++i){if(isPrime[i] == true){for(int j = 2*i; j <= N; j += i){isPrime[j] = false;}}}} +void spf(){for(int i = 0; i <= N; ++i) SPF[i] = i; for(int i = 2; i <= N; ++i) if(SPF[i] == i) for(int j = i; j <= N; j += i) if(SPF[j] == j) SPF[j] = i;} // SPF is the smallest prime number that divides a given number without leaving a remainder +int isqrt(int n){long long x = sqrtl(n);while (x*x>n){--x;} while((x+1) * (x+1)<=n){++x;}return x;} +int sqrtprecision(int l,int r,int target){while(r-l>EPS){int mid=(l+(r-l)/2);if(mid*mid&a,int target){int ans=-1; while(l <= r){int mid=(l+(r-l)/2); if(a[mid]==target){ans=mid;return ans;}if(a[mid](l, r)(rng);} + +bool solve(){ + string s ; + cin >> s ; + int n = s.size() ; + int sum = 0 ; + reverse(all(s)) ; + vector vis(n , 0) ; + char c = 'A' ; + for(int i = 0 ; i < n ; ++i){ + if(s[i] >= c) { + c = s[i] ; + }else{ + vis[i] = 1 ; + } + } + int best_replace = 0 ; + char cc = 'A' ; + for(int i = 0 ; i < n ; ++i){ + if(vis[i] == 1){ + if(s[i] >= cc && s[i] != c){ + cc = s[i] ; + best_replace = i ; + } + } + } + // cout << s << nl ; + reverse(all(vis)) ; + check1(vis) ; + // cout << best_replace << " " ; + s[best_replace] = 'E' ; + char care = 'A' ; + for(int i = 0 ; i < n ; ++i){ + if(s[i] >= care){ + if(s[i] == 'A') sum += 1 ; + if(s[i] == 'B') sum += 10 ; + if(s[i] == 'C') sum += 100 ; + if(s[i] == 'D') sum += 1000 ; + if(s[i] == 'E') sum += 10000 ; + care = s[i] ; + }else{ + if(s[i] == 'A') sum -= 1 ; + if(s[i] == 'B') sum -= 10 ; + if(s[i] == 'C') sum -= 100 ; + if(s[i] == 'D') sum -= 1000 ; + if(s[i] == 'E') sum -= 10000 ; + } + + } + cout << sum << nl ; + return true; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t; + cin >> t; + //int count = 1; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++; + }else{ + // cout << "NO" << endl; + } + } + return 0; +} + + + + +// Think twice, code once. \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/150_Div_2/q4/1.cpp b/CodeForces_Live_Contest/Educational_Round/150_Div_2/q4/1.cpp new file mode 100644 index 0000000..e69de29 diff --git a/CodeForces_Live_Contest/Educational_Round/152_Div_2/q1/.cph/.1.cpp_a64e7d3e960192a8177e82cb83631de1.prob b/CodeForces_Live_Contest/Educational_Round/152_Div_2/q1/.cph/.1.cpp_a64e7d3e960192a8177e82cb83631de1.prob new file mode 100644 index 0000000..73a1abd --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/152_Div_2/q1/.cph/.1.cpp_a64e7d3e960192a8177e82cb83631de1.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\152_Div_2\\q1\\1.cpp","tests":[{"id":1690468895754,"input":"3\n2 1 1\n10 1 2\n3 7 8\n","output":""}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\152_Div_2\\q1\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/152_Div_2/q1/1.bin b/CodeForces_Live_Contest/Educational_Round/152_Div_2/q1/1.bin new file mode 100644 index 0000000..699cc72 Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/152_Div_2/q1/1.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/152_Div_2/q1/1.cpp b/CodeForces_Live_Contest/Educational_Round/152_Div_2/q1/1.cpp new file mode 100644 index 0000000..609801e --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/152_Div_2/q1/1.cpp @@ -0,0 +1,119 @@ +#include +using namespace std; + +// Policy based data structures(PBDS) C++ STL +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// order_of_key(k): returns count of elements strictly smaller than k +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // for pairs only define simply by ordered_set s +typedef tree, null_type, less_equal>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset; +templateusing Tree = tree, rb_tree_tag, tree_order_statistics_node_update> ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree> s; for pairs + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + +void _print(long long t) {cerr << t;} +void _print(string t) {cerr << t;} +void _print(char t) {cerr << t;} +void _print(long double t) {cerr << t;} + +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#define ll long long // typedef array ii; pair h ye +#define int ll +#define ld long double +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << endl; +#define no cout << "NO" << endl; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< &a, pair &b){if(a.S != b.S){return a.S < b.S ;}return a.F > b.F ;} +int power(int x, int y){int res = 1 ; while(y > 0) {if(y & 1) res = (res * x) ; x = (x * x) ; y = y >> 1 ;} return res ;} +int modpower(int x, int y){int res = 1; x = x % mod97; while(y > 0){if(y&1) res = (res * x) % mod97; y = y >> 1; x = (x * x) % mod97 ;}return res ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +vector giveme_it_isprime_or_not(int n){vector isPrime(n+1, 1);isPrime[0]=isPrime[1]=false;for(int i = 2; i <= N; ++i){if(isPrime[i] == true){for(int j = 2*i; j <= N; j += i){isPrime[j] = false;}}} return isPrime;} +vector givemeprimes(int n) {int*arr = new int[n + 1](); vector vect; for(int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for(int j = i * i; j <= n; j += i)arr[j] = 1;} return vect;} +vector> givemedivisors(int n){int*arr = new int[n + 1]();vector > vect(n + 1);for(int i = 2; i <= n; ++i){if(arr[i] == 0){for(int j = i; j <= n; j += i){vect[j].pb(i);arr[i] = 1;}}} return vect ;} +vector givemesmallestprimefactors(int n){vector SPF(n + 1);for(int i = 0; i <= N; ++i){SPF[i] = i;}for(int i = 2; i <= N; ++i){if(SPF[i] == i){for(int j = i; j <= N; j += i){if(SPF[j] == j){SPF[j] = i;}}}}return SPF ;} // SPF is the smallest prime number that divides a given number without leaving a remainder +int sqrtprecision(int l,int r,int target){while(r-l>EPS){int mid=(l+(r-l)/2);if(mid*mid(l, r)(rng);} + +bool solve(){ + int n , m , k ; + cin >> n >> m >> k ; + int sum = m + k ; + if(sum > n){ + cout << n + n - 1 << nl ; + } + else if(n > sum){ + cout << sum + sum + 1 << nl ; + } + else if(sum == n){ + cout << n + n - 1 << nl ; + } + return true ; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t; + cin >> t; + //int count = 1; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++; + }else{ + // no + } + } + return 0; +} + + + + // Don't overthink and try to prove your idea. \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/152_Div_2/q2/.cph/.1.cpp_6ecf21eaaa9c8a677343bdfba76c2d60.prob b/CodeForces_Live_Contest/Educational_Round/152_Div_2/q2/.cph/.1.cpp_6ecf21eaaa9c8a677343bdfba76c2d60.prob new file mode 100644 index 0000000..3dc8709 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/152_Div_2/q2/.cph/.1.cpp_6ecf21eaaa9c8a677343bdfba76c2d60.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\152_Div_2\\q2\\1.cpp","tests":[{"id":1690469436041,"input":"3\n3 2\n1 2 3\n2 3\n1 1\n4 3\n2 8 3 5","output":"2 1 3 \n1 2 \n3 1 2 4"},{"id":1690470070901,"input":"1\n2 5\n7 6","output":""}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\152_Div_2\\q2\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/152_Div_2/q2/1.bin b/CodeForces_Live_Contest/Educational_Round/152_Div_2/q2/1.bin new file mode 100644 index 0000000..fa3b496 Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/152_Div_2/q2/1.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/152_Div_2/q2/1.cpp b/CodeForces_Live_Contest/Educational_Round/152_Div_2/q2/1.cpp new file mode 100644 index 0000000..724fd44 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/152_Div_2/q2/1.cpp @@ -0,0 +1,126 @@ +#include +using namespace std; + +// Policy based data structures(PBDS) C++ STL +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// order_of_key(k): returns count of elements strictly smaller than k +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // for pairs only define simply by ordered_set s +typedef tree, null_type, less_equal>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset; +templateusing Tree = tree, rb_tree_tag, tree_order_statistics_node_update> ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree> s; for pairs + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + +void _print(long long t) {cerr << t;} +void _print(string t) {cerr << t;} +void _print(char t) {cerr << t;} +void _print(long double t) {cerr << t;} + +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#define ll long long // typedef array ii; pair h ye +#define int ll +#define ld long double +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << endl; +#define no cout << "NO" << endl; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< &a, pair &b){if(a.F == b.F){return a.S < b.S ;}return a.F > b.F ;} +int power(int x, int y){int res = 1 ; while(y > 0) {if(y & 1) res = (res * x) ; x = (x * x) ; y = y >> 1 ;} return res ;} +int modpower(int x, int y){int res = 1; x = x % mod97; while(y > 0){if(y&1) res = (res * x) % mod97; y = y >> 1; x = (x * x) % mod97 ;}return res ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +vector giveme_it_isprime_or_not(int n){vector isPrime(n+1, 1);isPrime[0]=isPrime[1]=false;for(int i = 2; i <= N; ++i){if(isPrime[i] == true){for(int j = 2*i; j <= N; j += i){isPrime[j] = false;}}} return isPrime;} +vector givemeprimes(int n) {int*arr = new int[n + 1](); vector vect; for(int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for(int j = i * i; j <= n; j += i)arr[j] = 1;} return vect;} +vector> givemedivisors(int n){int*arr = new int[n + 1]();vector > vect(n + 1);for(int i = 2; i <= n; ++i){if(arr[i] == 0){for(int j = i; j <= n; j += i){vect[j].pb(i);arr[i] = 1;}}} return vect ;} +vector givemesmallestprimefactors(int n){vector SPF(n + 1);for(int i = 0; i <= N; ++i){SPF[i] = i;}for(int i = 2; i <= N; ++i){if(SPF[i] == i){for(int j = i; j <= N; j += i){if(SPF[j] == j){SPF[j] = i;}}}}return SPF ;} // SPF is the smallest prime number that divides a given number without leaving a remainder +int sqrtprecision(int l,int r,int target){while(r-l>EPS){int mid=(l+(r-l)/2);if(mid*mid(l, r)(rng);} + +bool solve(){ + int n , k ; + cin >> n >> k ; + iv(v , n) + for(int i = 0 ; i < n ; ++i){ + v[i] = v[i] % k ; + } + vector > p ; + for(int i = 0 ; i < n ; ++i){ + if(v[i] == 0){ + cout << i + 1 << " " ; + continue ; + } + p.pb({v[i] , i + 1}) ; + } + sort(all(p) , comparatorfunction) ; + for(int i = 0 ; i < p.size() ; ++i){ + cout << p[i].S << " " ; + } + cout << nl ; + return true ; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t; + cin >> t; + //int count = 1; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++; + }else{ + // no + } + } + return 0; +} + + + + // Don't overthink and try to prove your idea. \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/152_Div_2/q3/.cph/.1.cpp_39e27a8bdfb3b0b3874604cbe69be6b5.prob b/CodeForces_Live_Contest/Educational_Round/152_Div_2/q3/.cph/.1.cpp_39e27a8bdfb3b0b3874604cbe69be6b5.prob new file mode 100644 index 0000000..acb0438 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/152_Div_2/q3/.cph/.1.cpp_39e27a8bdfb3b0b3874604cbe69be6b5.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\152_Div_2\\q3\\1.cpp","tests":[{"id":1690470964103,"input":"3\n6 5\n101100\n1 2\n1 3\n2 4\n5 5\n1 6\n6 4\n100111\n2 2\n1 4\n1 3\n1 2\n1 1\n0\n1 1\n","output":"3\n3\n1\n"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\152_Div_2\\q3\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/152_Div_2/q3/1.bin b/CodeForces_Live_Contest/Educational_Round/152_Div_2/q3/1.bin new file mode 100644 index 0000000..e64211a Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/152_Div_2/q3/1.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/152_Div_2/q3/1.cpp b/CodeForces_Live_Contest/Educational_Round/152_Div_2/q3/1.cpp new file mode 100644 index 0000000..09b6082 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/152_Div_2/q3/1.cpp @@ -0,0 +1,155 @@ +#include +using namespace std; + +// Policy based data structures(PBDS) C++ STL +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// order_of_key(k): returns count of elements strictly smaller than k +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // for pairs only define simply by ordered_set s +typedef tree, null_type, less_equal>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset; +templateusing Tree = tree, rb_tree_tag, tree_order_statistics_node_update> ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree> s; for pairs + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + +void _print(long long t) {cerr << t;} +void _print(string t) {cerr << t;} +void _print(char t) {cerr << t;} +void _print(long double t) {cerr << t;} + +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#define ll long long // typedef array ii; pair h ye +#define int ll +#define ld long double +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << endl; +#define no cout << "NO" << endl; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< &a, pair &b){if(a.S != b.S){return a.S < b.S ;}return a.F > b.F ;} +int power(int x, int y){int res = 1 ; while(y > 0) {if(y & 1) res = (res * x) ; x = (x * x) ; y = y >> 1 ;} return res ;} +int modpower(int x, int y){int res = 1; x = x % mod97; while(y > 0){if(y&1) res = (res * x) % mod97; y = y >> 1; x = (x * x) % mod97 ;}return res ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +vector giveme_it_isprime_or_not(int n){vector isPrime(n+1, 1);isPrime[0]=isPrime[1]=false;for(int i = 2; i <= N; ++i){if(isPrime[i] == true){for(int j = 2*i; j <= N; j += i){isPrime[j] = false;}}} return isPrime;} +vector givemeprimes(int n) {int*arr = new int[n + 1](); vector vect; for(int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for(int j = i * i; j <= n; j += i)arr[j] = 1;} return vect;} +vector> givemedivisors(int n){int*arr = new int[n + 1]();vector > vect(n + 1);for(int i = 2; i <= n; ++i){if(arr[i] == 0){for(int j = i; j <= n; j += i){vect[j].pb(i);arr[i] = 1;}}} return vect ;} +vector givemesmallestprimefactors(int n){vector SPF(n + 1);for(int i = 0; i <= N; ++i){SPF[i] = i;}for(int i = 2; i <= N; ++i){if(SPF[i] == i){for(int j = i; j <= N; j += i){if(SPF[j] == j){SPF[j] = i;}}}}return SPF ;} // SPF is the smallest prime number that divides a given number without leaving a remainder +int sqrtprecision(int l,int r,int target){while(r-l>EPS){int mid=(l+(r-l)/2);if(mid*mid(l, r)(rng);} + +bool solve(){ + int n , m ; + cin >> n >> m ; + string s ; + cin >> s ; + map , int > mp ; + vector > p ; + for(int i = 0 ; i < m ; ++i){ + int l , r ; + cin >> l >> r ; + if(mp[{l , r}] > 0){ + + }else{ + p.pb({l , r}) ; + } + mp[{l , r}] += 1 ; + + } + int done = 0 ; + vector pf(n + 1) ; + pf[0] = 0 ; + for(int i = 1 ; i <= n ; ++i){ + pf[i] = pf[i - 1] + (s[i - 1] == '1') ; + } + int ans = 0 ; + for(auto &i : p){ + int l = i.F ; + int r = i.S ; + l -= 1 ; + r -= 1 ; + int len = r - l + 1 ; + int zero = 0 ; + + zero = r + 1 - pf[r + 1] - (l - pf[l]) ; + cout << l << " " << r << " " << zero << " " ; + check1(pf) + if(pf[r + 1] == r + 1 || pf[l] == pf[l + zero - 1 + 1]) { + if(done){ + + }else{ + ans += 1 ; + done = 1 ; + } + }else{ + ans += 1 ; + } + cout << ans << nl ; + } + cout << ans << nl ; + return true ; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t; + cin >> t; + //int count = 1; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++; + }else{ + // no + } + } + return 0; +} + + + + // Don't overthink and try to prove your idea. \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/152_Div_2/q4/1.cpp b/CodeForces_Live_Contest/Educational_Round/152_Div_2/q4/1.cpp new file mode 100644 index 0000000..e69de29 diff --git a/CodeForces_Live_Contest/Educational_Round/153_Div_2/q1/.cph/.1.cpp_b6eba6fc0363ee1dd6ef2797473734bf.prob b/CodeForces_Live_Contest/Educational_Round/153_Div_2/q1/.cph/.1.cpp_b6eba6fc0363ee1dd6ef2797473734bf.prob new file mode 100644 index 0000000..e552534 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/153_Div_2/q1/.cph/.1.cpp_b6eba6fc0363ee1dd6ef2797473734bf.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\153_Div_2\\q1\\1.cpp","tests":[{"id":1692294081521,"input":"4\n)(\n(()\n()\n))()\n","output":"YES\n(())\nYES\n()()()\nNO\nYES\n()(()())\n"},{"id":1692294425790,"input":"2\n(())\n()()","output":""}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\153_Div_2\\q1\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/153_Div_2/q1/1.bin b/CodeForces_Live_Contest/Educational_Round/153_Div_2/q1/1.bin new file mode 100644 index 0000000..dc47173 Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/153_Div_2/q1/1.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/153_Div_2/q1/1.cpp b/CodeForces_Live_Contest/Educational_Round/153_Div_2/q1/1.cpp new file mode 100644 index 0000000..a9bd518 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/153_Div_2/q1/1.cpp @@ -0,0 +1,148 @@ +#include +using namespace std; + +// Policy based data structures(PBDS) C++ STL +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// order_of_key(k): returns count of elements strictly smaller than k +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // for pairs only define simply by ordered_set s +typedef tree, null_type, less_equal>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset; +templateusing Tree = tree, rb_tree_tag, tree_order_statistics_node_update> ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree> s; for pairs + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + +void _print(long long t) {cerr << t;} +void _print(string t) {cerr << t;} +void _print(char t) {cerr << t;} +void _print(long double t) {cerr << t;} + +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#define ll long long // typedef array ii; pair h ye +#define int ll +#define ld long double +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << endl; +#define no cout << "NO" << endl; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< &a, pair &b){if(a.S != b.S){return a.S < b.S ;}return a.F > b.F ;} +int power(int x, int y){int res = 1 ; while(y > 0) {if(y & 1) res = (res * x) ; x = (x * x) ; y = y >> 1 ;} return res ;} +int modpower(int x, int y){int res = 1; x = x % mod97; while(y > 0){if(y&1) res = (res * x) % mod97; y = y >> 1; x = (x * x) % mod97 ;}return res ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +vector giveme_it_isprime_or_not(int n){vector isPrime(n+1, 1);isPrime[0]=isPrime[1]=false;for(int i = 2; i <= N; ++i){if(isPrime[i] == true){for(int j = 2*i; j <= N; j += i){isPrime[j] = false;}}} return isPrime;} +vector givemeprimes(int n) {int*arr = new int[n + 1](); vector vect; for(int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for(int j = i * i; j <= n; j += i)arr[j] = 1;} return vect;} +vector> givemedivisors(int n){int*arr = new int[n + 1]();vector > vect(n + 1);for(int i = 2; i <= n; ++i){if(arr[i] == 0){for(int j = i; j <= n; j += i){vect[j].pb(i);arr[i] = 1;}}} return vect ;} +vector givemesmallestprimefactors(int n){vector SPF(n + 1);for(int i = 0; i <= N; ++i){SPF[i] = i;}for(int i = 2; i <= N; ++i){if(SPF[i] == i){for(int j = i; j <= N; j += i){if(SPF[j] == j){SPF[j] = i;}}}}return SPF ;} // SPF is the smallest prime number that divides a given number without leaving a remainder +int sqrtprecision(int l,int r,int target){while(r-l>EPS){int mid=(l+(r-l)/2);if(mid*mid(l, r)(rng);} + +bool solve(){ + string s ; + cin >> s ; + int n = s.size() ; + if(n == 2){ + if(s[0] == '(' && s[1] == ')'){ + no + return true ; + } + } + int f = 0 ; + int ff = 0 ; + for(int i = 0 ; i < n ; ++i){ + if(i % 2 == 0){ + if(s[i] != '(') f = 1 ; + }else{ + if(s[i] != ')') f = 1 ; + } + } + for(int i = 0 ; i < n ; ++i){ + if(i % 2 == 0){ + if(s[i] != ')') ff = 1 ; + }else{ + if(s[i] != '(') ff = 1 ; + } + } + if(f && ff){ + yes + for(int i = 0 ; i < n ; ++i){ + cout << "()" << "" ; + } + cout << nl ; + return true ; + } + yes + for(int i = 0 ; i < n ; ++i){ + cout << "(" << "" ; + } + for(int i = 0 ; i < n ; ++i){ + cout << ")" << "" ; + } + cout << nl ; + return true ; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t; + cin >> t; + //int count = 1; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++; + }else{ + // no + } + } + return 0; +} + + + + // Talk is Cheap. Show me the code \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/153_Div_2/q2/.cph/.1.cpp_2a432e9a95ae43559b8f66e5e8949a8b.prob b/CodeForces_Live_Contest/Educational_Round/153_Div_2/q2/.cph/.1.cpp_2a432e9a95ae43559b8f66e5e8949a8b.prob new file mode 100644 index 0000000..ccc6654 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/153_Div_2/q2/.cph/.1.cpp_2a432e9a95ae43559b8f66e5e8949a8b.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\153_Div_2\\q2\\1.cpp","tests":[{"id":1692295628215,"input":"4\n11 3 0 0\n11 3 20 20\n11 3 6 1\n100000000 2 0 0\n","output":"5\n0\n1\n50000000"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\153_Div_2\\q2\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/153_Div_2/q2/1.bin b/CodeForces_Live_Contest/Educational_Round/153_Div_2/q2/1.bin new file mode 100644 index 0000000..5993a14 Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/153_Div_2/q2/1.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/153_Div_2/q2/1.cpp b/CodeForces_Live_Contest/Educational_Round/153_Div_2/q2/1.cpp new file mode 100644 index 0000000..f242c66 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/153_Div_2/q2/1.cpp @@ -0,0 +1,115 @@ +#include +using namespace std; + +// Policy based data structures(PBDS) C++ STL +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// order_of_key(k): returns count of elements strictly smaller than k +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // for pairs only define simply by ordered_set s +typedef tree, null_type, less_equal>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset; +templateusing Tree = tree, rb_tree_tag, tree_order_statistics_node_update> ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree> s; for pairs + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + +void _print(long long t) {cerr << t;} +void _print(string t) {cerr << t;} +void _print(char t) {cerr << t;} +void _print(long double t) {cerr << t;} + +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#define ll long long // typedef array ii; pair h ye +#define int ll +#define ld long double +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << endl; +#define no cout << "NO" << endl; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< &a, pair &b){if(a.S != b.S){return a.S < b.S ;}return a.F > b.F ;} +int power(int x, int y){int res = 1 ; while(y > 0) {if(y & 1) res = (res * x) ; x = (x * x) ; y = y >> 1 ;} return res ;} +int modpower(int x, int y){int res = 1; x = x % mod97; while(y > 0){if(y&1) res = (res * x) % mod97; y = y >> 1; x = (x * x) % mod97 ;}return res ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +vector giveme_it_isprime_or_not(int n){vector isPrime(n+1, 1);isPrime[0]=isPrime[1]=false;for(int i = 2; i <= N; ++i){if(isPrime[i] == true){for(int j = 2*i; j <= N; j += i){isPrime[j] = false;}}} return isPrime;} +vector givemeprimes(int n) {int*arr = new int[n + 1](); vector vect; for(int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for(int j = i * i; j <= n; j += i)arr[j] = 1;} return vect;} +vector> givemedivisors(int n){int*arr = new int[n + 1]();vector > vect(n + 1);for(int i = 2; i <= n; ++i){if(arr[i] == 0){for(int j = i; j <= n; j += i){vect[j].pb(i);arr[i] = 1;}}} return vect ;} +vector givemesmallestprimefactors(int n){vector SPF(n + 1);for(int i = 0; i <= N; ++i){SPF[i] = i;}for(int i = 2; i <= N; ++i){if(SPF[i] == i){for(int j = i; j <= N; j += i){if(SPF[j] == j){SPF[j] = i;}}}}return SPF ;} // SPF is the smallest prime number that divides a given number without leaving a remainder +int sqrtprecision(int l,int r,int target){while(r-l>EPS){int mid=(l+(r-l)/2);if(mid*mid(l, r)(rng);} + +bool solve(){ + int m , k , a1 , ak ; + cin >> m >> k >> a1 >> ak ; + int remainder = m % k ; + if(remainder > a1){ + cout << max({0ll , (m / k) - ak}) + (m % k) - a1 << nl ; + }else{ + cout << max({0ll , (m / k) - ak - ((a1 - remainder) / k)}) << nl ; + } + return true ; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t; + cin >> t; + //int count = 1; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++; + }else{ + // no + } + } + return 0; +} + + + + // Talk is Cheap. Show me the code \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/153_Div_2/q3/1.cpp b/CodeForces_Live_Contest/Educational_Round/153_Div_2/q3/1.cpp new file mode 100644 index 0000000..e69de29 diff --git a/CodeForces_Live_Contest/Educational_Round/153_Div_2/q4/1.cpp b/CodeForces_Live_Contest/Educational_Round/153_Div_2/q4/1.cpp new file mode 100644 index 0000000..e69de29 diff --git a/CodeForces_Live_Contest/Educational_Round/157_Div_2/q1/.cph/.1.cpp_817e3476cff2caf8b17d48f5a58481df.prob b/CodeForces_Live_Contest/Educational_Round/157_Div_2/q1/.cph/.1.cpp_817e3476cff2caf8b17d48f5a58481df.prob new file mode 100644 index 0000000..76513aa --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/157_Div_2/q1/.cph/.1.cpp_817e3476cff2caf8b17d48f5a58481df.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\157_Div_2\\q1\\1.cpp","tests":[{"id":1699022346428,"input":"3\n5 7 2\n10 5 0\n5 8 2\n","output":""}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\157_Div_2\\q1\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/157_Div_2/q1/1.bin b/CodeForces_Live_Contest/Educational_Round/157_Div_2/q1/1.bin new file mode 100644 index 0000000..2381b5d Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/157_Div_2/q1/1.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/157_Div_2/q1/1.cpp b/CodeForces_Live_Contest/Educational_Round/157_Div_2/q1/1.cpp new file mode 100644 index 0000000..0a2c1d3 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/157_Div_2/q1/1.cpp @@ -0,0 +1,123 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +// Policy based data structures(PBDS) C++ STL +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// order_of_key(k): returns count of elements strictly smaller than k +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // for pairs only define simply by ordered_set s +typedef tree, null_type, less_equal>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset; +templateusing Tree = tree, rb_tree_tag, tree_order_statistics_node_update> ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree> s; for pairs + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + +void _print(long long t) {cerr << t;} +void _print(string t) {cerr << t;} +void _print(char t) {cerr << t;} +void _print(long double t) {cerr << t;} + +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#define ll long long // typedef array ii; pair h ye +#define int ll +#define ld long double +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << endl; +#define no cout << "NO" << endl; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< &a, pair &b){if(a.S != b.S){return a.S < b.S ;}return a.F > b.F ;} +long long power(long long x, long long y){long long res = 1 ; while(y > 0) {if(y & 1) res = (res * (long long)x) ; x = ((long long)x * (long long)x) ; y = y >> 1 ;} return res ;} +int modpower(int x, int y){long long res = 1; x = x % MOD; while(y > 0){if(y&1) res = (res * (long long)x) % MOD; y = y >> 1; x = ((long long)x * (long long)x) % MOD ;}return res ;} +int modinv(int x){return modpower(x , MOD - 2) ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +vector giveme_it_isprime_or_not(int n){vector isPrime(n+1, 1);isPrime[0]=isPrime[1]=false;for(int i = 2; i * i <= n; ++i){if(isPrime[i] == true){for(int j = 2 * i; j <= n; j += i){isPrime[j] = false;}}} return isPrime;} // Time Complexity - O(n * sqrt(n) * log(n)) +vector givemeprimes(int n) {int*arr = new int[n + 1](); vector vect; for(int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for(int j = i * i; j <= n; j += i)arr[j] = 1;} return vect;} // can be calculated in O(n) +vector> givemedivisors(int n){int*arr = new int[n + 1]();vector > vect(n + 1);for(int i = 2; i <= n; ++i){if(arr[i] == 0){for(int j = i; j <= n; j += i){vect[j].pb(i);arr[i] = 1;}}} return vect ;} +vector givemesmallestprimefactors(int n){vector SPF(n + 1);for(int i = 0; i <= n; ++i){SPF[i] = i;}for(int i = 2; i <= n; ++i){if(SPF[i] == i){for(int j = i; j <= n; j += i){if(SPF[j] == j){SPF[j] = i;}}}}return SPF ;} // SPF is the smallest prime number that divides a given number without leaving a remainder +int sqrtprecision(int l,int r,int target){while(r-l>EPS){int mid=(l+(r-l)/2);if(mid*mid(l, r)(rng);} + +bool solve(){ + int x , y , k ; + cin >> x >> y >> k ; + if(x >= y){ + cout << x << nl ; + } + else{ + int t = y - x ; + if(k >= t){ + cout << y << nl ; + } + else{ + cout << x + k + (y - x - k) * 2 << nl ; + } + } + return true ; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t ; + cin >> t ; + //int count = 1 ; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++ ; + }else{ + // no + } + } + return 0 ; +} + + + + // Talk is Cheap. Show me the code \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/157_Div_2/q2/.cph/.1.cpp_8875429db48090d9696955c4447dcd2b.prob b/CodeForces_Live_Contest/Educational_Round/157_Div_2/q2/.cph/.1.cpp_8875429db48090d9696955c4447dcd2b.prob new file mode 100644 index 0000000..0af18ed --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/157_Div_2/q2/.cph/.1.cpp_8875429db48090d9696955c4447dcd2b.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\157_Div_2\\q2\\1.cpp","tests":[{"id":1699022639087,"input":"2\n2\n15 1 10 5\n3\n10 30 20 20 30 10\n","output":""}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\157_Div_2\\q2\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/157_Div_2/q2/1.bin b/CodeForces_Live_Contest/Educational_Round/157_Div_2/q2/1.bin new file mode 100644 index 0000000..77e7e58 Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/157_Div_2/q2/1.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/157_Div_2/q2/1.cpp b/CodeForces_Live_Contest/Educational_Round/157_Div_2/q2/1.cpp new file mode 100644 index 0000000..e23e879 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/157_Div_2/q2/1.cpp @@ -0,0 +1,129 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +// Policy based data structures(PBDS) C++ STL +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// order_of_key(k): returns count of elements strictly smaller than k +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // for pairs only define simply by ordered_set s +typedef tree, null_type, less_equal>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset; +templateusing Tree = tree, rb_tree_tag, tree_order_statistics_node_update> ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree> s; for pairs + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + +void _print(long long t) {cerr << t;} +void _print(string t) {cerr << t;} +void _print(char t) {cerr << t;} +void _print(long double t) {cerr << t;} + +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#define ll long long // typedef array ii; pair h ye +#define int ll +#define ld long double +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << endl; +#define no cout << "NO" << endl; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< &a, pair &b){if(a.S != b.S){return a.S < b.S ;}return a.F > b.F ;} +long long power(long long x, long long y){long long res = 1 ; while(y > 0) {if(y & 1) res = (res * (long long)x) ; x = ((long long)x * (long long)x) ; y = y >> 1 ;} return res ;} +int modpower(int x, int y){long long res = 1; x = x % MOD; while(y > 0){if(y&1) res = (res * (long long)x) % MOD; y = y >> 1; x = ((long long)x * (long long)x) % MOD ;}return res ;} +int modinv(int x){return modpower(x , MOD - 2) ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +vector giveme_it_isprime_or_not(int n){vector isPrime(n+1, 1);isPrime[0]=isPrime[1]=false;for(int i = 2; i * i <= n; ++i){if(isPrime[i] == true){for(int j = 2 * i; j <= n; j += i){isPrime[j] = false;}}} return isPrime;} // Time Complexity - O(n * sqrt(n) * log(n)) +vector givemeprimes(int n) {int*arr = new int[n + 1](); vector vect; for(int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for(int j = i * i; j <= n; j += i)arr[j] = 1;} return vect;} // can be calculated in O(n) +vector> givemedivisors(int n){int*arr = new int[n + 1]();vector > vect(n + 1);for(int i = 2; i <= n; ++i){if(arr[i] == 0){for(int j = i; j <= n; j += i){vect[j].pb(i);arr[i] = 1;}}} return vect ;} +vector givemesmallestprimefactors(int n){vector SPF(n + 1);for(int i = 0; i <= n; ++i){SPF[i] = i;}for(int i = 2; i <= n; ++i){if(SPF[i] == i){for(int j = i; j <= n; j += i){if(SPF[j] == j){SPF[j] = i;}}}}return SPF ;} // SPF is the smallest prime number that divides a given number without leaving a remainder +int sqrtprecision(int l,int r,int target){while(r-l>EPS){int mid=(l+(r-l)/2);if(mid*mid(l, r)(rng);} + +bool solve(){ + int n ; + cin >> n ; + iv(v , 2 * n) + n = n * 2 ; + sort(all(v)) ; + int ans = 0 ; + for(int i = 1 ; i < n / 2 ; ++i){ + ans += v[i] - v[i - 1] ; + } + for(int i = n / 2 + 1 ; i < n ; ++i){ + ans += v[i] - v[i - 1] ; + } + cout << ans << nl ; + vector>ans1 ; + for(int i = 0 ; i < n / 2 ; ++i){ + ans1.pb({v[i] , v[n / 2 + i]}) ; + } + for(auto &i : ans1){ + cout << i.F << " " << i.S << nl ; + } + return true ; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t ; + cin >> t ; + //int count = 1 ; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++ ; + }else{ + // no + } + } + return 0 ; +} + + + + // Talk is Cheap. Show me the code \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/157_Div_2/q3/.cph/.1.cpp_c8755931c549c1f8ec2ca9006530f704.prob b/CodeForces_Live_Contest/Educational_Round/157_Div_2/q3/.cph/.1.cpp_c8755931c549c1f8ec2ca9006530f704.prob new file mode 100644 index 0000000..7e88462 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/157_Div_2/q3/.cph/.1.cpp_c8755931c549c1f8ec2ca9006530f704.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\157_Div_2\\q3\\1.cpp","tests":[{"id":1699024231388,"input":"10\n5 93746 59 3746 593 746 5937 46 59374 6\n","output":"20"},{"id":1699024747298,"input":"5\n2 22 222 2222 22222\n","output":"13"},{"id":1699024753377,"input":"3\n1 1 1","output":"9"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\157_Div_2\\q3\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/157_Div_2/q3/1.bin b/CodeForces_Live_Contest/Educational_Round/157_Div_2/q3/1.bin new file mode 100644 index 0000000..7e5e467 Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/157_Div_2/q3/1.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/157_Div_2/q3/1.cpp b/CodeForces_Live_Contest/Educational_Round/157_Div_2/q3/1.cpp new file mode 100644 index 0000000..6e04a0a --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/157_Div_2/q3/1.cpp @@ -0,0 +1,211 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +#include +#include +using namespace __gnu_pbds; +typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // for pairs only define simply by ordered_set s +typedef tree, null_type, less_equal>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset; +templateusing Tree = tree, rb_tree_tag, tree_order_statistics_node_update> ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree> s; for pairs + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + +void _print(long long t) {cerr << t;} +void _print(string t) {cerr << t;} +void _print(char t) {cerr << t;} +void _print(long double t) {cerr << t;} + +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#define ll long long +#define int ll +#define ld long double +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << endl; +#define no cout << "NO" << endl; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< &a, pair &b){if(a.S != b.S){return a.S < b.S ;}return a.F > b.F ;} +long long power(long long x, long long y){long long res = 1 ; while(y > 0) {if(y & 1) res = (res * (long long)x) ; x = ((long long)x * (long long)x) ; y = y >> 1 ;} return res ;} +int modpower(int x, int y){long long res = 1; x = x % MOD; while(y > 0){if(y&1) res = (res * (long long)x) % MOD; y = y >> 1; x = ((long long)x * (long long)x) % MOD ;}return res ;} +int modinv(int x){return modpower(x , MOD - 2) ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +vector giveme_it_isprime_or_not(int n){vector isPrime(n+1, 1);isPrime[0]=isPrime[1]=false;for(int i = 2; i * i <= n; ++i){if(isPrime[i] == true){for(int j = 2 * i; j <= n; j += i){isPrime[j] = false;}}} return isPrime;} // Time Complexity - O(n * sqrt(n) * log(n)) +vector givemeprimes(int n) {int*arr = new int[n + 1](); vector vect; for(int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for(int j = i * i; j <= n; j += i)arr[j] = 1;} return vect;} // can be calculated in O(n) +vector> givemedivisors(int n){int*arr = new int[n + 1]();vector > vect(n + 1);for(int i = 2; i <= n; ++i){if(arr[i] == 0){for(int j = i; j <= n; j += i){vect[j].pb(i);arr[i] = 1;}}} return vect ;} +vector givemesmallestprimefactors(int n){vector SPF(n + 1);for(int i = 0; i <= n; ++i){SPF[i] = i;}for(int i = 2; i <= n; ++i){if(SPF[i] == i){for(int j = i; j <= n; j += i){if(SPF[j] == j){SPF[j] = i;}}}}return SPF ;} // SPF is the smallest prime number that divides a given number without leaving a remainder +int sqrtprecision(int l,int r,int target){while(r-l>EPS){int mid=(l+(r-l)/2);if(mid*mid(l, r)(rng);} + +bool solve(){ + int n ; + cin >> n ; + string s[n] ; + for(int i = 0 ; i < n ; ++i){ + cin >> s[i] ; + } + vector v ; + for(int i = 0 ; i < n ; ++i){ + v.pb(stoi(s[i])) ; + } + // check1(v) + vector vv = v ; + int ans = 0 ; + { + map , int > mp ; + for(int i = 0 ; i < n ; ++i){ + int total_sum = 0 ; + int len = 0 ; + int num = v[i] ; + while(num){ + total_sum += (num % 10) ; + num /= 10 ; + len++ ; + } + int back_len = 0 ; + int back_sum = 0 ; + num = v[i] ; + while(num){ + back_sum += (num % 10) ; + num /= 10 ; + back_len++ ; + int want_length = back_len - (len - back_len) ; + int want_sum = back_sum - (total_sum - back_sum) ; + ans += mp[{want_length , want_sum}] ; + } + mp[{len , total_sum}] += 1 ; + } + } + { + map , int > mp ; + for(int i = 0 ; i < n ; ++i){ + string ss = to_string(v[i]) ; + reverse(all(ss)) ; + v[i] = stoi(ss) ; + int total_sum = 0 ; + int len = 0 ; + int num = v[i] ; + while(num){ + total_sum += (num % 10) ; + num /= 10 ; + len++ ; + } + int back_len = 0 ; + int back_sum = 0 ; + num = v[i] ; + while(num){ + back_sum += (num % 10) ; + num /= 10 ; + back_len++ ; + int want_length = back_len - (len - back_len) ; + int want_sum = back_sum - (total_sum - back_sum) ; + ans += mp[{want_length , want_sum}] ; + } + mp[{len , total_sum}]+= 1 ; + ss = to_string(v[i]) ; + reverse(all(ss)) ; + v[i] = stoi(ss) ; + } + } + reverse(all(v)) ; + for(auto &i : v){ + string ss = to_string(i) ; + reverse(all(ss)) ; + i = stoi(ss) ; + } + // for(auto &i : mp2){ + // cout << i.F.F << " " << i.F.S << nl ; + // } + // cout << mp.size() * 2 + n << nl ; + { + map , int > mp ; + for(int i = 0 ; i < n ; ++i){ + int total_sum = 0 ; + int len = 0 ; + int num = v[i] ; + while(num){ + total_sum += (num % 10) ; + num /= 10 ; + len++ ; + } + int back_len = 0 ; + int back_sum = 0 ; + num = v[i] ; + while(num){ + back_sum += (num % 10) ; + num /= 10 ; + back_len++ ; + int want_length = back_len - (len - back_len) ; + int want_sum = back_sum - (total_sum - back_sum) ; + ans += mp[{want_length , want_sum}] ; + } + mp[{len , total_sum}] += 1 ; + } + } + cout << ans + n << nl ; + return true ; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t = 1 ; + //cin >> t ; + //int count = 1 ; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++; + }else{ + // no + } + } + return 0 ; +} + + + + + // Talk is Cheap. Show me the code diff --git a/CodeForces_Live_Contest/Educational_Round/157_Div_2/q4/.cph/.1.cpp_6464208d34bb1dd0168a0ae3ae887294.prob b/CodeForces_Live_Contest/Educational_Round/157_Div_2/q4/.cph/.1.cpp_6464208d34bb1dd0168a0ae3ae887294.prob new file mode 100644 index 0000000..7d911b7 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/157_Div_2/q4/.cph/.1.cpp_6464208d34bb1dd0168a0ae3ae887294.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\157_Div_2\\q4\\1.cpp","tests":[{"id":1699100554255,"input":"4\n2 1 2\n","output":"0 2 3 1 "},{"id":1699100560694,"input":"6\n1 6 1 4 1","output":"2 3 5 4 0 1"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\157_Div_2\\q4\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/157_Div_2/q4/1.bin b/CodeForces_Live_Contest/Educational_Round/157_Div_2/q4/1.bin new file mode 100644 index 0000000..e1b6db0 Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/157_Div_2/q4/1.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/157_Div_2/q4/1.cpp b/CodeForces_Live_Contest/Educational_Round/157_Div_2/q4/1.cpp new file mode 100644 index 0000000..5a2ec95 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/157_Div_2/q4/1.cpp @@ -0,0 +1,219 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +#include +#include +using namespace __gnu_pbds; +typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // for pairs only define simply by ordered_set s +typedef tree, null_type, less_equal>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset; +templateusing Tree = tree, rb_tree_tag, tree_order_statistics_node_update> ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree> s; for pairs + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + +void _print(long long t) {cerr << t;} +void _print(string t) {cerr << t;} +void _print(char t) {cerr << t;} +void _print(long double t) {cerr << t;} + +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#define ll long long +#define int ll +#define ld long double +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << endl; +#define no cout << "NO" << endl; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< &a, pair &b){if(a.S != b.S){return a.S < b.S ;}return a.F > b.F ;} +long long power(long long x, long long y){long long res = 1 ; while(y > 0) {if(y & 1) res = (res * (long long)x) ; x = ((long long)x * (long long)x) ; y = y >> 1 ;} return res ;} +int modpower(int x, int y){long long res = 1; x = x % MOD; while(y > 0){if(y&1) res = (res * (long long)x) % MOD; y = y >> 1; x = ((long long)x * (long long)x) % MOD ;}return res ;} +int modinv(int x){return modpower(x , MOD - 2) ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +vector giveme_it_isprime_or_not(int n){vector isPrime(n+1, 1);isPrime[0]=isPrime[1]=false;for(int i = 2; i * i <= n; ++i){if(isPrime[i] == true){for(int j = 2 * i; j <= n; j += i){isPrime[j] = false;}}} return isPrime;} // Time Complexity - O(n * sqrt(n) * log(n)) +vector givemeprimes(int n) {int*arr = new int[n + 1](); vector vect; for(int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for(int j = i * i; j <= n; j += i)arr[j] = 1;} return vect;} // can be calculated in O(n) +vector> givemedivisors(int n){int*arr = new int[n + 1]();vector > vect(n + 1);for(int i = 2; i <= n; ++i){if(arr[i] == 0){for(int j = i; j <= n; j += i){vect[j].pb(i);arr[i] = 1;}}} return vect ;} +vector givemesmallestprimefactors(int n){vector SPF(n + 1);for(int i = 0; i <= n; ++i){SPF[i] = i;}for(int i = 2; i <= n; ++i){if(SPF[i] == i){for(int j = i; j <= n; j += i){if(SPF[j] == j){SPF[j] = i;}}}}return SPF ;} // SPF is the smallest prime number that divides a given number without leaving a remainder +int sqrtprecision(int l,int r,int target){while(r-l>EPS){int mid=(l+(r-l)/2);if(mid*mid(l, r)(rng);} + +class Trie { +public: + struct BITS_TRIE { + private: + struct node { + int start = 0 ; + int end = 0 ; + bool flag = false ; + int cnt = 0 ; + node* next[2] ; + node() { + next[1] = next[0] = NULL ; + } + }; + node root ; + + public: + void insert(int val) { + node* temp = &root; + temp->cnt++ ; + for(int i = 31 ; i >= 0 ; --i) { + int bit = 1 ; + if((val & (1 << i)) == 0) { + bit = 0 ; + } + + if(temp->next[bit] == NULL) { + temp->next[bit] = new node() ; + } + + temp = temp->next[bit] ; + temp->cnt++ ; + } + } + + int max_xor(int val) { + int ans = 0 ; + node* temp = &root ; + for(int i = 31 ; i >= 0 ; --i) { + int bit = 1 ; + if((val & (1 << i)) == 0) { + bit = 0 ; + } + + int req = 1 - bit ; + + if(temp->next[req] == NULL) { + temp = temp->next[1 - req] ; + } + else if(temp->next[req]->cnt == 0) { + temp = temp->next[1 - req] ; + } + else { + ans += (1 << i) ; + temp = temp->next[req] ; + } + } + + return ans ; + } + + int min_xor(int val){ + int ans = 0 ; + node* temp = &root ; + for(int i = 31 ; i >= 0 ; --i){ + int bit = 1 ; + if((val & (1 << i)) == 0){ + bit = 0 ; + } + + int req = bit ; + + if(temp->next[req] == NULL){ + ans += (1 << i) ; + temp = temp->next[1 - req] ; + } + else if(temp->next[req]->cnt == 0){ + ans += (1 << i) ; + temp=temp->next[1 - req] ; + } + else{ + temp = temp->next[req] ; + } + } + + return ans ; + } + }; +}; + +bool solve(){ + int n ; + cin >> n ; + iv(v , n - 1) + vector b(n , 0) ; + for(int i = 0 ; i < n - 1 ; ++i){ + b[i + 1] = b[i] ^ v[i] ; + } + Trie::BITS_TRIE t ; + for(int i = 0 ; i < n ; ++i){ + t.insert(b[i]) ; + } + int x = 0 ; + for(int i = 0 ; ; ++i){ + int maxi = t.max_xor(i) ; + if(maxi == n - 1){ + x = i ; + break ; + } + } + for(int i = 0 ; i < n ; ++i){ + cout << (b[i] ^ x) << " " ; + } + cout << nl ; + return true ; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t = 1 ; + //cin >> t ; + //int count = 1 ; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++; + }else{ + // no + } + } + return 0 ; +} + + + + + // Talk is Cheap. Show me the code diff --git a/CodeForces_Live_Contest/Educational_Round/158_Div_2/q1/.cph/.1.cpp_e159f4abd9f443157b74968aa95adaa5.prob b/CodeForces_Live_Contest/Educational_Round/158_Div_2/q1/.cph/.1.cpp_e159f4abd9f443157b74968aa95adaa5.prob new file mode 100644 index 0000000..6f087c6 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/158_Div_2/q1/.cph/.1.cpp_e159f4abd9f443157b74968aa95adaa5.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\158_Div_2\\q1\\1.cpp","tests":[{"id":1700836707234,"input":"3\n3 7\n1 2 5\n3 6\n1 2 5\n1 10\n7\n","output":"4\n3\n7\n"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\158_Div_2\\q1\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/158_Div_2/q1/1.bin b/CodeForces_Live_Contest/Educational_Round/158_Div_2/q1/1.bin new file mode 100644 index 0000000..a27a0b6 Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/158_Div_2/q1/1.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/158_Div_2/q1/1.cpp b/CodeForces_Live_Contest/Educational_Round/158_Div_2/q1/1.cpp new file mode 100644 index 0000000..1141161 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/158_Div_2/q1/1.cpp @@ -0,0 +1,118 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +// Policy based data structures(PBDS) C++ STL +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// order_of_key(k): returns count of elements strictly smaller than k +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // for pairs only define simply by ordered_set s +typedef tree, null_type, less_equal>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset; +templateusing Tree = tree, rb_tree_tag, tree_order_statistics_node_update> ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree > s; for pairs + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + +void _print(long long t) {cerr << t;} +void _print(string t) {cerr << t;} +void _print(char t) {cerr << t;} +void _print(long double t) {cerr << t;} + +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#define ll long long // typedef array p ; pair h ye +#define int ll +#define ld long double +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << endl; +#define no cout << "NO" << endl; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< &a, pair &b){if(a.S != b.S){return a.S < b.S ;}return a.F > b.F ;} +long long power(long long x, long long y){long long res = 1 ; while(y > 0) {if(y & 1) res = (res * (long long)x) ; x = ((long long)x * (long long)x) ; y = y >> 1 ;} return res ;} +int modpower(int x, int y){long long res = 1; x = x % MOD; while(y > 0){if(y&1) res = (res * (long long)x) % MOD; y = y >> 1; x = ((long long)x * (long long)x) % MOD ;}return res ;} +int modinv(int x){return modpower(x , MOD - 2) ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +vector giveme_it_isprime_or_not(int n){vector isPrime(n+1, 1);isPrime[0]=isPrime[1]=false;for(int i = 2; i * i <= n; ++i){if(isPrime[i] == true){for(int j = 2 * i; j <= n; j += i){isPrime[j] = false;}}} return isPrime;} // Time Complexity - O(n * sqrt(n) * log(n)) +vector givemeprimes(int n) {int*arr = new int[n + 1](); vector vect; for(int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for(int j = i * i; j <= n; j += i)arr[j] = 1;} return vect;} // can be calculated in O(n) +vector> givemedivisors(int n){int*arr = new int[n + 1]();vector > vect(n + 1);for(int i = 2; i <= n; ++i){if(arr[i] == 0){for(int j = i; j <= n; j += i){vect[j].pb(i);arr[i] = 1;}}} return vect ;} +vector givemesmallestprimefactors(int n){vector SPF(n + 1);for(int i = 0; i <= n; ++i){SPF[i] = i;}for(int i = 2; i <= n; ++i){if(SPF[i] == i){for(int j = i; j <= n; j += i){if(SPF[j] == j){SPF[j] = i;}}}}return SPF ;} // SPF is the smallest prime number that divides a given number without leaving a remainder +int sqrtprecision(int l,int r,int target){while(r-l>EPS){int mid=(l+(r-l)/2);if(mid*mid(l, r)(rng);} + +bool solve(){ + int n , x ; + cin >> n >> x ; + iv(v , n) + int ans = v[0] ; + for(int i = 0 ; i < n - 1 ; ++i){ + ans = max(ans , v[i + 1] - v[i]) ; + } + ans = max(ans , (x - v[n - 1]) * 2) ; + cout << ans << nl ; + return true ; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t ; + cin >> t ; + //int count = 1 ; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++ ; + }else{ + // no + } + } + return 0 ; +} + + + + // Talk is Cheap. Show me the code \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/158_Div_2/q2/.cph/.1.cpp_5e1eb0985e2389b427f103a7059aa57d.prob b/CodeForces_Live_Contest/Educational_Round/158_Div_2/q2/.cph/.1.cpp_5e1eb0985e2389b427f103a7059aa57d.prob new file mode 100644 index 0000000..8f23bf2 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/158_Div_2/q2/.cph/.1.cpp_5e1eb0985e2389b427f103a7059aa57d.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\158_Div_2\\q2\\1.cpp","tests":[{"id":1700837164176,"input":"4\n4\n1 2 2 1\n5\n1 0 1 0 1\n5\n5 4 3 2 1\n1\n12\n","output":"1\n2\n4\n11\n"},{"id":1700837659715,"input":"2\n4\n1 1 1 1\n4\n1 2 3 4","output":"0\n3"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\158_Div_2\\q2\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/158_Div_2/q2/1.bin b/CodeForces_Live_Contest/Educational_Round/158_Div_2/q2/1.bin new file mode 100644 index 0000000..9193063 Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/158_Div_2/q2/1.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/158_Div_2/q2/1.cpp b/CodeForces_Live_Contest/Educational_Round/158_Div_2/q2/1.cpp new file mode 100644 index 0000000..94a6a62 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/158_Div_2/q2/1.cpp @@ -0,0 +1,132 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +// Policy based data structures(PBDS) C++ STL +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// order_of_key(k): returns count of elements strictly smaller than k +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // for pairs only define simply by ordered_set s +typedef tree, null_type, less_equal>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset; +templateusing Tree = tree, rb_tree_tag, tree_order_statistics_node_update> ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree > s; for pairs + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + +void _print(long long t) {cerr << t;} +void _print(string t) {cerr << t;} +void _print(char t) {cerr << t;} +void _print(long double t) {cerr << t;} + +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#define ll long long // typedef array p ; pair h ye +#define int ll +#define ld long double +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << endl; +#define no cout << "NO" << endl; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< &a, pair &b){if(a.S != b.S){return a.S < b.S ;}return a.F > b.F ;} +long long power(long long x, long long y){long long res = 1 ; while(y > 0) {if(y & 1) res = (res * (long long)x) ; x = ((long long)x * (long long)x) ; y = y >> 1 ;} return res ;} +int modpower(int x, int y){long long res = 1; x = x % MOD; while(y > 0){if(y&1) res = (res * (long long)x) % MOD; y = y >> 1; x = ((long long)x * (long long)x) % MOD ;}return res ;} +int modinv(int x){return modpower(x , MOD - 2) ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +vector giveme_it_isprime_or_not(int n){vector isPrime(n+1, 1);isPrime[0]=isPrime[1]=false;for(int i = 2; i * i <= n; ++i){if(isPrime[i] == true){for(int j = 2 * i; j <= n; j += i){isPrime[j] = false;}}} return isPrime;} // Time Complexity - O(n * sqrt(n) * log(n)) +vector givemeprimes(int n) {int*arr = new int[n + 1](); vector vect; for(int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for(int j = i * i; j <= n; j += i)arr[j] = 1;} return vect;} // can be calculated in O(n) +vector> givemedivisors(int n){int*arr = new int[n + 1]();vector > vect(n + 1);for(int i = 2; i <= n; ++i){if(arr[i] == 0){for(int j = i; j <= n; j += i){vect[j].pb(i);arr[i] = 1;}}} return vect ;} +vector givemesmallestprimefactors(int n){vector SPF(n + 1);for(int i = 0; i <= n; ++i){SPF[i] = i;}for(int i = 2; i <= n; ++i){if(SPF[i] == i){for(int j = i; j <= n; j += i){if(SPF[j] == j){SPF[j] = i;}}}}return SPF ;} // SPF is the smallest prime number that divides a given number without leaving a remainder +int sqrtprecision(int l,int r,int target){while(r-l>EPS){int mid=(l+(r-l)/2);if(mid*mid(l, r)(rng);} + +bool solve(){ + int n ; + cin >> n ; + iv(v , n) + if(n == 1){ + cout << v[0] - 1 << nl ; + return true ; + } + stack s ; + int ans = 0 ; + for(int i = 0 ; i < n ; ++i){ + while(!s.empty() and s.top() >= v[i]){ + ans += s.top() - v[i] ; + s.pop() ; + } + while(!s.empty() and s.top() < v[i]){ + s.pop() ; + } + s.push(v[i]) ; + } + if(s.size() == 1){ + ans += s.top() - 1 ; + } + cout << ans << nl ; + return true ; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t ; + cin >> t ; + //int count = 1 ; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++ ; + }else{ + // no + } + } + return 0 ; +} + + + + // Talk is Cheap. Show me the code \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/158_Div_2/q3/.cph/.1.cpp_610592f4c005535a6a0c5864f2cd438e.prob b/CodeForces_Live_Contest/Educational_Round/158_Div_2/q3/.cph/.1.cpp_610592f4c005535a6a0c5864f2cd438e.prob new file mode 100644 index 0000000..f04af02 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/158_Div_2/q3/.cph/.1.cpp_610592f4c005535a6a0c5864f2cd438e.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\158_Div_2\\q3\\1.cpp","tests":[{"id":1700842914600,"input":"4\n1\n10\n2\n4 6\n6\n2 1 2 1 2 1\n2\n0 32\n","output":"0\n2\n2 5\n1\n1\n6\n"},{"id":1700843247997,"input":"1\n4\n0 0 0 0","output":""}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\158_Div_2\\q3\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/158_Div_2/q3/1.bin b/CodeForces_Live_Contest/Educational_Round/158_Div_2/q3/1.bin new file mode 100644 index 0000000..087261e Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/158_Div_2/q3/1.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/158_Div_2/q3/1.cpp b/CodeForces_Live_Contest/Educational_Round/158_Div_2/q3/1.cpp new file mode 100644 index 0000000..8cf6913 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/158_Div_2/q3/1.cpp @@ -0,0 +1,145 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +// Policy based data structures(PBDS) C++ STL +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// order_of_key(k): returns count of elements strictly smaller than k +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // for pairs only define simply by ordered_set s +typedef tree, null_type, less_equal>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset; +templateusing Tree = tree, rb_tree_tag, tree_order_statistics_node_update> ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree > s; for pairs + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + +void _print(long long t) {cerr << t;} +void _print(string t) {cerr << t;} +void _print(char t) {cerr << t;} +void _print(long double t) {cerr << t;} + +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#define ll long long // typedef array p ; pair h ye +#define int ll +#define ld long double +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << endl; +#define no cout << "NO" << endl; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< &a, pair &b){if(a.S != b.S){return a.S < b.S ;}return a.F > b.F ;} +long long power(long long x, long long y){long long res = 1 ; while(y > 0) {if(y & 1) res = (res * (long long)x) ; x = ((long long)x * (long long)x) ; y = y >> 1 ;} return res ;} +int modpower(int x, int y){long long res = 1; x = x % MOD; while(y > 0){if(y&1) res = (res * (long long)x) % MOD; y = y >> 1; x = ((long long)x * (long long)x) % MOD ;}return res ;} +int modinv(int x){return modpower(x , MOD - 2) ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +vector giveme_it_isprime_or_not(int n){vector isPrime(n+1, 1);isPrime[0]=isPrime[1]=false;for(int i = 2; i * i <= n; ++i){if(isPrime[i] == true){for(int j = 2 * i; j <= n; j += i){isPrime[j] = false;}}} return isPrime;} // Time Complexity - O(n * sqrt(n) * log(n)) +vector givemeprimes(int n) {int*arr = new int[n + 1](); vector vect; for(int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for(int j = i * i; j <= n; j += i)arr[j] = 1;} return vect;} // can be calculated in O(n) +vector> givemedivisors(int n){int*arr = new int[n + 1]();vector > vect(n + 1);for(int i = 2; i <= n; ++i){if(arr[i] == 0){for(int j = i; j <= n; j += i){vect[j].pb(i);arr[i] = 1;}}} return vect ;} +vector givemesmallestprimefactors(int n){vector SPF(n + 1);for(int i = 0; i <= n; ++i){SPF[i] = i;}for(int i = 2; i <= n; ++i){if(SPF[i] == i){for(int j = i; j <= n; j += i){if(SPF[j] == j){SPF[j] = i;}}}}return SPF ;} // SPF is the smallest prime number that divides a given number without leaving a remainder +int sqrtprecision(int l,int r,int target){while(r-l>EPS){int mid=(l+(r-l)/2);if(mid*mid(l, r)(rng);} + +bool solve(){ + int n ; + cin >> n ; + iv(v , n) + sort(all(v)) ; + int mx = v[n - 1] ; + int mn = v[0] ; + int cnt = 0 ; + int dif = mx - mn ; + while(dif > 0){ + dif /= 2 ; + cnt++ ; + } + // cout << cnt << nl ; + if(cnt == 0){ + cout << 0 << nl ; + } + else if(cnt > n){ + cout << cnt << nl ; + } + else{ + cout << cnt << nl ; + for(int i = 0 ; i < cnt ; ++i){ + if(mn % 2 == 1){ + mn += 1 ; + } + if(mx % 2 != mn % 2){ + cout << 0 << " " ; + } + else{ + cout << 1 << " " ; + } + mx /= 2 ; + mn /= 2 ; + } + cout << nl ; + } + return true ; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t ; + cin >> t ; + //int count = 1 ; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++ ; + }else{ + // no + } + } + return 0 ; +} + + + + // Talk is Cheap. Show me the code \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/158_Div_2/q4/1.cpp b/CodeForces_Live_Contest/Educational_Round/158_Div_2/q4/1.cpp new file mode 100644 index 0000000..e69de29 diff --git a/CodeForces_Live_Contest/Educational_Round/160_Div_2/.cph/.1.cpp_10ade0298bfe64cc2a6b732cc9aa8911.prob b/CodeForces_Live_Contest/Educational_Round/160_Div_2/.cph/.1.cpp_10ade0298bfe64cc2a6b732cc9aa8911.prob new file mode 100644 index 0000000..77eab4e --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/160_Div_2/.cph/.1.cpp_10ade0298bfe64cc2a6b732cc9aa8911.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\160_Div_2\\1.cpp","tests":[{"id":1702913575248,"input":"5\n20002001\n391125\n200200\n2001000\n12\n","output":"2000 2001\n39 1125\n-1\n200 1000\n1 2\n"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\160_Div_2\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/160_Div_2/.cph/.2.cpp_d6096c1f22b18f410e3ca11dd96328df.prob b/CodeForces_Live_Contest/Educational_Round/160_Div_2/.cph/.2.cpp_d6096c1f22b18f410e3ca11dd96328df.prob new file mode 100644 index 0000000..cea3972 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/160_Div_2/.cph/.2.cpp_d6096c1f22b18f410e3ca11dd96328df.prob @@ -0,0 +1 @@ +{"name":"Local: 2","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\160_Div_2\\2.cpp","tests":[{"id":1702914413982,"input":"4\n0\n011\n0101110001\n111100","output":"1\n1\n0\n4"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\160_Div_2\\2.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/160_Div_2/.cph/.3.cpp_b1683a5bd9a8034f86eaefeb29384916.prob b/CodeForces_Live_Contest/Educational_Round/160_Div_2/.cph/.3.cpp_b1683a5bd9a8034f86eaefeb29384916.prob new file mode 100644 index 0000000..9ea27d0 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/160_Div_2/.cph/.3.cpp_b1683a5bd9a8034f86eaefeb29384916.prob @@ -0,0 +1 @@ +{"name":"Local: 3","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\160_Div_2\\3.cpp","tests":[{"id":1702915317778,"input":"5\n1 0\n1 0\n1 0\n2 3\n2 4\n","output":"YES\nNO\n"},{"id":1702915326705,"input":"7\n1 0\n1 1\n1 2\n1 10\n2 4\n2 6\n2 7\n","output":"YES\nYES\nYES\n"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\160_Div_2\\3.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/160_Div_2/1.bin b/CodeForces_Live_Contest/Educational_Round/160_Div_2/1.bin new file mode 100644 index 0000000..ea3658f Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/160_Div_2/1.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/160_Div_2/1.cpp b/CodeForces_Live_Contest/Educational_Round/160_Div_2/1.cpp new file mode 100644 index 0000000..5b985f6 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/160_Div_2/1.cpp @@ -0,0 +1,143 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +// Policy based data structures(PBDS) C++ STL +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// order_of_key(k): returns count of elements strictly smaller than k +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // for pairs only define simply by ordered_set s +typedef tree, null_type, less_equal>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset; +templateusing Tree = tree, rb_tree_tag, tree_order_statistics_node_update> ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree > s; for pairs + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + +void _print(long long t) {cerr << t;} +void _print(string t) {cerr << t;} +void _print(char t) {cerr << t;} +void _print(long double t) {cerr << t;} + +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#define ll long long // typedef array p ; pair h ye +#define int ll +#define ld long double +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << endl; +#define no cout << "NO" << endl; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< &a, pair &b){if(a.S != b.S){return a.S < b.S ;}return a.F > b.F ;} +long long power(long long x, long long y){long long res = 1 ; while(y > 0) {if(y & 1) res = (res * (long long)x) ; x = ((long long)x * (long long)x) ; y = y >> 1 ;} return res ;} +int modpower(int x, int y){long long res = 1; x = x % MOD; while(y > 0){if(y&1) res = (res * (long long)x) % MOD; y = y >> 1; x = ((long long)x * (long long)x) % MOD ;}return res ;} +int modinv(int x){return modpower(x , MOD - 2) ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +vector giveme_it_isprime_or_not(int n){vector isPrime(n+1, 1);isPrime[0]=isPrime[1]=false;for(int i = 2; i * i <= n; ++i){if(isPrime[i] == true){for(int j = 2 * i; j <= n; j += i){isPrime[j] = false;}}} return isPrime;} // Time Complexity - O(n * sqrt(n) * log(n)) +vector givemeprimes(int n) {int*arr = new int[n + 1](); vector vect; for(int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for(int j = i * i; j <= n; j += i)arr[j] = 1;} return vect;} // can be calculated in O(n) +vector> givemedivisors(int n){int*arr = new int[n + 1]();vector > vect(n + 1);for(int i = 2; i <= n; ++i){if(arr[i] == 0){for(int j = i; j <= n; j += i){vect[j].pb(i);arr[i] = 1;}}} return vect ;} +vector givemesmallestprimefactors(int n){vector SPF(n + 1);for(int i = 0; i <= n; ++i){SPF[i] = i;}for(int i = 2; i <= n; ++i){if(SPF[i] == i){for(int j = i; j <= n; j += i){if(SPF[j] == j){SPF[j] = i;}}}}return SPF ;} // SPF is the smallest prime number that divides a given number without leaving a remainder +int sqrtprecision(int l,int r,int target){while(r-l>EPS){int mid=(l+(r-l)/2);if(mid*mid(l, r)(rng);} + +bool solve(){ + string s ; + cin >> s ; + string first = "" ; + string second = "" ; + int n = s.size() ; + if(s[0] == '0'){ + cout << -1 << nl ; + return true ; + } + first += s[0] ; + int ind = -1 ; + for(int i = 1 ; i < n ; ++i){ + if(s[i] != '0'){ + ind = i ; + break ; + } + first += s[i] ; + } + if(ind == -1){ + cout << -1 << nl ; + return true ; + } + while(ind < n){ + second += s[ind] ; + ind++ ; + } + // cout << first.size() << " " << second.size() << nl ; + int ft = stoi(first) ; + int sd = stoi(second) ; + if(ft >= sd){ + cout << -1 << nl ; + return true ; + } + cout << ft << " " << sd << nl ; + return true ; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t ; + cin >> t ; + //int count = 1 ; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++ ; + }else{ + // no + } + } + return 0 ; +} + + + + // Talk is Cheap. Show me the code \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/160_Div_2/2.bin b/CodeForces_Live_Contest/Educational_Round/160_Div_2/2.bin new file mode 100644 index 0000000..f677667 Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/160_Div_2/2.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/160_Div_2/2.cpp b/CodeForces_Live_Contest/Educational_Round/160_Div_2/2.cpp new file mode 100644 index 0000000..15f0bd5 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/160_Div_2/2.cpp @@ -0,0 +1,149 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +// Policy based data structures(PBDS) C++ STL +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// order_of_key(k): returns count of elements strictly smaller than k +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // for pairs only define simply by ordered_set s +typedef tree, null_type, less_equal>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset; +templateusing Tree = tree, rb_tree_tag, tree_order_statistics_node_update> ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree > s; for pairs + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + +void _print(long long t) {cerr << t;} +void _print(string t) {cerr << t;} +void _print(char t) {cerr << t;} +void _print(long double t) {cerr << t;} + +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#define ll long long // typedef array p ; pair h ye +#define int ll +#define ld long double +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << endl; +#define no cout << "NO" << endl; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< &a, pair &b){if(a.S != b.S){return a.S < b.S ;}return a.F > b.F ;} +long long power(long long x, long long y){long long res = 1 ; while(y > 0) {if(y & 1) res = (res * (long long)x) ; x = ((long long)x * (long long)x) ; y = y >> 1 ;} return res ;} +int modpower(int x, int y){long long res = 1; x = x % MOD; while(y > 0){if(y&1) res = (res * (long long)x) % MOD; y = y >> 1; x = ((long long)x * (long long)x) % MOD ;}return res ;} +int modinv(int x){return modpower(x , MOD - 2) ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +vector giveme_it_isprime_or_not(int n){vector isPrime(n+1, 1);isPrime[0]=isPrime[1]=false;for(int i = 2; i * i <= n; ++i){if(isPrime[i] == true){for(int j = 2 * i; j <= n; j += i){isPrime[j] = false;}}} return isPrime;} // Time Complexity - O(n * sqrt(n) * log(n)) +vector givemeprimes(int n) {int*arr = new int[n + 1](); vector vect; for(int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for(int j = i * i; j <= n; j += i)arr[j] = 1;} return vect;} // can be calculated in O(n) +vector> givemedivisors(int n){int*arr = new int[n + 1]();vector > vect(n + 1);for(int i = 2; i <= n; ++i){if(arr[i] == 0){for(int j = i; j <= n; j += i){vect[j].pb(i);arr[i] = 1;}}} return vect ;} +vector givemesmallestprimefactors(int n){vector SPF(n + 1);for(int i = 0; i <= n; ++i){SPF[i] = i;}for(int i = 2; i <= n; ++i){if(SPF[i] == i){for(int j = i; j <= n; j += i){if(SPF[j] == j){SPF[j] = i;}}}}return SPF ;} // SPF is the smallest prime number that divides a given number without leaving a remainder +int sqrtprecision(int l,int r,int target){while(r-l>EPS){int mid=(l+(r-l)/2);if(mid*mid(l, r)(rng);} + +bool solve(){ + string s ; + cin >> s ; + int n = s.size() ; + int one = 0 ; + int zero = 0 ; + for(int i = 0 ; i < n ; ++i){ + if(s[i] == '1'){ + one++ ; + }else{ + zero++ ; + } + } + if(one == zero){ + cout << 0 << nl ; + return true ; + } + string t = s ; + for(int i = 0 ; i < n ; ++i){ + if(s[i] == '1' and zero){ + s[i] = '0' ; + zero -= 1 ; + } + else if(s[i] == '0' and one){ + s[i] = '1' ; + one -= 1 ; + } + } + int i = 0 ; + int j = 0 ; + int ans = 0 ; + while(i < n and j < n){ + if(s[i] != t[j]){ + i++ ; + j++ ; + }else{ + ans++ ; + i++ ; + } + } + cout << ans << nl ; + return true ; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t ; + cin >> t ; + //int count = 1 ; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++ ; + }else{ + // no + } + } + return 0 ; +} + + + + // Talk is Cheap. Show me the code \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/160_Div_2/3.bin b/CodeForces_Live_Contest/Educational_Round/160_Div_2/3.bin new file mode 100644 index 0000000..ad09ada Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/160_Div_2/3.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/160_Div_2/3.cpp b/CodeForces_Live_Contest/Educational_Round/160_Div_2/3.cpp new file mode 100644 index 0000000..d66a181 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/160_Div_2/3.cpp @@ -0,0 +1,136 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +#include +#include +using namespace __gnu_pbds; +typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // for pairs only define simply by ordered_set s +typedef tree, null_type, less_equal>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset; +templateusing Tree = tree, rb_tree_tag, tree_order_statistics_node_update> ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree > s; for pairs + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + +void _print(long long t) {cerr << t;} +void _print(string t) {cerr << t;} +void _print(char t) {cerr << t;} +void _print(long double t) {cerr << t;} + +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#define ll long long +#define int ll +#define ld long double +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << endl; +#define no cout << "NO" << endl; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< &a, pair &b){if(a.S != b.S){return a.S < b.S ;}return a.F > b.F ;} +long long power(long long x, long long y){long long res = 1 ; while(y > 0) {if(y & 1) res = (res * (long long)x) ; x = ((long long)x * (long long)x) ; y = y >> 1 ;} return res ;} +int modpower(int x, int y){long long res = 1; x = x % MOD; while(y > 0){if(y&1) res = (res * (long long)x) % MOD; y = y >> 1; x = ((long long)x * (long long)x) % MOD ;}return res ;} +int modinv(int x){return modpower(x , MOD - 2) ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +vector giveme_it_isprime_or_not(int n){vector isPrime(n+1, 1);isPrime[0]=isPrime[1]=false;for(int i = 2; i * i <= n; ++i){if(isPrime[i] == true){for(int j = 2 * i; j <= n; j += i){isPrime[j] = false;}}} return isPrime;} // Time Complexity - O(n * sqrt(n) * log(n)) +vector givemeprimes(int n) {int*arr = new int[n + 1](); vector vect; for(int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for(int j = i * i; j <= n; j += i)arr[j] = 1;} return vect;} // can be calculated in O(n) +vector> givemedivisors(int n){int*arr = new int[n + 1]();vector > vect(n + 1);for(int i = 2; i <= n; ++i){if(arr[i] == 0){for(int j = i; j <= n; j += i){vect[j].pb(i);arr[i] = 1;}}} return vect ;} +vector givemesmallestprimefactors(int n){vector SPF(n + 1);for(int i = 0; i <= n; ++i){SPF[i] = i;}for(int i = 2; i <= n; ++i){if(SPF[i] == i){for(int j = i; j <= n; j += i){if(SPF[j] == j){SPF[j] = i;}}}}return SPF ;} // SPF is the smallest prime number that divides a given number without leaving a remainder +int sqrtprecision(int l,int r,int target){while(r-l>EPS){int mid=(l+(r-l)/2);if(mid*mid(l, r)(rng);} + +bool solve(){ + int m ; + cin >> m ; + map mp ; + for(int i = 0 ; i < m ; ++i){ + int num , value ; + cin >> num >> value ; + if(num == 1){ + mp[value]++ ; + } + else{ + int val = value ; + int B = 0 ; + for(int j = 29 ; j >= 0 ; --j){ + int t = (1 << j) ; + int tt = mp[j] ; + while(t <= val and tt){ + val -= t ; + tt-- ; + } + if(val == 0){ + yes + B = 1 ; + break ; + } + } + if(!B){ + no + } + } + } + return true ; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t = 1 ; + //cin >> t ; + //int count = 1 ; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++; + }else{ + // no + } + } + return 0 ; +} + + + + + // Talk is Cheap. Show me the code diff --git a/CodeForces_Live_Contest/Educational_Round/160_Div_2/4.cpp b/CodeForces_Live_Contest/Educational_Round/160_Div_2/4.cpp new file mode 100644 index 0000000..dc8a37e --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/160_Div_2/4.cpp @@ -0,0 +1,79 @@ +#include +#include +#include +typedef long long ll; +#define pb push_back +#define ff first +#define ss second +const int N=2e3+7; +const int mod=998244353; +const double eps=1e-9; +const double pi= 3.14159265358979323846; +using namespace std; +using namespace __gnu_pbds; +typedef tree, rb_tree_tag, + tree_order_statistics_node_update> + op_set; + +int32_t main() +{ + ios_base::sync_with_stdio(false); + cin.tie(0); + + int t; + cin >> t; + while(t--) + { + int n; + cin >> n; + + vector ar(n); + for(int i=0;i> ar[i]; + + vector dp(n); + vectorpre(n+1); + stack s; + + long long curr=0ll;//sum of dp[i] for all j such that ar[j]ar[i]) + { + curr=(curr-dp[s.top()]+mod)%mod; + s.pop(); + } + else + break; + } + + if(s.empty()) + dp[i]=1ll; + else + dp[i]=curr; + + int from=s.empty()?0:s.top()+1; + dp[i]=(dp[i]+pre[i]-(from?pre[from]:0ll) +mod )%mod; + pre[i+1]=(pre[i]+dp[i])%mod; + + curr=(curr+dp[i])%mod; + s.push(i); + } + + long long ans=0ll; + while(!s.empty()) + { + ans=(ans+dp[s.top()])%mod; + s.pop(); + } + + cout << ans << "\n"; + } +} + +/* +Haan chalte chalte shaam dhal gayi +Dekha jo tujhe toh phir ye baat bangayi +*/ \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/161_Div_2/.cph/.1.cpp_670ec2ae388f7609bf539745f43ae63e.prob b/CodeForces_Live_Contest/Educational_Round/161_Div_2/.cph/.1.cpp_670ec2ae388f7609bf539745f43ae63e.prob new file mode 100644 index 0000000..7bfb085 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/161_Div_2/.cph/.1.cpp_670ec2ae388f7609bf539745f43ae63e.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\161_Div_2\\1.cpp","tests":[{"id":1705588764548,"input":"4\n1\na\nb\nc\n2\naa\nbb\naa\n10\nmathforces\nluckforces\nadhoccoder\n3\nacc\nabd\nabc","output":"YES\nNO\nYES\nNO\n"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\161_Div_2\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/161_Div_2/.cph/.2.cpp_97762a2383d6249c5a6fa654cfe1d508.prob b/CodeForces_Live_Contest/Educational_Round/161_Div_2/.cph/.2.cpp_97762a2383d6249c5a6fa654cfe1d508.prob new file mode 100644 index 0000000..eb6c0c1 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/161_Div_2/.cph/.2.cpp_97762a2383d6249c5a6fa654cfe1d508.prob @@ -0,0 +1 @@ +{"name":"Local: 2","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\161_Div_2\\2.cpp","tests":[{"id":1705589690967,"input":"4\n7\n1 1 1 1 1 1 1\n4\n3 2 1 3\n3\n1 2 3\n1\n1\n","output":"35\n2\n0\n0\n"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\161_Div_2\\2.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/161_Div_2/.cph/.3.cpp_76a1a170a37a12656d4b36bc2ad9c8b7.prob b/CodeForces_Live_Contest/Educational_Round/161_Div_2/.cph/.3.cpp_76a1a170a37a12656d4b36bc2ad9c8b7.prob new file mode 100644 index 0000000..5dde4e6 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/161_Div_2/.cph/.3.cpp_76a1a170a37a12656d4b36bc2ad9c8b7.prob @@ -0,0 +1 @@ +{"name":"Local: 3","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\161_Div_2\\3.cpp","tests":[{"id":1705590700821,"input":"1\n5\n0 8 12 15 20\n5\n1 4\n1 5\n3 4\n3 2\n5 1\n","output":"3\n8\n1\n4\n14\n"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\161_Div_2\\3.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/161_Div_2/1.bin b/CodeForces_Live_Contest/Educational_Round/161_Div_2/1.bin new file mode 100644 index 0000000..652ffb8 Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/161_Div_2/1.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/161_Div_2/1.cpp b/CodeForces_Live_Contest/Educational_Round/161_Div_2/1.cpp new file mode 100644 index 0000000..6d2bcd8 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/161_Div_2/1.cpp @@ -0,0 +1,133 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +// Policy based data structures(PBDS) C++ STL +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// order_of_key(k): returns count of elements strictly smaller than k +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // for pairs only define simply by ordered_set s +typedef tree, null_type, less_equal>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset; +templateusing Tree_SET = tree, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_SET > s; for pairs +templateusing Tree_MULTISET = tree, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_MULTISET > s; for pairs + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << "\n"; +#else +#define debug(x) +#endif + +void _print(long long t) {cerr << t;} +void _print(string t) {cerr << t;} +void _print(char t) {cerr << t;} +void _print(long double t) {cerr << t;} + +template void _print(pair p); +template void _print(vector v); +template void _print(set v); +template void _print(map v); +template void _print(multiset v); +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#define nl "\n" +#define ll long long // typedef array p ; pair h ye +#define int ll +#define ld long double +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << nl ; +#define no cout << "NO" << nl ; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< 0) {if(y & 1) res = (res * (long long)x) ; x = ((long long)x * (long long)x) ; y = y >> 1 ;} return res ;} +int modpower(int x, int y){long long res = 1; x = x % MOD; while(y > 0){if(y&1) res = (res * (long long)x) % MOD; y = y >> 1; x = ((long long)x * (long long)x) % MOD ;}return res ;} +int modinv(int x){return modpower(x , MOD - 2) ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +bool comparatorfunction(pair &a, pair &b){if(a.S != b.S){return a.S < b.S ;}return a.F > b.F ;} +vector giveme_it_isprime_or_not(int n){vector isPrime(n+1, 1);isPrime[0]=isPrime[1]=false;for(int i = 2; i * i <= n; ++i){if(isPrime[i] == true){for(int j = 2 * i; j <= n; j += i){isPrime[j] = false;}}} return isPrime;} // Time Complexity - O(n * sqrt(n) * log(n)) +vector givemeprimes(int n) {int*arr = new int[n + 1](); vector vect; for(int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for(int j = i * i; j <= n; j += i)arr[j] = 1;} return vect;} // can be calculated in O(n) +vector> givemedivisors(int n){int*arr = new int[n + 1]();vector > vect(n + 1);for(int i = 2; i <= n; ++i){if(arr[i] == 0){for(int j = i; j <= n; j += i){vect[j].pb(i);arr[i] = 1;}}} return vect ;} +vector givemesmallestprimefactors(int n){vector SPF(n + 1);for(int i = 0; i <= n; ++i){SPF[i] = i;}for(int i = 2; i <= n; ++i){if(SPF[i] == i){for(int j = i; j <= n; j += i){if(SPF[j] == j){SPF[j] = i;}}}}return SPF ;} // SPF is the smallest prime number that divides a given number without leaving a remainder +int sqrtprecision(int l,int r,int target){while(r-l>EPS){int mid=(l+(r-l)/2);if(mid*mid(l, r)(rng);} + +bool solve(){ + int n ; + cin >> n ; + string a , b , c ; + cin >> a >> b >> c ; + int f = 0 ; + for(int i = 0 ; i < n ; ++i){ + if(c[i] == a[i] || c[i] == b[i]){ + + } + else{ + f = 1 ; + } + } + if(f) yes + else no + return true ; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +#ifndef ONLINE_JUDGE + freopen("Error.txt", "w", stderr); +#endif +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t ; + cin >> t ; + //int count = 1 ; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++ ; + }else{ + // no + } + } + return 0 ; +} + + + + // Talk is Cheap. Show me the code \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/161_Div_2/2.bin b/CodeForces_Live_Contest/Educational_Round/161_Div_2/2.bin new file mode 100644 index 0000000..5dbebd7 Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/161_Div_2/2.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/161_Div_2/2.cpp b/CodeForces_Live_Contest/Educational_Round/161_Div_2/2.cpp new file mode 100644 index 0000000..d22e367 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/161_Div_2/2.cpp @@ -0,0 +1,146 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +// Policy based data structures(PBDS) C++ STL +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// order_of_key(k): returns count of elements strictly smaller than k +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // for pairs only define simply by ordered_set s +typedef tree, null_type, less_equal>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset; +templateusing Tree_SET = tree, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_SET > s; for pairs +templateusing Tree_MULTISET = tree, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_MULTISET > s; for pairs + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << "\n"; +#else +#define debug(x) +#endif + +void _print(long long t) {cerr << t;} +void _print(string t) {cerr << t;} +void _print(char t) {cerr << t;} +void _print(long double t) {cerr << t;} + +template void _print(pair p); +template void _print(vector v); +template void _print(set v); +template void _print(map v); +template void _print(multiset v); +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#define nl "\n" +#define ll long long // typedef array p ; pair h ye +#define int ll +#define ld long double +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << nl ; +#define no cout << "NO" << nl ; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< 0) {if(y & 1) res = (res * (long long)x) ; x = ((long long)x * (long long)x) ; y = y >> 1 ;} return res ;} +int modpower(int x, int y){long long res = 1; x = x % MOD; while(y > 0){if(y&1) res = (res * (long long)x) % MOD; y = y >> 1; x = ((long long)x * (long long)x) % MOD ;}return res ;} +int modinv(int x){return modpower(x , MOD - 2) ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +bool comparatorfunction(pair &a, pair &b){if(a.S != b.S){return a.S < b.S ;}return a.F > b.F ;} +vector giveme_it_isprime_or_not(int n){vector isPrime(n+1, 1);isPrime[0]=isPrime[1]=false;for(int i = 2; i * i <= n; ++i){if(isPrime[i] == true){for(int j = 2 * i; j <= n; j += i){isPrime[j] = false;}}} return isPrime;} // Time Complexity - O(n * sqrt(n) * log(n)) +vector givemeprimes(int n) {int*arr = new int[n + 1](); vector vect; for(int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for(int j = i * i; j <= n; j += i)arr[j] = 1;} return vect;} // can be calculated in O(n) +vector> givemedivisors(int n){int*arr = new int[n + 1]();vector > vect(n + 1);for(int i = 2; i <= n; ++i){if(arr[i] == 0){for(int j = i; j <= n; j += i){vect[j].pb(i);arr[i] = 1;}}} return vect ;} +vector givemesmallestprimefactors(int n){vector SPF(n + 1);for(int i = 0; i <= n; ++i){SPF[i] = i;}for(int i = 2; i <= n; ++i){if(SPF[i] == i){for(int j = i; j <= n; j += i){if(SPF[j] == j){SPF[j] = i;}}}}return SPF ;} // SPF is the smallest prime number that divides a given number without leaving a remainder +int sqrtprecision(int l,int r,int target){while(r-l>EPS){int mid=(l+(r-l)/2);if(mid*mid(l, r)(rng);} + +bool solve(){ + int n ; + cin >> n ; + iv(v , n) + map mp ; + set s ; + for(int i = 0 ; i < n ; ++i){ + mp[v[i]] += 1 ; + s.insert(v[i]) ; + } + int ans = 0 ; + sort(all(v)) ; + vector vv(s.begin() , s.end()) ; + int mult = 0 ; + // check1(vv) + for(int i = 0 ; i < s.size() ; ++i){ + if(mp[vv[i]] > 1){ + int val = mp[vv[i]] ; + int cur = (val * (val - 1)) / 2 ; + ans += (cur * mult) ; + } + if(mp[vv[i]] > 2){ + int val = mp[vv[i]] ; + int cur = (val * (val - 1) * (val - 2)) / 6 ; + ans += cur ; + } + mult += mp[vv[i]] ; + } + cout << ans << nl ; + return true ; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +#ifndef ONLINE_JUDGE + freopen("Error.txt", "w", stderr); +#endif +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t ; + cin >> t ; + //int count = 1 ; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++ ; + }else{ + // no + } + } + return 0 ; +} + + + + // Talk is Cheap. Show me the code \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/161_Div_2/3.bin b/CodeForces_Live_Contest/Educational_Round/161_Div_2/3.bin new file mode 100644 index 0000000..96f9967 Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/161_Div_2/3.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/161_Div_2/3.cpp b/CodeForces_Live_Contest/Educational_Round/161_Div_2/3.cpp new file mode 100644 index 0000000..e29f845 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/161_Div_2/3.cpp @@ -0,0 +1,165 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +// Policy based data structures(PBDS) C++ STL +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// order_of_key(k): returns count of elements strictly smaller than k +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // for pairs only define simply by ordered_set s +typedef tree, null_type, less_equal>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset; +templateusing Tree_SET = tree, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_SET > s; for pairs +templateusing Tree_MULTISET = tree, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_MULTISET > s; for pairs + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << "\n"; +#else +#define debug(x) +#endif + +void _print(long long t) {cerr << t;} +void _print(string t) {cerr << t;} +void _print(char t) {cerr << t;} +void _print(long double t) {cerr << t;} + +template void _print(pair p); +template void _print(vector v); +template void _print(set v); +template void _print(map v); +template void _print(multiset v); +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#define nl "\n" +#define ll long long // typedef array p ; pair h ye +#define int ll +#define ld long double +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << nl ; +#define no cout << "NO" << nl ; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< 0) {if(y & 1) res = (res * (long long)x) ; x = ((long long)x * (long long)x) ; y = y >> 1 ;} return res ;} +int modpower(int x, int y){long long res = 1; x = x % MOD; while(y > 0){if(y&1) res = (res * (long long)x) % MOD; y = y >> 1; x = ((long long)x * (long long)x) % MOD ;}return res ;} +int modinv(int x){return modpower(x , MOD - 2) ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +bool comparatorfunction(pair &a, pair &b){if(a.S != b.S){return a.S < b.S ;}return a.F > b.F ;} +vector giveme_it_isprime_or_not(int n){vector isPrime(n+1, 1);isPrime[0]=isPrime[1]=false;for(int i = 2; i * i <= n; ++i){if(isPrime[i] == true){for(int j = 2 * i; j <= n; j += i){isPrime[j] = false;}}} return isPrime;} // Time Complexity - O(n * sqrt(n) * log(n)) +vector givemeprimes(int n) {int*arr = new int[n + 1](); vector vect; for(int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for(int j = i * i; j <= n; j += i)arr[j] = 1;} return vect;} // can be calculated in O(n) +vector> givemedivisors(int n){int*arr = new int[n + 1]();vector > vect(n + 1);for(int i = 2; i <= n; ++i){if(arr[i] == 0){for(int j = i; j <= n; j += i){vect[j].pb(i);arr[i] = 1;}}} return vect ;} +vector givemesmallestprimefactors(int n){vector SPF(n + 1);for(int i = 0; i <= n; ++i){SPF[i] = i;}for(int i = 2; i <= n; ++i){if(SPF[i] == i){for(int j = i; j <= n; j += i){if(SPF[j] == j){SPF[j] = i;}}}}return SPF ;} // SPF is the smallest prime number that divides a given number without leaving a remainder +int sqrtprecision(int l,int r,int target){while(r-l>EPS){int mid=(l+(r-l)/2);if(mid*mid(l, r)(rng);} + +bool solve(){ + int n ; + cin >> n ; + iv(v , n) + vector pre(n + 1 , 0) ; + pre[0] = 0 ; + for(int i = 1 ; i < n ; ++i){ + if(i == 1){ + pre[i] = 1 ; + } + else{ + if(v[i - 1] - v[i - 2] > v[i] - v[i - 1]){ + pre[i] = pre[i - 1] + 1 ; + } + else{ + pre[i] = pre[i - 1] + v[i] - v[i - 1] ; + } + } + } + pre[n] = pre[n - 1] + 1 ; + vector suf(n + 1 , 0) ; + for(int i = n - 1 ; i > 0 ; --i){ + if(i == n - 1){ + suf[i] = 1 ; + } + else{ + if(v[i + 1] - v[i] > v[i] - v[i - 1]){ + suf[i] = suf[i + 1] + 1 ; + } + else{ + suf[i] = suf[i + 1] + v[i] - v[i - 1] ; + } + } + } + // check1(pre) + // check1(suf) + int m ; + cin >> m ; + while(m--){ + int x , y ; + cin >> x >> y ; + if(x < y){ + cout << pre[y - 1] - pre[x - 1] << nl ; + } + else{ + cout << suf[y] - suf[x] << nl ; + } + } + return true ; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +#ifndef ONLINE_JUDGE + freopen("Error.txt", "w", stderr); +#endif +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t ; + cin >> t ; + //int count = 1 ; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++ ; + }else{ + // no + } + } + return 0 ; +} + + + + // Talk is Cheap. Show me the code \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/161_Div_2/4.cpp b/CodeForces_Live_Contest/Educational_Round/161_Div_2/4.cpp new file mode 100644 index 0000000..e69de29 diff --git a/CodeForces_Live_Contest/Educational_Round/161_Div_2/5.cpp b/CodeForces_Live_Contest/Educational_Round/161_Div_2/5.cpp new file mode 100644 index 0000000..e69de29 diff --git a/CodeForces_Live_Contest/Educational_Round/162_Div_2/.cph/.1.cpp_bfce053709ad7ea6f38941240786d396.prob b/CodeForces_Live_Contest/Educational_Round/162_Div_2/.cph/.1.cpp_bfce053709ad7ea6f38941240786d396.prob new file mode 100644 index 0000000..2f186fe --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/162_Div_2/.cph/.1.cpp_bfce053709ad7ea6f38941240786d396.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\162_Div_2\\1.cpp","tests":[{"id":1708699064460,"input":"5\n8\n0 1 1 1 0 1 1 0\n6\n0 1 0 0 0 0\n6\n1 1 1 1 1 1\n5\n1 0 1 0 1\n9\n0 1 1 0 0 0 1 1 0","output":"1\n0\n0\n2\n3"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\162_Div_2\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/162_Div_2/.cph/.2.cpp_3c70273a809379379809efd17c13524c.prob b/CodeForces_Live_Contest/Educational_Round/162_Div_2/.cph/.2.cpp_3c70273a809379379809efd17c13524c.prob new file mode 100644 index 0000000..4f992d5 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/162_Div_2/.cph/.2.cpp_3c70273a809379379809efd17c13524c.prob @@ -0,0 +1 @@ +{"name":"Local: 2","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\162_Div_2\\2.cpp","tests":[{"id":1708699770227,"input":"5\n3 2\n1 2 3\n-1 2 3\n2 1\n1 1\n-1 1\n4 10\n3 4 2 5\n-3 -2 1 3\n5 3\n2 1 3 2 5\n-3 -2 3 4 5\n2 1\n1 2\n1 2\n","output":"YES\nNO\nYES\nYES\nNO\n"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\162_Div_2\\2.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/162_Div_2/.cph/.3.cpp_9c266119427b9eba01218fa84076602d.prob b/CodeForces_Live_Contest/Educational_Round/162_Div_2/.cph/.3.cpp_9c266119427b9eba01218fa84076602d.prob new file mode 100644 index 0000000..b42104b --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/162_Div_2/.cph/.3.cpp_9c266119427b9eba01218fa84076602d.prob @@ -0,0 +1 @@ +{"name":"Local: 3","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\162_Div_2\\3.cpp","tests":[{"id":1708700417361,"input":"1\n5 4\n1 2 1 4 5\n1 5\n4 4\n3 4\n1 3\n","output":"YES\nNO\nYES\nNO\n"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\162_Div_2\\3.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/162_Div_2/.cph/.4.cpp_889cfb3b94fbe19e6c8efe34c894ee5f.prob b/CodeForces_Live_Contest/Educational_Round/162_Div_2/.cph/.4.cpp_889cfb3b94fbe19e6c8efe34c894ee5f.prob new file mode 100644 index 0000000..c124697 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/162_Div_2/.cph/.4.cpp_889cfb3b94fbe19e6c8efe34c894ee5f.prob @@ -0,0 +1 @@ +{"name":"Local: 4","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\162_Div_2\\4.cpp","tests":[{"id":1708703641657,"input":"4\n4\n3 2 4 2\n3\n1 2 3\n5\n2 2 3 1 1\n7\n4 2 3 6 1 1 8\n","output":"2 1 2 1 \n1 1 -1 \n2 1 -1 1 2 \n2 1 1 3 1 1 4 \n"},{"id":1708703884421,"input":"1\n4\n3 2 4 2","output":"2 1 2 1"},{"id":1708704858309,"input":"2\n4\n1 1 1 2\n4\n2 1 1 1","output":""}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\162_Div_2\\4.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/162_Div_2/.cph/.5.cpp_14c8b70948e417375a2811fa2934a6eb.prob b/CodeForces_Live_Contest/Educational_Round/162_Div_2/.cph/.5.cpp_14c8b70948e417375a2811fa2934a6eb.prob new file mode 100644 index 0000000..d4edcbc --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/162_Div_2/.cph/.5.cpp_14c8b70948e417375a2811fa2934a6eb.prob @@ -0,0 +1 @@ +{"name":"Local: 5","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\162_Div_2\\5.cpp","tests":[{"id":1708714595842,"input":"4\n3\n1 2 1\n1 2\n2 3\n5\n2 1 2 1 2\n1 2\n1 3\n3 4\n4 5\n5\n1 2 3 4 5\n1 2\n1 3\n3 4\n4 5\n4\n2 2 2 2\n3 1\n3 2\n3 4","output":"1\n3\n0\n3"},{"id":1708714831454,"input":"1\n21\n19 17 17 12 13 3 9 13 13 16 18 14 10 16 9 1 4 5 6 15 16\n12 14\n3 9\n17 20\n8 15\n9 13\n6 10\n16 11\n5 19\n12 11\n5 21\n12 2\n4 8\n7 10\n12 18\n8 1\n11 13\n9 17\n7 13\n1 14\n3 19","output":"7"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\162_Div_2\\5.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/162_Div_2/1.bin b/CodeForces_Live_Contest/Educational_Round/162_Div_2/1.bin new file mode 100644 index 0000000..3ede32e Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/162_Div_2/1.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/162_Div_2/1.cpp b/CodeForces_Live_Contest/Educational_Round/162_Div_2/1.cpp new file mode 100644 index 0000000..3409ea1 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/162_Div_2/1.cpp @@ -0,0 +1,110 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize(3, "Ofast", "inline") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +// Policy based data structures(PBDS) C++ STL +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// order_of_key(k): returns count of elements strictly smaller than k +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +template using Tree_SET = tree< T , null_type , less, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_SET > s; for pairs +template using Tree_MULTISET = tree< T , null_type , less_equal, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_MULTISET > s; for pairs + +#define nl "\n" +#define ll long long // typedef array p ; pair h ye +#define int ll +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << nl ; +#define no cout << "NO" << nl ; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< 0){if(y&1) res = (res * (long long)x) % MOD; y = y >> 1; x = ((long long)x * (long long)x) % MOD ;}return res ;} +int mod_ADDITION(int a, int b, int m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} +int mod_SUBTRACTION(int a, int b, int m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} +int mod_MULTIPLICATION(int a, int b, int m) {a = a % m; b = b % m; return ((((long long)a * (long long)b) % m) + m) % m;} +int mod_DIVISION(int a, int b, int m){a %= m , b %= m; return mod_MULTIPLICATION(a , modpower(b , m - 2) , m);} +long long power(long long x, long long y){long long res = 1 ; while(y > 0) {if(y & 1) res = (res * (long long)x) ; x = ((long long)x * (long long)x) ; y = y >> 1 ;} return res ;} +int modinv(int x){return modpower(x , MOD - 2) ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +bool comparatorfunction(pair &a, pair &b){if(a.F != b.F){return a.F < b.F ;}return a.S > b.S ;} +int getRandomNumber(int l, int r) {return uniform_int_distribution(l, r)(rng);} + +bool solve(){ + int n ; + cin >> n ; + iv(v , n) + int ft_one = 0 ; + int lst_one = 0 ; + for(int i = 0; i < n; i++){ + if(v[i] == 1){ + ft_one = i ; + break ; + } + } + for(int i = n - 1; i >= 0; i--){ + if(v[i] == 1){ + lst_one = i ; + break ; + } + } + int cnt = count(all(v) , 1) ; + if(cnt == 0){ + cout << 0 << nl ; + return true ; + } + int ans = 0 ; + for(int i = ft_one; i <= lst_one; i++){ + if(v[i] == 0){ + ans++ ; + } + } + cout << ans << nl ; + return true ; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t ; + cin >> t ; + //int count = 1 ; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++ ; + }else{ + // no + } + } + return 0 ; +} + + diff --git a/CodeForces_Live_Contest/Educational_Round/162_Div_2/2.bin b/CodeForces_Live_Contest/Educational_Round/162_Div_2/2.bin new file mode 100644 index 0000000..5c6f721 Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/162_Div_2/2.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/162_Div_2/2.cpp b/CodeForces_Live_Contest/Educational_Round/162_Div_2/2.cpp new file mode 100644 index 0000000..80038d5 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/162_Div_2/2.cpp @@ -0,0 +1,108 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize(3, "Ofast", "inline") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +// Policy based data structures(PBDS) C++ STL +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// order_of_key(k): returns count of elements strictly smaller than k +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +template using Tree_SET = tree< T , null_type , less, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_SET > s; for pairs +template using Tree_MULTISET = tree< T , null_type , less_equal, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_MULTISET > s; for pairs + +#define nl "\n" +#define ll long long // typedef array p ; pair h ye +#define int ll +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << nl ; +#define no cout << "NO" << nl ; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< 0){if(y&1) res = (res * (long long)x) % MOD; y = y >> 1; x = ((long long)x * (long long)x) % MOD ;}return res ;} +int mod_ADDITION(int a, int b, int m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} +int mod_SUBTRACTION(int a, int b, int m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} +int mod_MULTIPLICATION(int a, int b, int m) {a = a % m; b = b % m; return ((((long long)a * (long long)b) % m) + m) % m;} +int mod_DIVISION(int a, int b, int m){a %= m , b %= m; return mod_MULTIPLICATION(a , modpower(b , m - 2) , m);} +long long power(long long x, long long y){long long res = 1 ; while(y > 0) {if(y & 1) res = (res * (long long)x) ; x = ((long long)x * (long long)x) ; y = y >> 1 ;} return res ;} +int modinv(int x){return modpower(x , MOD - 2) ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +bool comparatorfunction(pair &a, pair &b){if(a.F != b.F){return a.F < b.F ;}return a.S > b.S ;} +int getRandomNumber(int l, int r) {return uniform_int_distribution(l, r)(rng);} + +bool solve(){ + int n , k ; + cin >> n >> k ; + iv(a , n) + iv(x , n) + for(int i = 0 ; i < n ; ++i){ + if(x[i] < 0){ + x[i] *= -1 ; + } + } + map mp ; + for(int i = 0 ; i < n ; ++i){ + mp[x[i]] += a[i] ; + } + int left = 0 ; + int move = 0 ; + int f = 0 ; + for(auto &i : mp){ + int rem = i.F - move ; + if(left + rem * k < i.S){ + f = 1 ; + break ; + } + left = left + rem * k - i.S ; + move = i.F ; + } + if(f) no + else yes + return true ; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t ; + cin >> t ; + //int count = 1 ; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++ ; + }else{ + // no + } + } + return 0 ; +} + + diff --git a/CodeForces_Live_Contest/Educational_Round/162_Div_2/3.bin b/CodeForces_Live_Contest/Educational_Round/162_Div_2/3.bin new file mode 100644 index 0000000..8d472c8 Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/162_Div_2/3.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/162_Div_2/3.cpp b/CodeForces_Live_Contest/Educational_Round/162_Div_2/3.cpp new file mode 100644 index 0000000..89cdb6c --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/162_Div_2/3.cpp @@ -0,0 +1,123 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize(3, "Ofast", "inline") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +// Policy based data structures(PBDS) C++ STL +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// order_of_key(k): returns count of elements strictly smaller than k +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +template using Tree_SET = tree< T , null_type , less, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_SET > s; for pairs +template using Tree_MULTISET = tree< T , null_type , less_equal, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_MULTISET > s; for pairs + +#define nl "\n" +#define ll long long // typedef array p ; pair h ye +#define int ll +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << nl ; +#define no cout << "NO" << nl ; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< 0){if(y&1) res = (res * (long long)x) % MOD; y = y >> 1; x = ((long long)x * (long long)x) % MOD ;}return res ;} +int mod_ADDITION(int a, int b, int m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} +int mod_SUBTRACTION(int a, int b, int m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} +int mod_MULTIPLICATION(int a, int b, int m) {a = a % m; b = b % m; return ((((long long)a * (long long)b) % m) + m) % m;} +int mod_DIVISION(int a, int b, int m){a %= m , b %= m; return mod_MULTIPLICATION(a , modpower(b , m - 2) , m);} +long long power(long long x, long long y){long long res = 1 ; while(y > 0) {if(y & 1) res = (res * (long long)x) ; x = ((long long)x * (long long)x) ; y = y >> 1 ;} return res ;} +int modinv(int x){return modpower(x , MOD - 2) ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +bool comparatorfunction(pair &a, pair &b){if(a.F != b.F){return a.F < b.F ;}return a.S > b.S ;} +int getRandomNumber(int l, int r) {return uniform_int_distribution(l, r)(rng);} + +bool solve(){ + int n , q ; + cin >> n >> q ; + iv(c , n) + vector pf(n , 0) ; + pf[0] = (c[0] == 1 ? 1 : 0) ; + for(int i = 1 ; i < n ; ++i){ + if(c[i] == 1){ + pf[i] = pf[i - 1] + c[i] ; + } + else{ + pf[i] = pf[i - 1] ; + } + } + // check1(pf) + vector pf_sum(n , 0) ; + pf_sum[0] = c[0] ; + for(int i = 1 ; i < n ; ++i){ + pf_sum[i] = pf_sum[i - 1] + c[i] ; + } + while(q--){ + int l , r ; + cin >> l >> r ; + l -= 1 ; + r -= 1 ; + int sum = 0 ; + if(l == 0){ + sum = pf_sum[r] ; + } + else{ + sum = pf_sum[r] - pf_sum[l - 1] ; + } + int one = 0 ; + if(l == 0){ + one = pf[r] ; + } + else{ + one = pf[r] - pf[l - 1] ; + } + int len = r - l + 1 ; + if(sum < len + one || r == l) no + else yes + } + return true ; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t ; + cin >> t ; + //int count = 1 ; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++ ; + }else{ + // no + } + } + return 0 ; +} + + diff --git a/CodeForces_Live_Contest/Educational_Round/162_Div_2/4.bin b/CodeForces_Live_Contest/Educational_Round/162_Div_2/4.bin new file mode 100644 index 0000000..c91193f Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/162_Div_2/4.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/162_Div_2/4.cpp b/CodeForces_Live_Contest/Educational_Round/162_Div_2/4.cpp new file mode 100644 index 0000000..e068280 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/162_Div_2/4.cpp @@ -0,0 +1,154 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize(3, "Ofast", "inline") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +// Policy based data structures(PBDS) C++ STL +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// order_of_key(k): returns count of elements strictly smaller than k +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +template using Tree_SET = tree< T , null_type , less, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_SET > s; for pairs +template using Tree_MULTISET = tree< T , null_type , less_equal, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_MULTISET > s; for pairs + +#define nl "\n" +#define ll long long // typedef array p ; pair h ye +#define int ll +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << nl ; +#define no cout << "NO" << nl ; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< 0){if(y&1) res = (res * (long long)x) % MOD; y = y >> 1; x = ((long long)x * (long long)x) % MOD ;}return res ;} +int mod_ADDITION(int a, int b, int m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} +int mod_SUBTRACTION(int a, int b, int m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} +int mod_MULTIPLICATION(int a, int b, int m) {a = a % m; b = b % m; return ((((long long)a * (long long)b) % m) + m) % m;} +int mod_DIVISION(int a, int b, int m){a %= m , b %= m; return mod_MULTIPLICATION(a , modpower(b , m - 2) , m);} +long long power(long long x, long long y){long long res = 1 ; while(y > 0) {if(y & 1) res = (res * (long long)x) ; x = ((long long)x * (long long)x) ; y = y >> 1 ;} return res ;} +int modinv(int x){return modpower(x , MOD - 2) ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +bool comparatorfunction(pair &a, pair &b){if(a.F != b.F){return a.F < b.F ;}return a.S > b.S ;} +int getRandomNumber(int l, int r) {return uniform_int_distribution(l, r)(rng);} + +bool solve(){ + int n ; + cin >> n ; + iv(v , n) + vector left ; + vector pf(n) ; + pf[0] = v[0] ; + for(int i = 1 ; i < n ; ++i){ + pf[i] = pf[i - 1] + v[i] ; + } + for(int i = 0 ; i < n - 1 ; ++i){ + if(v[i] != v[i + 1]){ + left.pb(i) ; + } + } + vector vv = v ; + reverse(all(vv)) ; + vector right ; + vector sf(n) ; + sf[0] = vv[0] ; + for(int i = 1 ; i < n ; ++i){ + sf[i] = sf[i - 1] + vv[i] ; + } + for(int i = 0 ; i < n - 1 ; ++i){ + if(vv[i] != vv[i + 1]){ + right.pb(i) ; + } + } + // check1(pf) + // check1(sf) + vector ans(n , inf) ; + vector rans(n , inf) ; + for(int i = 0 ; i < n ; ++i){ + int last = left.size() ; + if(left.size()) last = upper_bound(all(left) , i) - left.begin() ; + int sum_last = upper_bound(all(pf) , pf[i] + v[i]) - pf.begin() ; + // cout << last << " " << sum_last << nl ; + if(i < n - 1 and v[i + 1] > v[i]){ + ans[i] = 1 ; + } + else if(last == left.size() || sum_last == pf.size()){ + ans[i] = inf ; + } + else{ + ans[i] = max(sum_last - i , left[last] + 1 - i) ; + } + } + for(int i = 0 ; i < n ; ++i){ + int last = right.size() ; + if(right.size()) last = upper_bound(all(right) , i) - right.begin() ; + int sum_last = upper_bound(all(sf) , sf[i] + vv[i]) - sf.begin() ; + // cout << last << " " << sum_last << " " ; + if(i < n - 1 and vv[i + 1] > vv[i]){ + // cout << "ft" << nl ; + rans[n - 1 - i] = 1 ; + } + else if(last == right.size() || sum_last == sf.size()){ + // cout << "sc" << nl ; + rans[n - 1 - i] = inf ; + } + else{ + // cout << "th" << nl ; + rans[n - 1 - i] = max(sum_last - i , right[last] + 1 - i) ; + } + } + // check1(ans) + // check1(rans) + for(int i = 0 ; i < n ; ++i){ + ans[i] = min(ans[i] , rans[i]) ; + } + for(int i = 0 ; i < n ; ++i){ + if(ans[i] == inf) ans[i] = -1 ; + } + check1(ans) + return true ; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t ; + cin >> t ; + //int count = 1 ; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++ ; + }else{ + // no + } + } + return 0 ; +} + + diff --git a/CodeForces_Live_Contest/Educational_Round/162_Div_2/5.bin b/CodeForces_Live_Contest/Educational_Round/162_Div_2/5.bin new file mode 100644 index 0000000..b6b50e1 Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/162_Div_2/5.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/162_Div_2/5.cpp b/CodeForces_Live_Contest/Educational_Round/162_Div_2/5.cpp new file mode 100644 index 0000000..4e0334b --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/162_Div_2/5.cpp @@ -0,0 +1,122 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize(3, "Ofast", "inline") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +// Policy based data structures(PBDS) C++ STL +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// order_of_key(k): returns count of elements strictly smaller than k +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +template using Tree_SET = tree< T , null_type , less, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_SET > s; for pairs +template using Tree_MULTISET = tree< T , null_type , less_equal, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_MULTISET > s; for pairs + +#define nl "\n" +#define ll long long // typedef array p ; pair h ye +#define int ll +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << nl ; +#define no cout << "NO" << nl ; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< 0){if(y&1) res = (res * (long long)x) % MOD; y = y >> 1; x = ((long long)x * (long long)x) % MOD ;}return res ;} +int mod_ADDITION(int a, int b, int m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} +int mod_SUBTRACTION(int a, int b, int m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} +int mod_MULTIPLICATION(int a, int b, int m) {a = a % m; b = b % m; return ((((long long)a * (long long)b) % m) + m) % m;} +int mod_DIVISION(int a, int b, int m){a %= m , b %= m; return mod_MULTIPLICATION(a , modpower(b , m - 2) , m);} +long long power(long long x, long long y){long long res = 1 ; while(y > 0) {if(y & 1) res = (res * (long long)x) ; x = ((long long)x * (long long)x) ; y = y >> 1 ;} return res ;} +int modinv(int x){return modpower(x , MOD - 2) ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +bool comparatorfunction(pair &a, pair &b){if(a.F != b.F){return a.F < b.F ;}return a.S > b.S ;} +int getRandomNumber(int l, int r) {return uniform_int_distribution(l, r)(rng);} + + + +bool solve(){ + int n ; + cin >> n ; + vectorcolor(n) ; + for(int i=0;i>color[i]; + color[i]-=1 ; + } + vector> adj(n) ; + for(int i = 0 ; i < n - 1 ; ++i){ + int u , v ; + cin >> u >> v ; + u -= 1 ; + v -= 1 ; + adj[u].pb(v) ; + adj[v].pb(u) ; + } + int ans=0; + vector> mp(n) ; + function dfs=[&](int child,int parent)->void{ + int seen=color[child]; + for(auto &i:adj[child]){ + if(i==parent) continue; + dfs(i,child) ; + if(mp[i].size() > mp[child].size()) swap(child , i); + for(auto &j : mp[i]){ + if(seen == j.F){ + // ans += j.S * (j.S - 1) / 2 ; + } + mp[child][j.F] += j.S ; + } + } + ans += mp[child][color[child]] ; + mp[child][color[child]] = 1 ; + }; + dfs(0,-1) ; + for(auto &i : mp[0]){ + ans += i.S * (i.S - 1) / 2 ; + } + cout << ans << nl ; + return true ; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t ; + cin >> t ; + //int count = 1 ; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++ ; + }else{ + // no + } + } + return 0 ; +} + + diff --git a/CodeForces_Live_Contest/Educational_Round/163_Div_2/.cph/.1.cpp_04daafc9ef27016c8041a9a18d261b8a.prob b/CodeForces_Live_Contest/Educational_Round/163_Div_2/.cph/.1.cpp_04daafc9ef27016c8041a9a18d261b8a.prob new file mode 100644 index 0000000..5ca0b9d --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/163_Div_2/.cph/.1.cpp_04daafc9ef27016c8041a9a18d261b8a.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\163_Div_2\\1.cpp","tests":[{"id":1710513423621,"input":"3\n6\n1\n2\n","output":""}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\163_Div_2\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/163_Div_2/.cph/.2.cpp_ecb5c3f1626e02d522cccfd80a009d93.prob b/CodeForces_Live_Contest/Educational_Round/163_Div_2/.cph/.2.cpp_ecb5c3f1626e02d522cccfd80a009d93.prob new file mode 100644 index 0000000..bc6866d --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/163_Div_2/.cph/.2.cpp_ecb5c3f1626e02d522cccfd80a009d93.prob @@ -0,0 +1 @@ +{"name":"Local: 2","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\163_Div_2\\2.cpp","tests":[{"id":1710513750871,"input":"3\n4\n12 3 45 67\n3\n12 28 5\n2\n0 0\n","output":"YES\nNO\nYES\n"},{"id":1710514974428,"input":"3\n2\n36 34\n4 \n1 2 3 10\n4\n0 0 12 2","output":""}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\163_Div_2\\2.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/163_Div_2/.cph/.4.cpp_30297a1f4494db792d3300316a9e5cad.prob b/CodeForces_Live_Contest/Educational_Round/163_Div_2/.cph/.4.cpp_30297a1f4494db792d3300316a9e5cad.prob new file mode 100644 index 0000000..affd1bf --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/163_Div_2/.cph/.4.cpp_30297a1f4494db792d3300316a9e5cad.prob @@ -0,0 +1 @@ +{"name":"Local: 4","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\163_Div_2\\4.cpp","tests":[{"id":1710517908382,"input":"4\nzaabaabz\n?????\ncode?????s\ncodeforces","output":"6\n4\n10\n0"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\163_Div_2\\4.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/163_Div_2/1.bin b/CodeForces_Live_Contest/Educational_Round/163_Div_2/1.bin new file mode 100644 index 0000000..16a9c22 Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/163_Div_2/1.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/163_Div_2/1.cpp b/CodeForces_Live_Contest/Educational_Round/163_Div_2/1.cpp new file mode 100644 index 0000000..6a4d779 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/163_Div_2/1.cpp @@ -0,0 +1,91 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize(3, "Ofast", "inline") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +// Policy based data structures(PBDS) C++ STL +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// order_of_key(k): returns count of elements strictly smaller than k +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +template using Tree_SET = tree< T , null_type , less, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_SET > s; for pairs +template using Tree_MULTISET = tree< T , null_type , less_equal, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_MULTISET > s; for pairs + +#define nl "\n" +#define ll long long // typedef array p ; pair h ye +#define int ll +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << nl ; +#define no cout << "NO" << nl ; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< 0){if(y&1) res = (res * (long long)x) % MOD; y = y >> 1; x = ((long long)x * (long long)x) % MOD ;}return res ;} +int mod_ADDITION(int a, int b, int m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} +int mod_SUBTRACTION(int a, int b, int m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} +int mod_MULTIPLICATION(int a, int b, int m) {a = a % m; b = b % m; return ((((long long)a * (long long)b) % m) + m) % m;} +int mod_DIVISION(int a, int b, int m){a %= m , b %= m; return mod_MULTIPLICATION(a , modpower(b , m - 2) , m);} +long long power(long long x, long long y){long long res = 1 ; while(y > 0) {if(y & 1) res = (res * (long long)x) ; x = ((long long)x * (long long)x) ; y = y >> 1 ;} return res ;} +int modinv(int x){return modpower(x , MOD - 2) ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +bool comparatorfunction(pair &a, pair &b){if(a.F != b.F){return a.F < b.F ;}return a.S > b.S ;} +int getRandomNumber(int l, int r) {return uniform_int_distribution(l, r)(rng);} + +bool solve(){ + int n; + cin >> n ; + if(n%2) no + else{ + yes + for(int i=0;i> t ; + //int count = 1 ; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++ ; + }else{ + // no + } + } + return 0 ; +} + + diff --git a/CodeForces_Live_Contest/Educational_Round/163_Div_2/2.bin b/CodeForces_Live_Contest/Educational_Round/163_Div_2/2.bin new file mode 100644 index 0000000..4c1ebce Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/163_Div_2/2.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/163_Div_2/2.cpp b/CodeForces_Live_Contest/Educational_Round/163_Div_2/2.cpp new file mode 100644 index 0000000..04be430 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/163_Div_2/2.cpp @@ -0,0 +1,125 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize(3, "Ofast", "inline") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +// Policy based data structures(PBDS) C++ STL +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// order_of_key(k): returns count of elements strictly smaller than k +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +template using Tree_SET = tree< T , null_type , less, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_SET > s; for pairs +template using Tree_MULTISET = tree< T , null_type , less_equal, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_MULTISET > s; for pairs + +#define nl "\n" +#define ll long long // typedef array p ; pair h ye +#define int ll +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << nl ; +#define no cout << "NO" << nl ; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< 0){if(y&1) res = (res * (long long)x) % MOD; y = y >> 1; x = ((long long)x * (long long)x) % MOD ;}return res ;} +int mod_ADDITION(int a, int b, int m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} +int mod_SUBTRACTION(int a, int b, int m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} +int mod_MULTIPLICATION(int a, int b, int m) {a = a % m; b = b % m; return ((((long long)a * (long long)b) % m) + m) % m;} +int mod_DIVISION(int a, int b, int m){a %= m , b %= m; return mod_MULTIPLICATION(a , modpower(b , m - 2) , m);} +long long power(long long x, long long y){long long res = 1 ; while(y > 0) {if(y & 1) res = (res * (long long)x) ; x = ((long long)x * (long long)x) ; y = y >> 1 ;} return res ;} +int modinv(int x){return modpower(x , MOD - 2) ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +bool comparatorfunction(pair &a, pair &b){if(a.F != b.F){return a.F < b.F ;}return a.S > b.S ;} +int getRandomNumber(int l, int r) {return uniform_int_distribution(l, r)(rng);} + +bool solve(){ + int n; + cin >> n ; + iv(v , n) + vector mark(n,0); + vector ans ; + int f = 0 ; + vector > p(n , {-1 , -1}) ; + for(int i = 0 ; i < n - 1 ; ++i){ + if(v[i + 1] < v[i]){ + int val = v[i] ; + if(val < 10){ + f = 1 ; + break ; + } + p[i] = {(val / 10) % 10 , val % 10} ; + // cout << (val / 10) % 10 << " " ; + int j = i - 1 ; + while(j >= 0 and p[j].F == -1 and p[j + 1].F >= (v[j] % 10) and v[j] > 9){ + p[j] = {(v[j] / 10) % 10 , v[j] % 10} ; + // cout << j << " " ; + j -= 1 ; + } + } + } + if(f){ + no + return true ; + } + for(int i = 0 ; i > t ; + //int count = 1 ; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++ ; + }else{ + // no + } + } + return 0 ; +} + + diff --git a/CodeForces_Live_Contest/Educational_Round/163_Div_2/3.cpp b/CodeForces_Live_Contest/Educational_Round/163_Div_2/3.cpp new file mode 100644 index 0000000..43e7556 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/163_Div_2/3.cpp @@ -0,0 +1,83 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize(3, "Ofast", "inline") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +// Policy based data structures(PBDS) C++ STL +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// order_of_key(k): returns count of elements strictly smaller than k +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +template using Tree_SET = tree< T , null_type , less, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_SET > s; for pairs +template using Tree_MULTISET = tree< T , null_type , less_equal, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_MULTISET > s; for pairs + +#define nl "\n" +#define ll long long // typedef array p ; pair h ye +#define int ll +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << nl ; +#define no cout << "NO" << nl ; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< 0){if(y&1) res = (res * (long long)x) % MOD; y = y >> 1; x = ((long long)x * (long long)x) % MOD ;}return res ;} +int mod_ADDITION(int a, int b, int m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} +int mod_SUBTRACTION(int a, int b, int m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} +int mod_MULTIPLICATION(int a, int b, int m) {a = a % m; b = b % m; return ((((long long)a * (long long)b) % m) + m) % m;} +int mod_DIVISION(int a, int b, int m){a %= m , b %= m; return mod_MULTIPLICATION(a , modpower(b , m - 2) , m);} +long long power(long long x, long long y){long long res = 1 ; while(y > 0) {if(y & 1) res = (res * (long long)x) ; x = ((long long)x * (long long)x) ; y = y >> 1 ;} return res ;} +int modinv(int x){return modpower(x , MOD - 2) ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +bool comparatorfunction(pair &a, pair &b){if(a.F != b.F){return a.F < b.F ;}return a.S > b.S ;} +int getRandomNumber(int l, int r) {return uniform_int_distribution(l, r)(rng);} + +bool solve(){ + int n ; + cin >> n ; + int des = 1 ; + return true ; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t ; + cin >> t ; + //int count = 1 ; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++ ; + }else{ + // no + } + } + return 0 ; +} + + diff --git a/CodeForces_Live_Contest/Educational_Round/163_Div_2/4.bin b/CodeForces_Live_Contest/Educational_Round/163_Div_2/4.bin new file mode 100644 index 0000000..bda91d9 Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/163_Div_2/4.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/163_Div_2/4.cpp b/CodeForces_Live_Contest/Educational_Round/163_Div_2/4.cpp new file mode 100644 index 0000000..04dfc49 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/163_Div_2/4.cpp @@ -0,0 +1,201 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize(3, "Ofast", "inline") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +// Policy based data structures(PBDS) C++ STL +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// order_of_key(k): returns count of elements strictly smaller than k +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +template using Tree_SET = tree< T , null_type , less, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_SET > s; for pairs +template using Tree_MULTISET = tree< T , null_type , less_equal, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_MULTISET > s; for pairs + +#define nl "\n" +#define ll long long // typedef array p ; pair h ye +#define int ll +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << nl ; +#define no cout << "NO" << nl ; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< 0){if(y&1) res = (res * (long long)x) % MOD; y = y >> 1; x = ((long long)x * (long long)x) % MOD ;}return res ;} +int mod_ADDITION(int a, int b, int m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} +int mod_SUBTRACTION(int a, int b, int m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} +int mod_MULTIPLICATION(int a, int b, int m) {a = a % m; b = b % m; return ((((long long)a * (long long)b) % m) + m) % m;} +int mod_DIVISION(int a, int b, int m){a %= m , b %= m; return mod_MULTIPLICATION(a , modpower(b , m - 2) , m);} +long long power(long long x, long long y){long long res = 1 ; while(y > 0) {if(y & 1) res = (res * (long long)x) ; x = ((long long)x * (long long)x) ; y = y >> 1 ;} return res ;} +int modinv(int x){return modpower(x , MOD - 2) ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +bool comparatorfunction(pair &a, pair &b){if(a.F != b.F){return a.F < b.F ;}return a.S > b.S ;} +int getRandomNumber(int l, int r) {return uniform_int_distribution(l, r)(rng);} + +// USES - Longest Palindromic Substring , +// Pattern Matching:to find occurrences of a specific +// palindromic pattern within a given text. +/* + +aba -->#a#b#a# +abba -->#a#b#b#a# + +how to build manacher +m.build(s) ; + +*/ +struct manacher { + vector p ; + int n ; + void run_manacher(string s) { + // cout << s << "\n" ; + int n = s.length() ; + s = "$" + s + "^" ; + p.resize(n + 2) ; + int l = 1 ; // l and r are not inclusive + int r = 1 ; + for(int i = 1 ; i <= n ; ++i){ + p[i] = max(0ll , min(p[l + r - i] , r - i)) ; + while(i - p[i] >= 0 && i + p[i] <= n && s[i - p[i]] == s[i + p[i]]){ + p[i]++ ; + } + if(i + p[i] > r){ // or + l = i - p[i] ; + r = i + p[i] ; + } + } + // cout << s << nl ; + // for(auto &v : p){ + // cout << v << " " ; + // } + // cout << "\n" ; + } + void build(string s){ // so that every substring is odd length + string t ; + for (auto it : s){ + t += string("#") + it ; // making every substring odd length + } + run_manacher(t + "#") ; + } + // abbabba + // cen = 1 , odd = 1 length = 1 + // cen = 1 , odd = 0 length = 4 + vector get_vector_p(){ + return p ; + } + int getlongest(int cen, bool odd) { + int pos = 2 * cen + odd + 1 + (!odd) ; + return p[pos] - 1 ; + } + bool checkPal(int l, int r) { + if ((r - l + 1) <= getlongest((r + l) / 2, l % 2 == r % 2)) { + return 1 ; + } + return 0 ; + } +} man; + + +// LPS (Longest Prefix Suffix) Algorithm: + +// Purpose: The LPS algorithm is primarily used to find the length of the longest proper prefix which is also a proper suffix of a given string for each position in the string. + +// Key Concept: It calculates an array where each element at index i represents the length of the longest proper prefix of the substring ending at position i that is also a proper suffix of the substring. + +// Usage: It is used as a building block in other string matching algorithms, like the KMP algorithm. + +vector longestprefixsuffix(string s){ + int n = s.size(); + vector lps(n , 0); + lps[0] = 0; + int len = 0; + int i = 1; + while(i < n){ + if(len < (i - len - 1) and s[i] == s[len] || s[i] == '?' || s[len] == '?'){ + len++ ; + lps[i] = len ; + i++ ; + }else{ + if(len != 0){ + len = lps[len - 1] ; + }else{ + lps[i] = 0 ; + i++ ; + } + } + } + return lps ; +} + + + +bool solve(){ + string s ; + cin >> s ; + int n = s.size() ; + string rev="" ; + for(int i = 0 ; i < n ; ++i){ + rev += s[i]; + } + int ans=0; + for(int i = 0 ; i < n ; ++i){ + vector p = longestprefixsuffix(rev) ; + check1(p) + for(int j = 0 ; j < p.size() ; ++j){ + if(p[j]){ + if(j + 1 - (p[j] * 2) <= 0){ + int t = min(p[j] * 2 , (n / 2) * 2) ; + ans = max(ans , t) ; + } + } + } + reverse(all(rev)) ; + rev.pop_back() ; + reverse(all(rev)) ; + } + cout << ans << nl ; + return true ; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t ; + cin >> t ; + //int count = 1 ; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++ ; + }else{ + // no + } + } + return 0 ; +} + + diff --git a/CodeForces_Live_Contest/Educational_Round/164_Div_2/.cph/.1.cpp_9a3fc0dda5f1f5bbf450621fb7ccf2a4.prob b/CodeForces_Live_Contest/Educational_Round/164_Div_2/.cph/.1.cpp_9a3fc0dda5f1f5bbf450621fb7ccf2a4.prob new file mode 100644 index 0000000..d931f35 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/164_Div_2/.cph/.1.cpp_9a3fc0dda5f1f5bbf450621fb7ccf2a4.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\164_Div_2\\1.cpp","tests":[{"id":1712932816750,"input":"5\n1 1 1\n5 1 1\n5 2 1\n5 2 2\n5 5 3\n","output":"NO\nNO\nYES\nNO\nYES\n"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\164_Div_2\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/164_Div_2/.cph/.2.cpp_b827cd67d05c4ae7d59e2509229d949c.prob b/CodeForces_Live_Contest/Educational_Round/164_Div_2/.cph/.2.cpp_b827cd67d05c4ae7d59e2509229d949c.prob new file mode 100644 index 0000000..6299203 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/164_Div_2/.cph/.2.cpp_b827cd67d05c4ae7d59e2509229d949c.prob @@ -0,0 +1 @@ +{"name":"Local: 2","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\164_Div_2\\2.cpp","tests":[{"id":1712933811074,"input":"4\n3\n2 2 2\n5\n1 2 1 2 1\n1\n1\n7\n3 3 3 5 3 3 3\n","output":"-1\n1\n-1\n3\n"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\164_Div_2\\2.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/164_Div_2/.cph/.3.cpp_07825d6de89885d678fd1bf74d7b1788.prob b/CodeForces_Live_Contest/Educational_Round/164_Div_2/.cph/.3.cpp_07825d6de89885d678fd1bf74d7b1788.prob new file mode 100644 index 0000000..a45091c --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/164_Div_2/.cph/.3.cpp_07825d6de89885d678fd1bf74d7b1788.prob @@ -0,0 +1 @@ +{"name":"Local: 3","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\164_Div_2\\3.cpp","tests":[{"id":1712934173465,"input":"3\n73\n31\n2\n5\n3516\n3982","output":""}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\164_Div_2\\3.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/164_Div_2/1.bin b/CodeForces_Live_Contest/Educational_Round/164_Div_2/1.bin new file mode 100644 index 0000000..00f8b9f Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/164_Div_2/1.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/164_Div_2/1.cpp b/CodeForces_Live_Contest/Educational_Round/164_Div_2/1.cpp new file mode 100644 index 0000000..8fe15cb --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/164_Div_2/1.cpp @@ -0,0 +1,84 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize(3, "Ofast", "inline") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +// Policy based data structures(PBDS) C++ STL +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// order_of_key(k): returns count of elements strictly smaller than k +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +template using Tree_SET = tree< T , null_type , less, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_SET > s; for pairs +template using Tree_MULTISET = tree< T , null_type , less_equal, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_MULTISET > s; for pairs + +#define nl "\n" +#define ll long long // typedef array p ; pair h ye +#define int ll +#define yes cout << "YES" << nl ; +#define no cout << "NO" << nl ; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< 0){if(y&1) res = (res * (long long)x) % MOD; y = y >> 1; x = ((long long)x * (long long)x) % MOD ;}return res ;} +int mod_ADDITION(int a, int b, int m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} +int mod_SUBTRACTION(int a, int b, int m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} +int mod_MULTIPLICATION(int a, int b, int m) {a = a % m; b = b % m; return ((((long long)a * (long long)b) % m) + m) % m;} +int mod_DIVISION(int a, int b, int m){a %= m , b %= m; return mod_MULTIPLICATION(a , modpower(b , m - 2 , MOD) , m);} +long long power(long long x, long long y){long long res = 1 ; while(y > 0) {if(y & 1) res = (res * (long long)x) ; x = ((long long)x * (long long)x) ; y = y >> 1 ;} return res ;} +int modinv(int x){return modpower(x , MOD - 2 , MOD) ;} +bool comparatorfunction(pair &a, pair &b){if(a.F != b.F){return a.F < b.F ;}return a.S > b.S ;} + +bool solve(){ + int n , m , k ; + cin >> n >> m >> k ; + int val = (n + m - 1) / m ; + int rem = n - val ; + if(rem <= k) no + else yes + return true ; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t ; + cin >> t ; + //int count = 1 ; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++ ; + }else{ + // no + } + } + return 0 ; +} + + diff --git a/CodeForces_Live_Contest/Educational_Round/164_Div_2/2.bin b/CodeForces_Live_Contest/Educational_Round/164_Div_2/2.bin new file mode 100644 index 0000000..8d375e9 Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/164_Div_2/2.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/164_Div_2/2.cpp b/CodeForces_Live_Contest/Educational_Round/164_Div_2/2.cpp new file mode 100644 index 0000000..a8e9be7 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/164_Div_2/2.cpp @@ -0,0 +1,117 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize(3, "Ofast", "inline") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +// Policy based data structures(PBDS) C++ STL +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// order_of_key(k): returns count of elements strictly smaller than k +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +template using Tree_SET = tree< T , null_type , less, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_SET > s; for pairs +template using Tree_MULTISET = tree< T , null_type , less_equal, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_MULTISET > s; for pairs + +#define nl "\n" +#define ll long long // typedef array p ; pair h ye +#define int ll +#define yes cout << "YES" << nl ; +#define no cout << "NO" << nl ; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< 0){if(y&1) res = (res * (long long)x) % MOD; y = y >> 1; x = ((long long)x * (long long)x) % MOD ;}return res ;} +int mod_ADDITION(int a, int b, int m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} +int mod_SUBTRACTION(int a, int b, int m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} +int mod_MULTIPLICATION(int a, int b, int m) {a = a % m; b = b % m; return ((((long long)a * (long long)b) % m) + m) % m;} +int mod_DIVISION(int a, int b, int m){a %= m , b %= m; return mod_MULTIPLICATION(a , modpower(b , m - 2 , MOD) , m);} +long long power(long long x, long long y){long long res = 1 ; while(y > 0) {if(y & 1) res = (res * (long long)x) ; x = ((long long)x * (long long)x) ; y = y >> 1 ;} return res ;} +int modinv(int x){return modpower(x , MOD - 2 , MOD) ;} +bool comparatorfunction(pair &a, pair &b){if(a.F != b.F){return a.F < b.F ;}return a.S > b.S ;} + +bool solve(){ + int n ; + cin >> n ; + vector a(n) ; + for(int i = 0 ; i < n ; ++i){ + cin >> a[i] ; + } + if(n == 1){ + cout << -1 << nl ; + return true ; + } + if(n == 2){ + if(a[0] == a[1]) cout << -1 << nl ; + else cout << 0 << nl ; + return true ; + } + map mp ; + for(auto &i : a) mp[i] += 1 ; + int mx = 0 ; + for(auto &i : mp) mx=max(mx,i.S) ; + int ele = -1 ; + for(auto &i : mp){ + if(mx == i.S){ + ele = i.F ; + } + } + vectoridx; + idx.pb(0); + for(int i=0;i> t ; + //int count = 1 ; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++ ; + }else{ + // no + } + } + return 0 ; +} + + diff --git a/CodeForces_Live_Contest/Educational_Round/164_Div_2/3.bin b/CodeForces_Live_Contest/Educational_Round/164_Div_2/3.bin new file mode 100644 index 0000000..f04f863 Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/164_Div_2/3.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/164_Div_2/3.cpp b/CodeForces_Live_Contest/Educational_Round/164_Div_2/3.cpp new file mode 100644 index 0000000..45886c4 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/164_Div_2/3.cpp @@ -0,0 +1,98 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize(3, "Ofast", "inline") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +// Policy based data structures(PBDS) C++ STL +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// order_of_key(k): returns count of elements strictly smaller than k +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +template using Tree_SET = tree< T , null_type , less, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_SET > s; for pairs +template using Tree_MULTISET = tree< T , null_type , less_equal, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_MULTISET > s; for pairs + +#define nl "\n" +#define ll long long // typedef array p ; pair h ye +#define int ll +#define yes cout << "YES" << nl ; +#define no cout << "NO" << nl ; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< 0){if(y&1) res = (res * (long long)x) % MOD; y = y >> 1; x = ((long long)x * (long long)x) % MOD ;}return res ;} +int mod_ADDITION(int a, int b, int m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} +int mod_SUBTRACTION(int a, int b, int m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} +int mod_MULTIPLICATION(int a, int b, int m) {a = a % m; b = b % m; return ((((long long)a * (long long)b) % m) + m) % m;} +int mod_DIVISION(int a, int b, int m){a %= m , b %= m; return mod_MULTIPLICATION(a , modpower(b , m - 2 , MOD) , m);} +long long power(long long x, long long y){long long res = 1 ; while(y > 0) {if(y & 1) res = (res * (long long)x) ; x = ((long long)x * (long long)x) ; y = y >> 1 ;} return res ;} +int modinv(int x){return modpower(x , MOD - 2 , MOD) ;} +bool comparatorfunction(pair &a, pair &b){if(a.F != b.F){return a.F < b.F ;}return a.S > b.S ;} + +bool solve(){ + string x; + cin>>x; + string y; + cin>>y; + int n=x.size(); + if(x < y) swap(x , y) ; + int idx = n ; + for(int i = 0 ; i < n ; ++i){ + if(x[i] > y[i]){ + idx = i + 1 ; + break ; + } + } + for(int i = idx ; i < n ; ++i){ + if(x[i] > y[i]){ + swap(x[i],y[i]); + } + } + cout << x<> t ; + //int count = 1 ; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++ ; + }else{ + // no + } + } + return 0 ; +} + + diff --git a/CodeForces_Live_Contest/Educational_Round/164_Div_2/4.cpp b/CodeForces_Live_Contest/Educational_Round/164_Div_2/4.cpp new file mode 100644 index 0000000..e69de29 diff --git a/CodeForces_Live_Contest/Educational_Round/165_Div_2/.cph/.1.cpp_6e8556b3a048fa9e63e82c67e1fc49ec.prob b/CodeForces_Live_Contest/Educational_Round/165_Div_2/.cph/.1.cpp_6e8556b3a048fa9e63e82c67e1fc49ec.prob new file mode 100644 index 0000000..3c8373e --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/165_Div_2/.cph/.1.cpp_6e8556b3a048fa9e63e82c67e1fc49ec.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\165_Div_2\\1.cpp","tests":[{"id":1714401483382,"input":"3\n5\n3 1 2 5 4\n4\n2 3 4 1\n2\n2 1\n","output":"2\n3\n2\n"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\165_Div_2\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/165_Div_2/.cph/.2.cpp_a87f889cf22f0f38839d93d78341093a.prob b/CodeForces_Live_Contest/Educational_Round/165_Div_2/.cph/.2.cpp_a87f889cf22f0f38839d93d78341093a.prob new file mode 100644 index 0000000..3d7e2ac --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/165_Div_2/.cph/.2.cpp_a87f889cf22f0f38839d93d78341093a.prob @@ -0,0 +1 @@ +{"name":"Local: 2","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\165_Div_2\\2.cpp","tests":[{"id":1714401855074,"input":"5\n10\n0000\n11000\n101011\n01101001\n","output":"2\n0\n9\n5\n11\n"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\165_Div_2\\2.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/165_Div_2/.cph/.3.cpp_5c17174700ed2bf77760a21ccd10beaf.prob b/CodeForces_Live_Contest/Educational_Round/165_Div_2/.cph/.3.cpp_5c17174700ed2bf77760a21ccd10beaf.prob new file mode 100644 index 0000000..dad1432 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/165_Div_2/.cph/.3.cpp_5c17174700ed2bf77760a21ccd10beaf.prob @@ -0,0 +1 @@ +{"name":"Local: 3","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\165_Div_2\\3.cpp","tests":[{"id":1714403070536,"input":"4\n3 1\n3 1 2\n1 3\n5\n4 2\n2 2 1 3\n6 3\n4 1 2 2 4 3\n","output":"4\n5\n5\n10\n"},{"id":1714403959766,"input":"4\n2 1\n3 1\n1 0\n5\n4 0\n2 2 1 3\n6 2\n4 1 2 4 3 2","output":"2\n5\n8\n11"},{"id":1714404735972,"input":"1\n160 1\n1 1 7 1 1 1 1 1 1 1 1 1 1 7 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 1 1 1 1 1 7 1 1 1 7 1 1 7 1 1 7 1 1 7 1 1 1 7 1 1 1 7 1 1 7 1 1 1 7 1 1 1 7 1 7 1 1 1 7 1 1 7 1 1 1 1 1 7 1 1 1 1 1 1 1 1 1 1 7 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 1 1 1 1 1 7 1 1 1 7 1 1 7 1 1 7 1 1 7 1 1 1 7 1 1 1 7 1 1 7 1 1 1 7 1 1 1 7 1 7 1 1 1 7 1 1 7 1 1 1","output":"346"},{"id":1714404870049,"input":"1\n1 0 \n1","output":"1"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\165_Div_2\\3.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/165_Div_2/.cph/.4.cpp_947f8369ab3dc8816e56444511fd6edc.prob b/CodeForces_Live_Contest/Educational_Round/165_Div_2/.cph/.4.cpp_947f8369ab3dc8816e56444511fd6edc.prob new file mode 100644 index 0000000..8ead705 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/165_Div_2/.cph/.4.cpp_947f8369ab3dc8816e56444511fd6edc.prob @@ -0,0 +1 @@ +{"name":"Local: 4","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\165_Div_2\\4.cpp","tests":[{"id":1714429772202,"input":"4\n2 0\n2 1\n1 2\n4 1\n1 2 1 4\n3 3 2 3\n4 2\n2 1 1 1\n4 2 3 2\n6 2\n1 3 4 9 1 3\n7 6 8 10 6 8","output":"1\n1\n0\n7"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\165_Div_2\\4.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/165_Div_2/1.bin b/CodeForces_Live_Contest/Educational_Round/165_Div_2/1.bin new file mode 100644 index 0000000..44d5795 Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/165_Div_2/1.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/165_Div_2/1.cpp b/CodeForces_Live_Contest/Educational_Round/165_Div_2/1.cpp new file mode 100644 index 0000000..33e870c --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/165_Div_2/1.cpp @@ -0,0 +1,97 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize(3, "Ofast", "inline") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +// Policy based data structures(PBDS) C++ STL +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// order_of_key(k): returns count of elements strictly smaller than k +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +template using Tree_SET = tree< T , null_type , less, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_SET > s; for pairs +template using Tree_MULTISET = tree< T , null_type , less_equal, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_MULTISET > s; for pairs + +#define nl "\n" +#define ll long long // typedef array p ; pair h ye +#define int ll +#define yes cout << "YES" << nl ; +#define no cout << "NO" << nl ; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< 0){if(y&1) res = (res * (long long)x) % MOD; y = y >> 1; x = ((long long)x * (long long)x) % MOD ;}return res ;} +int mod_ADDITION(int a, int b, int m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} +int mod_SUBTRACTION(int a, int b, int m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} +int mod_MULTIPLICATION(int a, int b, int m) {a = a % m; b = b % m; return ((((long long)a * (long long)b) % m) + m) % m;} +int mod_DIVISION(int a, int b, int m){a %= m , b %= m; return mod_MULTIPLICATION(a , modpower(b , m - 2 , MOD) , m);} +long long power(long long x, long long y){long long res = 1 ; while(y > 0) {if(y & 1) res = (res * (long long)x) ; x = ((long long)x * (long long)x) ; y = y >> 1 ;} return res ;} +int modinv(int x){return modpower(x , MOD - 2 , MOD) ;} +bool comparatorfunction(pair &a, pair &b){if(a.F != b.F){return a.F < b.F ;}return a.S > b.S ;} + +bool solve(){ + int n; + cin>>n; + vectora(n); + vectorans(n); + for(int i=0;i>a[i]; + a[i] -= 1; + ans[a[i]]=i; + } + // check1(a) + // check1(ans) + int val=3; + for(int i=0;i> t ; + //int count = 1 ; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++ ; + }else{ + // no + } + } + return 0 ; +} + + diff --git a/CodeForces_Live_Contest/Educational_Round/165_Div_2/2.bin b/CodeForces_Live_Contest/Educational_Round/165_Div_2/2.bin new file mode 100644 index 0000000..fa33a76 Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/165_Div_2/2.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/165_Div_2/2.cpp b/CodeForces_Live_Contest/Educational_Round/165_Div_2/2.cpp new file mode 100644 index 0000000..f2ce739 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/165_Div_2/2.cpp @@ -0,0 +1,92 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize(3, "Ofast", "inline") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +// Policy based data structures(PBDS) C++ STL +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// order_of_key(k): returns count of elements strictly smaller than k +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +template using Tree_SET = tree< T , null_type , less, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_SET > s; for pairs +template using Tree_MULTISET = tree< T , null_type , less_equal, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_MULTISET > s; for pairs + +#define nl "\n" +#define ll long long // typedef array p ; pair h ye +#define int ll +#define yes cout << "YES" << nl ; +#define no cout << "NO" << nl ; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< 0){if(y&1) res = (res * (long long)x) % MOD; y = y >> 1; x = ((long long)x * (long long)x) % MOD ;}return res ;} +int mod_ADDITION(int a, int b, int m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} +int mod_SUBTRACTION(int a, int b, int m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} +int mod_MULTIPLICATION(int a, int b, int m) {a = a % m; b = b % m; return ((((long long)a * (long long)b) % m) + m) % m;} +int mod_DIVISION(int a, int b, int m){a %= m , b %= m; return mod_MULTIPLICATION(a , modpower(b , m - 2 , MOD) , m);} +long long power(long long x, long long y){long long res = 1 ; while(y > 0) {if(y & 1) res = (res * (long long)x) ; x = ((long long)x * (long long)x) ; y = y >> 1 ;} return res ;} +int modinv(int x){return modpower(x , MOD - 2 , MOD) ;} +bool comparatorfunction(pair &a, pair &b){if(a.F != b.F){return a.F < b.F ;}return a.S > b.S ;} + +bool solve(){ + string s; + cin>>s; + int n=s.size(); + int cnt=0; + int ans=0; + for(int i=0;i 0){ + ans += (cnt+1); + } + } + } + cout<> t ; + //int count = 1 ; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++ ; + }else{ + // no + } + } + return 0 ; +} + + diff --git a/CodeForces_Live_Contest/Educational_Round/165_Div_2/3.bin b/CodeForces_Live_Contest/Educational_Round/165_Div_2/3.bin new file mode 100644 index 0000000..948d2da Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/165_Div_2/3.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/165_Div_2/3.cpp b/CodeForces_Live_Contest/Educational_Round/165_Div_2/3.cpp new file mode 100644 index 0000000..2d8f3e7 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/165_Div_2/3.cpp @@ -0,0 +1,126 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize(3, "Ofast", "inline") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +// Policy based data structures(PBDS) C++ STL +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// order_of_key(k): returns count of elements strictly smaller than k +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +template using Tree_SET = tree< T , null_type , less, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_SET > s; for pairs +template using Tree_MULTISET = tree< T , null_type , less_equal, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_MULTISET > s; for pairs + +#define nl "\n" +#define ll long long // typedef array p ; pair h ye +#define int ll +#define yes cout << "YES" << nl ; +#define no cout << "NO" << nl ; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< 0){if(y&1) res = (res * (long long)x) % MOD; y = y >> 1; x = ((long long)x * (long long)x) % MOD ;}return res ;} +int mod_ADDITION(int a, int b, int m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} +int mod_SUBTRACTION(int a, int b, int m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} +int mod_MULTIPLICATION(int a, int b, int m) {a = a % m; b = b % m; return ((((long long)a * (long long)b) % m) + m) % m;} +int mod_DIVISION(int a, int b, int m){a %= m , b %= m; return mod_MULTIPLICATION(a , modpower(b , m - 2 , MOD) , m);} +long long power(long long x, long long y){long long res = 1 ; while(y > 0) {if(y & 1) res = (res * (long long)x) ; x = ((long long)x * (long long)x) ; y = y >> 1 ;} return res ;} +int modinv(int x){return modpower(x , MOD - 2 , MOD) ;} +bool comparatorfunction(pair &a, pair &b){if(a.F != b.F){return a.F < b.F ;}return a.S > b.S ;} + +int n,k; +vectora; +vector>dp; + +int rec(int i,int taken){ + if(i >= n) return 0; + if(dp[i][taken] != -1) { + return dp[i][taken]; + } + int ans=0; + if(i == 0){ + if(i < n - 1 and taken < k){ + ans += min(a[i + 1] + rec(i + 1 , taken + 1) , a[i] + rec(i + 1 , taken)) ; + } + else{ + ans += a[i] + rec(i + 1 , taken) ; + } + } + else{ + if(i < n - 1){ + if(taken < k){ + ans += min({a[i + 1] + rec(i + 1 , taken + 1) , a[i] + rec(i + 1 , taken), + a[i - 1] + rec(i - 1 , taken + 1)}) ; + } + else{ + ans += a[i] + rec(i + 1 , taken) ; + } + } + else{ + if(taken < k){ + ans += min({a[i] + rec(i + 1 , taken), a[i - 1] + rec(i - 1 , taken + 1)}) ; + } + else{ + ans += a[i] + rec(i + 1 , taken); + } + } + } + return dp[i][taken]=ans; +} + + +bool solve(){ + cin>>n>>k; + a=vector(n); + for(int i=0;i>a[i]; + } + dp=vector>(n+1,vector(k+1,-1)); + int ans=rec(0,0); + cout<> t ; + //int count = 1 ; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++ ; + }else{ + // no + } + } + return 0 ; +} + diff --git a/CodeForces_Live_Contest/Educational_Round/165_Div_2/4.bin b/CodeForces_Live_Contest/Educational_Round/165_Div_2/4.bin new file mode 100644 index 0000000..a9939e1 Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/165_Div_2/4.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/165_Div_2/4.cpp b/CodeForces_Live_Contest/Educational_Round/165_Div_2/4.cpp new file mode 100644 index 0000000..ff35323 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/165_Div_2/4.cpp @@ -0,0 +1,128 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize(3, "Ofast", "inline") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +// Policy based data structures(PBDS) C++ STL +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// order_of_key(k): returns count of elements strictly smaller than k +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +template using Tree_SET = tree< T , null_type , less, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_SET > s; for pairs +template using Tree_MULTISET = tree< T , null_type , less_equal, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_MULTISET > s; for pairs + +#define nl "\n" +#define ll long long // typedef array p ; pair h ye +#define int ll +#define yes cout << "YES" << nl ; +#define no cout << "NO" << nl ; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< 0){if(y&1) res = (res * (long long)x) % MOD; y = y >> 1; x = ((long long)x * (long long)x) % MOD ;}return res ;} +int mod_ADDITION(int a, int b, int m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} +int mod_SUBTRACTION(int a, int b, int m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} +int mod_MULTIPLICATION(int a, int b, int m) {a = a % m; b = b % m; return ((((long long)a * (long long)b) % m) + m) % m;} +int mod_DIVISION(int a, int b, int m){a %= m , b %= m; return mod_MULTIPLICATION(a , modpower(b , m - 2 , MOD) , m);} +long long power(long long x, long long y){long long res = 1 ; while(y > 0) {if(y & 1) res = (res * (long long)x) ; x = ((long long)x * (long long)x) ; y = y >> 1 ;} return res ;} +int modinv(int x){return modpower(x , MOD - 2 , MOD) ;} +bool comparatorfunction(pair &a, pair &b){if(a.F != b.F){return a.F > b.F ;}return a.S < b.S ;} + +bool solve(){ + int n,k; + cin>>n>>k; + vectora(n); + vectorb(n); + for(int i=0;i>a[i]; + } + for(int i=0;i>b[i]; + } + vector>p; + for(int i=0;ia[i]){ + p.pb({a[i],b[i]}); + } + } + sort(all(p)); + int sum_b=0; + int sum_a=0; + Tree_MULTISET pbds; + int ans=0; + // check2(p) + for(int i=0;i= pbds.size()+1){ + pbds.insert(p[i].S); + } + else{ + int rem = pbds.size() - pbds.order_of_key(p[i].S); + if(rem >= k){ + sum_b += p[i].S; + } + else{ + rem = pbds.size()-k; + sum_b += *(pbds.find_by_order(rem)); + } + pbds.insert(p[i].S); + } + } + ans=max(ans,sum_b-sum_a); + } + cout <> t ; + //int count = 1 ; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++ ; + }else{ + // no + } + } + return 0 ; +} + + diff --git a/CodeForces_Live_Contest/Educational_Round/166_Div_2/.cph/.1.cpp_f83df5e56da6190924385122a4962c97.prob b/CodeForces_Live_Contest/Educational_Round/166_Div_2/.cph/.1.cpp_f83df5e56da6190924385122a4962c97.prob new file mode 100644 index 0000000..eb3aeba --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/166_Div_2/.cph/.1.cpp_f83df5e56da6190924385122a4962c97.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\166_Div_2\\1.cpp","tests":[{"id":1717079943393,"input":"5\n4\n12ac\n5\n123wa\n9\nallllmost\n5\nac123\n6\n011679\n","output":"YES\nNO\nYES\nNO\nYES\n"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\166_Div_2\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/166_Div_2/.cph/.2.cpp_c166125b54f4d16974c1dc66445e42b5.prob b/CodeForces_Live_Contest/Educational_Round/166_Div_2/.cph/.2.cpp_c166125b54f4d16974c1dc66445e42b5.prob new file mode 100644 index 0000000..471ebb1 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/166_Div_2/.cph/.2.cpp_c166125b54f4d16974c1dc66445e42b5.prob @@ -0,0 +1 @@ +{"name":"Local: 2","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\166_Div_2\\2.cpp","tests":[{"id":1717080431515,"input":"3\n1\n2\n1 3\n2\n3 3\n3 3 3\n4\n4 2 1 2\n2 1 5 2 3","output":"3\n1\n8"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\166_Div_2\\2.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/166_Div_2/.cph/.3.cpp_33a147b2a8539b5eb7ff0525052168d4.prob b/CodeForces_Live_Contest/Educational_Round/166_Div_2/.cph/.3.cpp_33a147b2a8539b5eb7ff0525052168d4.prob new file mode 100644 index 0000000..6ce79ea --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/166_Div_2/.cph/.3.cpp_33a147b2a8539b5eb7ff0525052168d4.prob @@ -0,0 +1 @@ +{"name":"Local: 3","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeforcesProblemSolving\\CodeForces_Live_Contest\\Educational_Round\\166_Div_2\\3.cpp","tests":[{"id":1719650169552,"input":"4\n1 0\n2 1\n1 2\n0 2\n4 5 5\n5 4 1\n1 2\n2 1 5 4\n5 2 3 1\n3 1\n4 3 3 4 1\n5 5 4 5 2\n","output":"1 2 \n5 6 9 \n8 11 11 12 \n13 13 13 12 15 "},{"id":1719658859368,"input":"1\n1 0\n1 3\n2 2","output":"3 1"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeforcesProblemSolving\\CodeForces_Live_Contest\\Educational_Round\\166_Div_2\\3.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/166_Div_2/.cph/.4.cpp_90ff7531684ac2d6f55b09d4f550b3e9.prob b/CodeForces_Live_Contest/Educational_Round/166_Div_2/.cph/.4.cpp_90ff7531684ac2d6f55b09d4f550b3e9.prob new file mode 100644 index 0000000..7dad293 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/166_Div_2/.cph/.4.cpp_90ff7531684ac2d6f55b09d4f550b3e9.prob @@ -0,0 +1 @@ +{"name":"Local: 4","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeforcesProblemSolving\\CodeForces_Live_Contest\\Educational_Round\\166_Div_2\\4.cpp","tests":[{"id":1719680772747,"input":"4\n(())\n()\n()()()\n(()())(())\n","output":"1\n0\n3\n13\n"},{"id":1719682276071,"input":"12\n()\n()()\n(())\n()()()\n(())()\n()(())\n(()())\n((()))\n()()()()\n(())()()\n()(())()\n(()())()","output":"0\n1\n1\n3\n3\n3\n4\n1\n6\n6\n6\n7"},{"id":1719682848084,"input":"1\n((()))","output":"1"},{"id":1719686157802,"input":"1\n((()))()","output":"2"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeforcesProblemSolving\\CodeForces_Live_Contest\\Educational_Round\\166_Div_2\\4.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/166_Div_2/1.bin b/CodeForces_Live_Contest/Educational_Round/166_Div_2/1.bin new file mode 100644 index 0000000..0642042 Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/166_Div_2/1.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/166_Div_2/1.cpp b/CodeForces_Live_Contest/Educational_Round/166_Div_2/1.cpp new file mode 100644 index 0000000..397c9c2 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/166_Div_2/1.cpp @@ -0,0 +1,110 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize(3, "Ofast", "inline") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +// Policy based data structures(PBDS) C++ STL +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// order_of_key(k): returns count of elements strictly smaller than k +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +template using pbds_SET = tree< T , null_type , less, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_SET > s; for pairs +template using pbds_MULTISET = tree< T , null_type , less_equal, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_MULTISET > s; for pairs + +#define nl "\n" +#define ll long long // typedef array p ; pair h ye +#define int ll +#define yes cout << "YES" << nl ; +#define no cout << "NO" << nl ; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< 0){if(y&1) res = (res * (long long)x) % MOD; y = y >> 1; x = ((long long)x * (long long)x) % MOD ;}return res ;} +int mod_ADDITION(int a, int b, int m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} +int mod_SUBTRACTION(int a, int b, int m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} +int mod_MULTIPLICATION(int a, int b, int m) {a = a % m; b = b % m; return ((((long long)a * (long long)b) % m) + m) % m;} +int mod_DIVISION(int a, int b, int m){a %= m , b %= m; return mod_MULTIPLICATION(a , modpower(b , m - 2 , MOD) , m);} +long long power(long long x, long long y){long long res = 1 ; while(y > 0) {if(y & 1) res = (res * (long long)x) ; x = ((long long)x * (long long)x) ; y = y >> 1 ;} return res ;} +int modinv(int x){return modpower(x , MOD - 2 , MOD) ;} +bool comparatorfunction(pair &a, pair &b){if(a.F != b.F){return a.F < b.F ;}return a.S > b.S ;} + +bool solve(){ + int n; + cin>>n; + string s; + cin>>s; + int f=0; + for(int i=0;i='a' and c<='z'){ + f=1; + } + else{ + if(f){ + no + return true; + } + } + } + vectord,ch; + for(int i=0;i='a' and c<='z'){ + ch.pb(c); + } + else{ + d.pb(c); + } + } + vectordd=d,chch=ch; + sort(all(dd)); + sort(all(chch)); + if(dd==d and chch==ch) yes + else no + return true ; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t ; + cin >> t ; + //int count = 1 ; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++ ; + }else{ + // no + } + } + return 0 ; +} + + diff --git a/CodeForces_Live_Contest/Educational_Round/166_Div_2/2.bin b/CodeForces_Live_Contest/Educational_Round/166_Div_2/2.bin new file mode 100644 index 0000000..201443c Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/166_Div_2/2.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/166_Div_2/2.cpp b/CodeForces_Live_Contest/Educational_Round/166_Div_2/2.cpp new file mode 100644 index 0000000..35da971 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/166_Div_2/2.cpp @@ -0,0 +1,104 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize(3, "Ofast", "inline") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +// Policy based data structures(PBDS) C++ STL +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// order_of_key(k): returns count of elements strictly smaller than k +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +template using pbds_SET = tree< T , null_type , less, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_SET > s; for pairs +template using pbds_MULTISET = tree< T , null_type , less_equal, rb_tree_tag, tree_order_statistics_node_update > ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree_MULTISET > s; for pairs + +#define nl "\n" +#define ll long long // typedef array p ; pair h ye +#define int ll +#define yes cout << "YES" << nl ; +#define no cout << "NO" << nl ; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< 0){if(y&1) res = (res * (long long)x) % MOD; y = y >> 1; x = ((long long)x * (long long)x) % MOD ;}return res ;} +int mod_ADDITION(int a, int b, int m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} +int mod_SUBTRACTION(int a, int b, int m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} +int mod_MULTIPLICATION(int a, int b, int m) {a = a % m; b = b % m; return ((((long long)a * (long long)b) % m) + m) % m;} +int mod_DIVISION(int a, int b, int m){a %= m , b %= m; return mod_MULTIPLICATION(a , modpower(b , m - 2 , MOD) , m);} +long long power(long long x, long long y){long long res = 1 ; while(y > 0) {if(y & 1) res = (res * (long long)x) ; x = ((long long)x * (long long)x) ; y = y >> 1 ;} return res ;} +int modinv(int x){return modpower(x , MOD - 2 , MOD) ;} +bool comparatorfunction(pair &a, pair &b){if(a.F != b.F){return a.F < b.F ;}return a.S > b.S ;} + +bool solve(){ + int n; + cin>>n; + vectora(n),b(n+1); + for(int i=0;i>a[i]; + } + for(int i=0;i>b[i]; + } + int last=b[n]; + int mn=inf; + for(int i=0;i=b[i] || last<=b[i] and last>=a[i]){ + mn=0; + } + else{ + mn=min(mn,abs(last-a[i])); + mn=min(mn,abs(last-b[i])); + } + } + int ans=0; + for(int i=0;i> t ; + //int count = 1 ; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++ ; + }else{ + // no + } + } + return 0 ; +} + + diff --git a/CodeForces_Live_Contest/Educational_Round/166_Div_2/3.bin b/CodeForces_Live_Contest/Educational_Round/166_Div_2/3.bin new file mode 100644 index 0000000..44bb3cb Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/166_Div_2/3.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/166_Div_2/3.cpp b/CodeForces_Live_Contest/Educational_Round/166_Div_2/3.cpp new file mode 100644 index 0000000..d54a4b1 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/166_Div_2/3.cpp @@ -0,0 +1,206 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize(3, "Ofast", "inline") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +const int MOD = 1000000007 ; // 998244353 +const long long inf = 1000000000000000000LL; // 18 zero's // LLONG_MAX = 9223372036854775807 - 19 digits +#define int long long + +int GCD(int a, int b){if(b == 0){return a;} return GCD(b, a % b);} // Euclidean algorithm for computing the greatest common divisor +int LCM(int a, int b){return ((long long)a / (long long)GCD(a, b) * (long long)b) ;} +int modpower(int x, int y, int m){long long res = 1; x = x % m; while(y > 0){if(y&1) res = (res * (long long)x) % MOD; y = y >> 1; x = ((long long)x * (long long)x) % MOD ;}return res ;} +int mod_ADDITION(int a, int b, int m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} +int mod_SUBTRACTION(int a, int b, int m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} +int mod_MULTIPLICATION(int a, int b, int m) {a = a % m; b = b % m; return ((((long long)a * (long long)b) % m) + m) % m;} +int mod_DIVISION(int a, int b, int m){a %= m , b %= m; return mod_MULTIPLICATION(a , modpower(b , m - 2 , MOD) , m);} +long long power(long long x, long long y){long long res = 1 ; while(y > 0) {if(y & 1) res = (res * (long long)x) ; x = ((long long)x * (long long)x) ; y = y >> 1 ;} return res ;} +int modinv(int x){return modpower(x , MOD - 2 , MOD) ;} +bool comparatorfunction(pair &a, pair &b){if(a.first != b.first){return a.first < b.first ;}return a.second > b.second ;} + +bool solve(){ + int n,m; + cin>>n>>m; + vectora(n+m+1); + vectorb(n+m+1); + for(int i=0;i>a[i]; + } + for(int i=0;i>b[i]; + } + setpro_shi,pro_galat; + settest_shi,test_galat; + int pro=n; + int test=m; + int sum=0; + for(int i=1;ib[i]){ + if(pro>0){ + pro-=1; + sum+=a[i]; + pro_shi.insert(i); + } + else{ + test-=1; + sum+=b[i]; + test_galat.insert(i); + } + } + else{ + if(test>0){ + test-=1; + sum+=b[i]; + test_shi.insert(i); + } + else{ + pro-=1; + sum+=a[i]; + pro_galat.insert(i); + } + } + } + pro=0; + test=0; + cout<b[i]){ + if(a[i-1]>b[i-1]){ + if(pro0){ + pro_shi.insert(*(test_galat.begin())); + sum+=a[*(test_galat.begin())]; + sum-=b[*(test_galat.begin())]; + test_galat.erase(test_galat.begin()); + } + else if(test_shi.size()>0){ + pro_galat.insert(*prev(test_shi.end())); + sum+=a[*prev(test_shi.end())]; + sum-=b[*prev(test_shi.end())]; + test_shi.erase(prev(test_shi.end())); + } + } + else{ + sum-=b[i]; + } + } + else{ + pro+=1; + sum+=a[i-1]; + sum-=a[i]; + } + } + } + else{ + if(b[i-1]>a[i-1]){ + if(test0){ + test_shi.insert(*(pro_galat.begin())); + sum+=b[*(pro_galat.begin())]; + sum-=a[*(pro_galat.begin())]; + pro_galat.erase(pro_galat.begin()); + } + else if(pro_shi.size()>0){ + test_galat.insert(*prev(pro_shi.end())); + sum+=b[*prev(pro_shi.end())]; + sum-=a[*prev(pro_shi.end())]; + pro_shi.erase(prev(pro_shi.end())); + } + } + else{ + sum-=a[i]; + } + } + else{ + test+=1; + sum+=b[i-1]; + sum-=b[i]; + } + } + } + while(test_galat.size()>0 and *(test_galat.begin())<=i) test_galat.erase(test_galat.begin()); + while(pro_galat.size()>0 and *(pro_galat.begin())<=i) pro_galat.erase(pro_galat.begin()); + while(test_shi.size()>0 and *(test_shi.begin())<=i) test_shi.erase(test_shi.begin()); + while(pro_shi.size()>0 and *(pro_shi.begin())<=i) pro_shi.erase(pro_shi.begin()); + cout<> t ; + int count = 1 ; + while (t--){ + //cout << "Case #" << count << ": "; + // if(count==868){ + // int n,m; + // cin>>n>>m; + // vectora(n+m+1); + // vectorb(n+m+1); + // cout<>a[i]; + // cout<>b[i]; + // cout< +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize(3, "Ofast", "inline") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +const int MOD = 1000000007 ; // 998244353 +const long long inf = 1000000000000000000LL; // 18 zero's // LLONG_MAX = 9223372036854775807 - 19 digits +#define int long long + +int GCD(int a, int b){if(b == 0){return a;} return GCD(b, a % b);} // Euclidean algorithm for computing the greatest common divisor +int LCM(int a, int b){return ((long long)a / (long long)GCD(a, b) * (long long)b) ;} +int modpower(int x, int y, int m){long long res = 1; x = x % m; while(y > 0){if(y&1) res = (res * (long long)x) % MOD; y = y >> 1; x = ((long long)x * (long long)x) % MOD ;}return res ;} +int mod_ADDITION(int a, int b, int m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} +int mod_SUBTRACTION(int a, int b, int m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} +int mod_MULTIPLICATION(int a, int b, int m) {a = a % m; b = b % m; return ((((long long)a * (long long)b) % m) + m) % m;} +int mod_DIVISION(int a, int b, int m){a %= m , b %= m; return mod_MULTIPLICATION(a , modpower(b , m - 2 , MOD) , m);} +long long power(long long x, long long y){long long res = 1 ; while(y > 0) {if(y & 1) res = (res * (long long)x) ; x = ((long long)x * (long long)x) ; y = y >> 1 ;} return res ;} +int modinv(int x){return modpower(x , MOD - 2 , MOD) ;} +bool comparatorfunction(pair &a, pair &b){if(a.first != b.first){return a.first < b.first ;}return a.second > b.second ;} + + +/* + +How to define our segment tree in the main function +vector arr = {1 , 2 , 3 , 4} ; + +SGT st(n , arr); + +*/ + +struct SGT { + struct Node { + int val ; // may change + Node() { // Identity element + val = 0 ; // may change // warning it is for query answers only what should be the output answer + // val = power(2 , 30) - 1 ; // may change + // val = INF ; // may change + // val = -INF ; // may change + } + Node(int p1) { // Actual Node + val = p1 ; // may change + } + void merge(Node &l , Node &r) { // Merge two child nodes + val = max(l.val , r.val) ; // may change + } + }; + struct Update { // note if mentioned about update then only it is used + int val ; // may change + Update(int p1) { // Actual Update + val = p1 ; // may change + } + void apply(Node &a) { // apply update to given node + a.val = val ; // may change + } + }; + + vector tree ; // it will change according to the node + vector arr ; // type may change + int n , s ; + int sz ; // 2^k where k is the least integer which satisfy 2^k >= n + SGT(int array_len, vector &a) { // change if type updated + arr = a ; + n = array_len ; + s = 1 ; + while(s < 2 * n) { + s = (s << 1); + } + tree.resize(s); + fill(tree.begin(),tree.end(), Node()) ; + build(1 , 0 , n - 1) ; + } + void build(int index, int start, int end) // Never change this + { + if(start == end){ + tree[index] = Node(arr[start]) ; // may change + return ; + } + int mid = (start + end) / 2 ; + build(2 * index, start, mid) ; + build(2 * index + 1, mid + 1, end) ; + tree[index].merge(tree[2 * index] , tree[2 * index + 1]) ; + } + void update( int index, int start, int end, int query_index, Update &u) // Never Change this + { + if(start == end){ + u.apply(tree[index]) ; + return ; + } + int mid = (start + end) / 2 ; + if(mid >= query_index) + update(2 * index, start, mid, query_index, u); + else + update(2 * index + 1, mid + 1, end, query_index, u) ; + tree[index].merge(tree[2 * index], tree[2 * index + 1]) ; + } + Node query(int index, int start, int end, int left, int right) { // may change + if(start > right || end < left) // may change // both if statements can be removed + return Node() ; + if(start >= left && end <= right) // may change // both if statements can be removed + return tree[index] ; + int mid = (start + end) / 2 ; + Node l , r , ans ; + l = query(2 * index , start , mid , left, right) ; + r = query(2 * index + 1 , mid + 1 , end , left , right) ; + ans.merge(l , r) ; + return ans ; + } + void make_update(int index, int val) { // pass in as many parameters as required + Update new_update = Update(val); // may change + update(1 , 0 , n - 1 , index , new_update) ; + } + Node make_query(int left , int right) { // may change + return query(1 , 0 , n - 1 , left , right) ; // may change + } + int first(){ + return tree[1].val ; + } + void output(){ + for(int i = 1 ; i < s ; ++i){ + cout << tree[i].val << " " ; + } + cout << "\n" ; + } +}; + +bool solve(){ + string s; + cin>>s; + int n=s.size(); + vectorpf(n,0); + int sum=0; + map>mp; + for(int i=0;iv; + if(mp[sum].size()>0){ + for(auto &j:mp[sum]){ + v.push_back(j); + } + } + int len=v.size(); + cout<1 and len>0){ + int mid=(high+low)/2; + int idx=v[mid]; + int f=0; + int val1=pf[idx]; + // cout<val1)) f=1; + if(f>0){ + low=mid; + } + else{ + high=mid; + } + } + cout<> t ; + //int count = 1 ; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++ ; + }else{ + // no + } + } + return 0 ; +} + + diff --git a/CodeForces_Live_Contest/Educational_Round/167_Div_2/.cph/.1.cpp_96985a29fff59d875ffca746c29265d4.prob b/CodeForces_Live_Contest/Educational_Round/167_Div_2/.cph/.1.cpp_96985a29fff59d875ffca746c29265d4.prob new file mode 100644 index 0000000..7533572 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/167_Div_2/.cph/.1.cpp_96985a29fff59d875ffca746c29265d4.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\167_Div_2\\1.cpp","tests":[{"id":1719498447263,"input":"5\n24 42\n-2 -1\n-1 -2\n0 -50\n15 0\n","output":""}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\167_Div_2\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/167_Div_2/.cph/.2.cpp_2d516da41e518d71d228c491a24339d4.prob b/CodeForces_Live_Contest/Educational_Round/167_Div_2/.cph/.2.cpp_2d516da41e518d71d228c491a24339d4.prob new file mode 100644 index 0000000..dd3311d --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/167_Div_2/.cph/.2.cpp_2d516da41e518d71d228c491a24339d4.prob @@ -0,0 +1 @@ +{"name":"Local: 2","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\167_Div_2\\2.cpp","tests":[{"id":1719499633673,"input":"5\naba\ncb\ner\ncf\nmmm\nmmm\ncontest\ntest\ncde\nabcefg\n","output":"4\n4\n3\n7\n7\n"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\167_Div_2\\2.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/167_Div_2/.cph/.3.cpp_c364975de16488f4a84a20a62a739600.prob b/CodeForces_Live_Contest/Educational_Round/167_Div_2/.cph/.3.cpp_c364975de16488f4a84a20a62a739600.prob new file mode 100644 index 0000000..f1cd867 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/167_Div_2/.cph/.3.cpp_c364975de16488f4a84a20a62a739600.prob @@ -0,0 +1 @@ +{"name":"Local: 3","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\167_Div_2\\3.cpp","tests":[{"id":1719501059751,"input":"4\n2\n-1 1\n-1 -1\n1\n-1\n-1\n5\n0 -1 1 0 1\n-1 1 0 0 1\n4\n-1 -1 -1 1\n-1 1 1 1\n","output":"0\n-1\n1\n1\n"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\167_Div_2\\3.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/167_Div_2/.cph/.4.cpp_b168380bd04005536388c9cb6d5c6678.prob b/CodeForces_Live_Contest/Educational_Round/167_Div_2/.cph/.4.cpp_b168380bd04005536388c9cb6d5c6678.prob new file mode 100644 index 0000000..d57ba14 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/167_Div_2/.cph/.4.cpp_b168380bd04005536388c9cb6d5c6678.prob @@ -0,0 +1 @@ +{"name":"Local: 4","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\167_Div_2\\4.cpp","tests":[{"id":1719504643152,"input":"5 3\n9 6 7 5 5\n8 4 5 1 2\n10 4 7\n","output":"12"},{"id":1719504646797,"input":"3 4\n10 20 20\n0 0 0\n9 10 19 20\n","output":"8"},{"id":1719504653155,"input":"1 5\n3\n1\n1000000000 1000000000 1000000000 1000000000 1000000000\n","output":"4999999990\n"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeForces_Live_Contest\\Educational_Round\\167_Div_2\\4.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/167_Div_2/1.bin b/CodeForces_Live_Contest/Educational_Round/167_Div_2/1.bin new file mode 100644 index 0000000..37bffc3 Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/167_Div_2/1.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/167_Div_2/1.cpp b/CodeForces_Live_Contest/Educational_Round/167_Div_2/1.cpp new file mode 100644 index 0000000..4032e41 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/167_Div_2/1.cpp @@ -0,0 +1,64 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize(3, "Ofast", "inline") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +const int MOD = 1000000007 ; // 998244353 +const long long inf = 1000000000000000000LL; // 18 zero's // LLONG_MAX = 9223372036854775807 - 19 digits +#define int long long + +int GCD(int a, int b){if(b == 0){return a;} return GCD(b, a % b);} // Euclidean algorithm for computing the greatest common divisor +int LCM(int a, int b){return (a / GCD(a, b) * b) ;} +int modpower(int x, int y, int m){long long res = 1; x = x % m; while(y > 0){if(y&1) res = (res * (long long)x) % MOD; y = y >> 1; x = ((long long)x * (long long)x) % MOD ;}return res ;} +int mod_ADDITION(int a, int b, int m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} +int mod_SUBTRACTION(int a, int b, int m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} +int mod_MULTIPLICATION(int a, int b, int m) {a = a % m; b = b % m; return ((((long long)a * (long long)b) % m) + m) % m;} +int mod_DIVISION(int a, int b, int m){a %= m , b %= m; return mod_MULTIPLICATION(a , modpower(b , m - 2 , MOD) , m);} +long long power(long long x, long long y){long long res = 1 ; while(y > 0) {if(y & 1) res = (res * (long long)x) ; x = ((long long)x * (long long)x) ; y = y >> 1 ;} return res ;} +int modinv(int x){return modpower(x , MOD - 2 , MOD) ;} +bool comparatorfunction(pair &a, pair &b){if(a.first != b.first){return a.first < b.first ;}return a.second > b.second ;} + +bool solve(){ + int n; + cin>>n; + for(int i=0;i>x>>y; + if(y+1>=0){ + cout<<"YES"< +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize(3, "Ofast", "inline") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +const int MOD = 1000000007 ; // 998244353 +const long long inf = 1000000000000000000LL; // 18 zero's // LLONG_MAX = 9223372036854775807 - 19 digits +#define int long long + +int GCD(int a, int b){if(b == 0){return a;} return GCD(b, a % b);} // Euclidean algorithm for computing the greatest common divisor +int LCM(int a, int b){return ((long long)a / (long long)GCD(a, b) * (long long)b) ;} +int modpower(int x, int y, int m){long long res = 1; x = x % m; while(y > 0){if(y&1) res = (res * (long long)x) % MOD; y = y >> 1; x = ((long long)x * (long long)x) % MOD ;}return res ;} +int mod_ADDITION(int a, int b, int m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} +int mod_SUBTRACTION(int a, int b, int m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} +int mod_MULTIPLICATION(int a, int b, int m) {a = a % m; b = b % m; return ((((long long)a * (long long)b) % m) + m) % m;} +int mod_DIVISION(int a, int b, int m){a %= m , b %= m; return mod_MULTIPLICATION(a , modpower(b , m - 2 , MOD) , m);} +long long power(long long x, long long y){long long res = 1 ; while(y > 0) {if(y & 1) res = (res * (long long)x) ; x = ((long long)x * (long long)x) ; y = y >> 1 ;} return res ;} +int modinv(int x){return modpower(x , MOD - 2 , MOD) ;} +bool comparatorfunction(pair &a, pair &b){if(a.first != b.first){return a.first < b.first ;}return a.second > b.second ;} + +bool solve(){ + string a; + cin>>a; + string b; + cin>>b; + int n=a.size(); + int m=b.size(); + int tot=0; + int mn=inf; + while(tot> t ; + //int count = 1 ; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++ ; + }else{ + // no + } + } + return 0 ; +} + + diff --git a/CodeForces_Live_Contest/Educational_Round/167_Div_2/3.bin b/CodeForces_Live_Contest/Educational_Round/167_Div_2/3.bin new file mode 100644 index 0000000..c511d6b Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/167_Div_2/3.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/167_Div_2/3.cpp b/CodeForces_Live_Contest/Educational_Round/167_Div_2/3.cpp new file mode 100644 index 0000000..0135dcf --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/167_Div_2/3.cpp @@ -0,0 +1,137 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize(3, "Ofast", "inline") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +const int MOD = 1000000007 ; // 998244353 +const long long inf = 1000000000000000000LL; // 18 zero's // LLONG_MAX = 9223372036854775807 - 19 digits +#define int long long + +int GCD(int a, int b){if(b == 0){return a;} return GCD(b, a % b);} // Euclidean algorithm for computing the greatest common divisor +int LCM(int a, int b){return ((long long)a / (long long)GCD(a, b) * (long long)b) ;} +int modpower(int x, int y, int m){long long res = 1; x = x % m; while(y > 0){if(y&1) res = (res * (long long)x) % MOD; y = y >> 1; x = ((long long)x * (long long)x) % MOD ;}return res ;} +int mod_ADDITION(int a, int b, int m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} +int mod_SUBTRACTION(int a, int b, int m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} +int mod_MULTIPLICATION(int a, int b, int m) {a = a % m; b = b % m; return ((((long long)a * (long long)b) % m) + m) % m;} +int mod_DIVISION(int a, int b, int m){a %= m , b %= m; return mod_MULTIPLICATION(a , modpower(b , m - 2 , MOD) , m);} +long long power(long long x, long long y){long long res = 1 ; while(y > 0) {if(y & 1) res = (res * (long long)x) ; x = ((long long)x * (long long)x) ; y = y >> 1 ;} return res ;} +int modinv(int x){return modpower(x , MOD - 2 , MOD) ;} +bool comparatorfunction(pair &a, pair &b){if(a.first != b.first){return a.first < b.first ;}return a.second > b.second ;} + +bool solve(){ + int n; + cin>>n; + vectora(n); + for(int i=0;i>a[i]; + } + vectorb(n); + for(int i=0;i>b[i]; + } + int equalone=0; + int equalminusone=0; + int suma=0; + int sumb=0; + for(int i=0;ib[i]){ + suma+=a[i]; + } + else{ + sumb+=b[i]; + } + } + } + if(suma>sumb){ + while(equalone>0 and sumb0){ + suma+=(equalone+1)/2; + sumb+=equalone/2; + } + } + else if(sumb>suma){ + while(equalone>0 and suma0){ + suma+=(equalone+1)/2; + sumb+=equalone/2; + } + } + else{ + if(equalone>0){ + suma+=(equalone+1)/2; + sumb+=equalone/2; + } + } + if(suma>sumb){ + while(equalminusone>0 and sumb0){ + suma-=(equalminusone+1)/2; + sumb-=equalminusone/2; + } + } + else if(sumb>suma){ + while(equalminusone>0 and suma0){ + suma-=(equalminusone+1)/2; + sumb-=equalminusone/2; + } + } + else{ + if(equalminusone>0){ + suma-=(equalminusone+1)/2; + sumb-=equalminusone/2; + } + } + cout<> t ; + //int count = 1 ; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++ ; + }else{ + // no + } + } + return 0 ; +} + + diff --git a/CodeForces_Live_Contest/Educational_Round/167_Div_2/4.bin b/CodeForces_Live_Contest/Educational_Round/167_Div_2/4.bin new file mode 100644 index 0000000..fce7bb9 Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/167_Div_2/4.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/167_Div_2/4.cpp b/CodeForces_Live_Contest/Educational_Round/167_Div_2/4.cpp new file mode 100644 index 0000000..254bb4a --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/167_Div_2/4.cpp @@ -0,0 +1,119 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize(3, "Ofast", "inline") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +const int MOD = 1000000007 ; // 998244353 +const long long inf = 1000000000000000000LL; // 18 zero's // LLONG_MAX = 9223372036854775807 - 19 digits +#define int long long + +int GCD(int a, int b){if(b == 0){return a;} return GCD(b, a % b);} // Euclidean algorithm for computing the greatest common divisor +int LCM(int a, int b){return ((long long)a / (long long)GCD(a, b) * (long long)b) ;} +int modpower(int x, int y, int m){long long res = 1; x = x % m; while(y > 0){if(y&1) res = (res * (long long)x) % MOD; y = y >> 1; x = ((long long)x * (long long)x) % MOD ;}return res ;} +int mod_ADDITION(int a, int b, int m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} +int mod_SUBTRACTION(int a, int b, int m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} +int mod_MULTIPLICATION(int a, int b, int m) {a = a % m; b = b % m; return ((((long long)a * (long long)b) % m) + m) % m;} +int mod_DIVISION(int a, int b, int m){a %= m , b %= m; return mod_MULTIPLICATION(a , modpower(b , m - 2 , MOD) , m);} +long long power(long long x, long long y){long long res = 1 ; while(y > 0) {if(y & 1) res = (res * (long long)x) ; x = ((long long)x * (long long)x) ; y = y >> 1 ;} return res ;} +int modinv(int x){return modpower(x , MOD - 2 , MOD) ;} +bool comparatorfunction(pair &a, pair &b){if(a.first != b.first){return a.first < b.first ;}return a.second > b.second ;} + +bool solve(){ + int n,m; + cin>>n>>m; + vectora(n),b(n); + for(int i=0;i>a[i]; + } + for(int i=0;i>b[i]; + } + vectorc(m); + for(int i=0;i>c[i]; + } + vector>p,pr; + for(int i=0;idone; + for(int i=0;i0){ + + } + else{ + done[dif]=1; + // cout<pq; + // for(int i=0;i0 and pq.top()>=num){ + // int ele=pq.top(); + // // cout<=p[j].first){ + int num=p[j].second; + int dif=p[j].first; + ans+=((cur-num)/dif+1)*2; + cur=num-dif+(cur-num)%dif; + } + } + cout<> t ; + //int count = 1 ; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++ ; + }else{ + // no + } + } + return 0 ; +} + + diff --git a/CodeForces_Live_Contest/Educational_Round/169_Div_2/.cph/.1.cpp_ce5f4cf0b84698e0e8f1ac3e2e53d9c2.prob b/CodeForces_Live_Contest/Educational_Round/169_Div_2/.cph/.1.cpp_ce5f4cf0b84698e0e8f1ac3e2e53d9c2.prob new file mode 100644 index 0000000..6528d7b --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/169_Div_2/.cph/.1.cpp_ce5f4cf0b84698e0e8f1ac3e2e53d9c2.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeforcesProblemSolving\\CodeForces_Live_Contest\\Educational_Round\\169_Div_2\\1.cpp","tests":[{"id":1723732794822,"input":"3\n2\n3 8\n2\n5 6\n6\n1 2 3 4 5 10\n","output":"YES\nNO\nNO\n"},{"id":1723733129528,"input":"2\n3\n1 1 3\n2\n1 1","output":""}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeforcesProblemSolving\\CodeForces_Live_Contest\\Educational_Round\\169_Div_2\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/169_Div_2/.cph/.2.cpp_02d8477954309ce39af859b927592e33.prob b/CodeForces_Live_Contest/Educational_Round/169_Div_2/.cph/.2.cpp_02d8477954309ce39af859b927592e33.prob new file mode 100644 index 0000000..1deea04 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/169_Div_2/.cph/.2.cpp_02d8477954309ce39af859b927592e33.prob @@ -0,0 +1 @@ +{"name":"Local: 2","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeforcesProblemSolving\\CodeForces_Live_Contest\\Educational_Round\\169_Div_2\\2.cpp","tests":[{"id":1723733833916,"input":"4\n1 2\n3 4\n2 5\n2 5\n3 7\n6 7\n4 5\n2 8\n","output":"1\n3\n2\n3\n"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeforcesProblemSolving\\CodeForces_Live_Contest\\Educational_Round\\169_Div_2\\2.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/169_Div_2/.cph/.3.cpp_d2e6629d6419512070903afdd77178d0.prob b/CodeForces_Live_Contest/Educational_Round/169_Div_2/.cph/.3.cpp_d2e6629d6419512070903afdd77178d0.prob new file mode 100644 index 0000000..9f28d10 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/169_Div_2/.cph/.3.cpp_d2e6629d6419512070903afdd77178d0.prob @@ -0,0 +1 @@ +{"name":"Local: 3","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeforcesProblemSolving\\CodeForces_Live_Contest\\Educational_Round\\169_Div_2\\3.cpp","tests":[{"id":1723734856311,"input":"4\n2 5\n1 10\n3 0\n10 15 12\n4 6\n3 1 2 4\n2 4\n6 9\n","output":"4\n13\n0\n0\n"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeforcesProblemSolving\\CodeForces_Live_Contest\\Educational_Round\\169_Div_2\\3.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/169_Div_2/.cph/.4.cpp_547cc91468f513c95e3f80ef74499403.prob b/CodeForces_Live_Contest/Educational_Round/169_Div_2/.cph/.4.cpp_547cc91468f513c95e3f80ef74499403.prob new file mode 100644 index 0000000..c652b54 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/169_Div_2/.cph/.4.cpp_547cc91468f513c95e3f80ef74499403.prob @@ -0,0 +1 @@ +{"name":"Local: 4","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeforcesProblemSolving\\CodeForces_Live_Contest\\Educational_Round\\169_Div_2\\4.cpp","tests":[{"id":1723736426613,"input":"2\n4 5\nBR BR GY GR\n1 2\n3 1\n4 4\n1 4\n4 2\n2 1\nBG RY\n1 2\n","output":"1\n4\n0\n3\n2\n-1\n"},{"id":1723738616644,"input":"1\n1 1\nBG\n1 1","output":"0"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\CodeforcesProblemSolving\\CodeForces_Live_Contest\\Educational_Round\\169_Div_2\\4.cpp","group":"local","local":true} \ No newline at end of file diff --git a/CodeForces_Live_Contest/Educational_Round/169_Div_2/1.bin b/CodeForces_Live_Contest/Educational_Round/169_Div_2/1.bin new file mode 100644 index 0000000..dda3474 Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/169_Div_2/1.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/169_Div_2/1.cpp b/CodeForces_Live_Contest/Educational_Round/169_Div_2/1.cpp new file mode 100644 index 0000000..3bbd913 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/169_Div_2/1.cpp @@ -0,0 +1,63 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize(3, "Ofast", "inline") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +#define int long long + +bool solve() +{ + int n; + cin>>n; + vectora(n); + mapmp; + for(int i=0;i>a[i]; + mp[a[i]]+=1; + } + vectorv; + for(auto &i:mp){ + v.push_back(i.first); + } + sort(v.begin(),v.end()); + n=v.size(); + if(n>=3){ + cout<<"NO"<> t; + while (t--) + { + if (solve()) + { + + } + else + { + + } + } + return 0; +} + + diff --git a/CodeForces_Live_Contest/Educational_Round/169_Div_2/2.bin b/CodeForces_Live_Contest/Educational_Round/169_Div_2/2.bin new file mode 100644 index 0000000..f21ced7 Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/169_Div_2/2.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/169_Div_2/2.cpp b/CodeForces_Live_Contest/Educational_Round/169_Div_2/2.cpp new file mode 100644 index 0000000..a1dfed2 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/169_Div_2/2.cpp @@ -0,0 +1,83 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize(3, "Ofast", "inline") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +#define int long long + +bool solve() +{ + int l,r; + cin>>l>>r; + int L,R; + cin>>L>>R; + if(L<=l){ + int temp1=L; + int temp2=R; + L=l; + R=r; + l=temp1; + r=temp2; + } + // cout<=L){ + cout<=L){ + cout<R){ + cout<=L){ + cout<=L){ + cout<R){ + cout<> t; + while (t--) + { + if (solve()) + { + + } + else + { + + } + } + return 0; +} + + diff --git a/CodeForces_Live_Contest/Educational_Round/169_Div_2/3.bin b/CodeForces_Live_Contest/Educational_Round/169_Div_2/3.bin new file mode 100644 index 0000000..bf4d4e3 Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/169_Div_2/3.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/169_Div_2/3.cpp b/CodeForces_Live_Contest/Educational_Round/169_Div_2/3.cpp new file mode 100644 index 0000000..1662708 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/169_Div_2/3.cpp @@ -0,0 +1,52 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize(3, "Ofast", "inline") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +#define int long long + +bool solve() +{ + int n,k; + cin>>n>>k; + vectora(n); + for(int i=0;i>a[i]; + } + sort(a.begin(),a.end()); + reverse(a.begin(),a.end()); + int ans=0; + for(int i=1;i> t; + while (t--) + { + if (solve()) + { + + } + else + { + + } + } + return 0; +} + + diff --git a/CodeForces_Live_Contest/Educational_Round/169_Div_2/4.bin b/CodeForces_Live_Contest/Educational_Round/169_Div_2/4.bin new file mode 100644 index 0000000..e575c9e Binary files /dev/null and b/CodeForces_Live_Contest/Educational_Round/169_Div_2/4.bin differ diff --git a/CodeForces_Live_Contest/Educational_Round/169_Div_2/4.cpp b/CodeForces_Live_Contest/Educational_Round/169_Div_2/4.cpp new file mode 100644 index 0000000..ee0b3a4 --- /dev/null +++ b/CodeForces_Live_Contest/Educational_Round/169_Div_2/4.cpp @@ -0,0 +1,287 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize(3, "Ofast", "inline") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +#define int long long + +bool solve() +{ + int n,q; + cin>>n>>q; + vectora(n); + for(int i=0;i>a[i]; + } + vectorBG; + vectorBR; + vectorBY; + vectorGR; + vectorGY; + vectorRY; + for(int i=0;i>x>>y; + x-=1; + y-=1; + string ft=a[x]; + string se=a[y]; + if(ft>se) swap(ft,se); + if(x>y) swap(x,y); + int ans=1e9; + // cout<0){ + auto it=upper_bound(BR.begin(),BR.end(),x)-BR.begin(); + if(it==BR.size()){ + int idx=BR[it-1]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + } + else if(it==0){ + int idx=BR[it]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + } + else{ + int idx=BR[it]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + idx=BR[it-1]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + } + } + if(BY.size()>0){ + auto it=upper_bound(BY.begin(),BY.end(),x)-BY.begin(); + if(it==BY.size()){ + int idx=BY[it-1]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + } + else if(it==0){ + int idx=BY[it]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + } + else{ + int idx=BY[it]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + idx=BY[it-1]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + } + } + if(GR.size()>0){ + auto it=upper_bound(GR.begin(),GR.end(),x)-GR.begin(); + if(it==GR.size()){ + int idx=GR[it-1]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + } + else if(it==0){ + int idx=GR[it]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + } + else{ + int idx=GR[it]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + idx=GR[it-1]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + } + } + if(GY.size()>0){ + auto it=upper_bound(GY.begin(),GY.end(),x)-GY.begin(); + if(it==GY.size()){ + int idx=GY[it-1]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + } + else if(it==0){ + int idx=GY[it]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + } + else{ + int idx=GY[it]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + idx=GY[it-1]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + } + } + } + else if(ft=="BR" and se=="GY"){ + // search BG,BY,GR,RY + if(BG.size()>0){ + auto it=upper_bound(BG.begin(),BG.end(),x)-BG.begin(); + if(it==BG.size()){ + int idx=BG[it-1]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + } + else if(it==0){ + int idx=BG[it]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + } + else{ + int idx=BG[it]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + idx=BG[it-1]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + } + } + if(BY.size()>0){ + auto it=upper_bound(BY.begin(),BY.end(),x)-BY.begin(); + if(it==BY.size()){ + int idx=BY[it-1]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + } + else if(it==0){ + int idx=BY[it]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + } + else{ + int idx=BY[it]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + idx=BY[it-1]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + } + } + if(GR.size()>0){ + auto it=upper_bound(GR.begin(),GR.end(),x)-GR.begin(); + if(it==GR.size()){ + int idx=GR[it-1]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + } + else if(it==0){ + int idx=GR[it]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + } + else{ + int idx=GR[it]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + idx=GR[it-1]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + } + } + if(RY.size()>0){ + auto it=upper_bound(RY.begin(),RY.end(),x)-RY.begin(); + if(it==RY.size()){ + int idx=RY[it-1]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + } + else if(it==0){ + int idx=RY[it]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + } + else{ + int idx=RY[it]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + idx=RY[it-1]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + } + } + } + else if(ft=="BY" and se=="GR"){ + // search BG,BR,GY,RY + if(BG.size()>0){ + auto it=upper_bound(BG.begin(),BG.end(),x)-BG.begin(); + if(it==BG.size()){ + int idx=BG[it-1]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + } + else if(it==0){ + int idx=BG[it]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + } + else{ + int idx=BG[it]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + idx=BG[it-1]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + } + } + if(BR.size()>0){ + auto it=upper_bound(BR.begin(),BR.end(),x)-BR.begin(); + if(it==BR.size()){ + int idx=BR[it-1]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + } + else if(it==0){ + int idx=BR[it]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + } + else{ + int idx=BR[it]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + idx=BR[it-1]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + } + } + if(GY.size()>0){ + auto it=upper_bound(GY.begin(),GY.end(),x)-GY.begin(); + if(it==GY.size()){ + int idx=GY[it-1]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + } + else if(it==0){ + int idx=GY[it]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + } + else{ + int idx=GY[it]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + idx=GY[it-1]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + } + } + if(RY.size()>0){ + auto it=upper_bound(RY.begin(),RY.end(),x)-RY.begin(); + if(it==RY.size()){ + int idx=RY[it-1]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + } + else if(it==0){ + int idx=RY[it]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + } + else{ + int idx=RY[it]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + idx=RY[it-1]; + ans=min(ans,abs(idx-x)+abs(idx-y)); + } + } + } + else{ + ans=min(ans,abs(y-x)); + } + if(ans==1e9) cout<<-1<> t; + while (t--) + { + if (solve()) + { + + } + else + { + + } + } + return 0; +} + +