feat: Add solutions for Codeforces problems 1968F, 1968G1
This commit is contained in:
parent
f3665e71d5
commit
a2f9c81865
49
Codes/1968 F - Equal XOR Segments/1968F.cpp
Normal file
49
Codes/1968 F - Equal XOR Segments/1968F.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
#define ll long long
|
||||
#define endl '\n'
|
||||
#define FAST (ios_base::sync_with_stdio(false), cin.tie(nullptr));
|
||||
ll pow(ll x,ll y,ll m=1e9+7){ll ans=1;x%=m;while(y){if(y&1)ans=(ans*x)%m;x=(x*x)%m;y>>=1;}return ans;}
|
||||
|
||||
void solve()
|
||||
{
|
||||
ll n, q;
|
||||
cin >> n >> q;
|
||||
vector<ll>v(n+1,0);
|
||||
map<ll, vector<ll>> m;
|
||||
m[0].push_back(0);
|
||||
for(int i = 1; i <= n; ++i)
|
||||
{
|
||||
cin>>v[i];
|
||||
v[i] ^= v[i-1];
|
||||
m[v[i]].push_back(i);
|
||||
}
|
||||
while(q--)
|
||||
{
|
||||
ll l, r;
|
||||
cin>>l>>r;
|
||||
if(v[l-1]==v[r])
|
||||
{
|
||||
cout<<"YES\n";
|
||||
continue;
|
||||
}
|
||||
auto &v1=m[v[r]], &v2=m[v[l-1]];
|
||||
int it1=*lower_bound(v1.begin(), v1.end(), l);
|
||||
int it2=*--lower_bound(v2.begin(), v2.end(), r);
|
||||
if(it1<it2) cout<<"YES\n";
|
||||
else cout<<"NO\n";
|
||||
}
|
||||
cout<<endl;
|
||||
}
|
||||
|
||||
signed main()
|
||||
{
|
||||
FAST;
|
||||
int TCS = 1;
|
||||
cin >> TCS;
|
||||
for (int TC = 1; TC <= TCS; ++TC)
|
||||
{
|
||||
// cout<<"Case "<<TC<<": ";
|
||||
solve();
|
||||
}
|
||||
}
|
66
Codes/1968 G1 - Division + LCP (easy version)/1968G1.cpp
Normal file
66
Codes/1968 G1 - Division + LCP (easy version)/1968G1.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
#define ll long long
|
||||
#define endl '\n'
|
||||
#define FAST (ios_base::sync_with_stdio(false), cin.tie(nullptr));
|
||||
ll pow(ll x,ll y,ll m=1e9+7){ll ans=1;x%=m;while(y){if(y&1)ans=(ans*x)%m;x=(x*x)%m;y>>=1;}return ans;}
|
||||
|
||||
vector<int>Zfunc(string &str)
|
||||
{
|
||||
int n=str.size();
|
||||
vector<int>z(n);
|
||||
int l=0,r=0;
|
||||
for(int i=1;i<n;i++)
|
||||
{
|
||||
if(i<=r) z[i]=min(r-i+1,z[i-l]);
|
||||
while(i+z[i]<n&&str[z[i]]==str[i+z[i]]) z[i]++;
|
||||
if(i+z[i]-1>r)
|
||||
{
|
||||
l=i;
|
||||
r=i+z[i]-1;
|
||||
}
|
||||
}
|
||||
return z;
|
||||
}
|
||||
|
||||
void solve()
|
||||
{
|
||||
int n, k;
|
||||
string s;
|
||||
cin>> n >> k >> k >> s;
|
||||
vector<int>z = Zfunc(s);
|
||||
ll low = 1, high = n, ans = 0;
|
||||
while(low <= high)
|
||||
{
|
||||
ll mid = low + (high - low) / 2;
|
||||
ll cnt = 1;
|
||||
for(int i = mid;i < n;)
|
||||
{
|
||||
if(z[i] >= mid)
|
||||
{
|
||||
cnt++;
|
||||
i += mid;
|
||||
}
|
||||
else i++;
|
||||
}
|
||||
if(cnt >= k)
|
||||
{
|
||||
ans = mid;
|
||||
low = mid+1;
|
||||
}
|
||||
else high = mid-1;
|
||||
}
|
||||
cout<<ans<<endl;
|
||||
}
|
||||
|
||||
signed main()
|
||||
{
|
||||
FAST;
|
||||
int TCS = 1;
|
||||
cin >> TCS;
|
||||
for (int TC = 1; TC <= TCS; ++TC)
|
||||
{
|
||||
// cout<<"Case "<<TC<<": ";
|
||||
solve();
|
||||
}
|
||||
}
|
@ -311,8 +311,10 @@ This repository contains my solutions of Codeforces problems. They are in C++ la
|
||||
| 299 | 1968 C | Assembly via Remainders | [Question](https://codeforces.com/problemset/problem/1968/C) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1968%20C%20-%20Assembly%20via%20Remainders)
|
||||
| 300 | 1968 D | Permutation Game | [Question](https://codeforces.com/problemset/problem/1968/D) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1968%20D%20-%20Permutation%20Game)
|
||||
| 301 | 1968 E | Cells Arrangement | [Question](https://codeforces.com/problemset/problem/1968/E) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1968%20E%20-%20Cells%20Arrangement)
|
||||
| 302 | 1969 A | Two Friends | [Question](https://codeforces.com/problemset/problem/1969/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1969%20A%20-%20Two%20Friends)
|
||||
| 303 | 1969 B | Shifts and Sorting | [Question](https://codeforces.com/problemset/problem/1969/B) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1969%20B%20-%20Shifts%20and%20Sorting)
|
||||
| 302 | 1968 F | Equal XOR Segments | [Question](https://codeforces.com/problemset/problem/1968/F) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1968%20F%20-%20Equal%20XOR%20Segments)
|
||||
| 303 | 1968 G1 | Division + LCP (easy version) | [Question](https://codeforces.com/problemset/problem/1968/G1) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1968%20G1%20-%20Division%20+%20LCP%20(easy%20version))
|
||||
| 304 | 1969 A | Two Friends | [Question](https://codeforces.com/problemset/problem/1969/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1969%20A%20-%20Two%20Friends)
|
||||
| 305 | 1969 B | Shifts and Sorting | [Question](https://codeforces.com/problemset/problem/1969/B) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1969%20B%20-%20Shifts%20and%20Sorting)
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user