added 1955D
This commit is contained in:
parent
c7223dcf3d
commit
964c0ed3be
78
Codes/1955 D - Inaccurate Subsequence Search/1955D.cpp
Normal file
78
Codes/1955 D - Inaccurate Subsequence Search/1955D.cpp
Normal file
@ -0,0 +1,78 @@
|
||||
#include<bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
#define FAST_IO (ios_base:: sync_with_stdio(false),cin.tie(NULL));
|
||||
#define ll long long
|
||||
#define ull unsigned long long
|
||||
#define endl '\n'
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define pb push_back
|
||||
#define all(x) x.begin(), x.end()
|
||||
#define sz(x) (int)(x).size()
|
||||
#define yes cout<<"YES"<<endl
|
||||
#define no cout<<"NO"<<endl
|
||||
#define neg1 cout<<-1<<endl
|
||||
#define PI 3.141592653589793238
|
||||
#define MIN INT_MIN
|
||||
#define MAX INT_MAX
|
||||
#define INF LONG_LONG_MAX
|
||||
#define MOD 1000000007
|
||||
#define LLM 1000000000000000007
|
||||
|
||||
ll factorial(ll n) { if(n==0) return 1; ll res = 1; for (ll i = 2; i <= n; i++) res = res * i; return res; }
|
||||
ll nPr(ll n, ll r) { return factorial(n) / factorial(n - r); }
|
||||
ll nCr(ll n, ll r) { return factorial(n) / (factorial(r) * factorial(n - r));}
|
||||
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
|
||||
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b);}
|
||||
ull mypow(ull a, ull b,ull m=MOD) { ull ans = 1; a%=m; while(b){ if (b&1) ans = (ans*a) % m; a = (a*a) % m; b >>= 1; } return ans; }
|
||||
bool isPrime(ll n) { if(n <= 1) return false; for(ll i = 2; i*i <= n; i++) if(n % i == 0) return false; return true; }
|
||||
|
||||
#ifndef ONLINE_JUDGE
|
||||
#define dbg(x...) cerr << #x << " : "; _print(x)
|
||||
#else
|
||||
#define dbg(...)
|
||||
#endif
|
||||
void __print(int x) {cerr << x;}void __print(long x) {cerr << x;} void __print(long long x){cerr << x;}
|
||||
void __print(unsigned x){cerr << x;} void __print(unsigned long x){cerr << x;} void __print(unsigned long long x){cerr << x;}
|
||||
void __print(float x){cerr << x;} void __print(double x){cerr << x;} void __print(long double x){cerr << x;}
|
||||
void __print(char x){cerr << x;} void __print(const char *x){cerr << x;} void __print(const string &x){cerr << x;}
|
||||
void __print(bool x){cerr << (x ? "true" : "false");} void _print() { cerr << "\n"; }
|
||||
template <typename A> void __print(const A &x); template <typename A, typename B> void __print(const pair<A, B> &p);
|
||||
template <typename A> void __print(const A &x) {bool f=1; cerr << '['; for (const auto &i : x) {cerr << (f ? "" : ","), __print(i); f = 0;} cerr << ']';}
|
||||
template <typename A, typename B> void __print(const pair<A, B> &p) {cerr << '('; __print(p.first); cerr << ','; __print(p.second); cerr << ')';}
|
||||
template <typename Head, typename... Tail> void _print(const Head &H, const Tail &...T) { __print(H); if (sizeof...(T)) cerr << ", "; _print(T...);}
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void solve()
|
||||
{
|
||||
int n,m,k;
|
||||
cin>>n>>m>>k;
|
||||
vector<int>a(n),b(m);
|
||||
for(auto &i:a) cin>>i;
|
||||
for(auto &i:b) cin>>i;
|
||||
map<int,int>cta, ctb;
|
||||
for(auto x:b) ctb[x]++;
|
||||
for(int i=0; i<m; ++i) cta[a[i]]++;
|
||||
int ans=0,ct=0;
|
||||
for(auto e: ctb) ct+= min(cta[e.ff],ctb[e.ff]);
|
||||
ans += (ct>=k);
|
||||
for(int i=m; i<n; ++i)
|
||||
{
|
||||
cta[a[i-m]]--;
|
||||
ct -= (ctb[a[i-m]] > cta[a[i-m]]);
|
||||
cta[a[i]]++;
|
||||
ct += (ctb[a[i]]>=cta[a[i]]);
|
||||
ans += (ct>=k);
|
||||
}
|
||||
cout<<ans<<endl;
|
||||
}
|
||||
|
||||
signed main()
|
||||
{
|
||||
FAST_IO;
|
||||
int TC = 1;
|
||||
cin >> TC;
|
||||
while (TC--)
|
||||
solve();
|
||||
}
|
@ -294,6 +294,7 @@ This repository contains my solutions of Codeforces problems. They are in C++ la
|
||||
| 282 | 1955 A | Yogurt Sale | [Question](https://codeforces.com/problemset/problem/1955/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1955%20A%20-%20Yogurt%20Sale)
|
||||
| 283 | 1955 B | Progressive Square | [Question](https://codeforces.com/problemset/problem/1955/B) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1955%20B%20-%20Progressive%20Square)
|
||||
| 284 | 1955 C | Inhabitant of the Deep Sea | [Question](https://codeforces.com/problemset/problem/1955/C) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1955%20C%20-%20Inhabitant%20of%20the%20Deep%20Sea)
|
||||
| 285 | 1955 D | Inaccurate Subsequence Search | [Question](https://codeforces.com/problemset/problem/1955/D) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1955%20D%20-%20Inaccurate%20Subsequence%20Search)
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user