prompt
string
response
string
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include<iostream> #include<cstdio> #include<algorithm> #include<map> #include<string> #include<vector> #include<climits> #define MAX 100001 int n,k; int data[MAX]; using namespace std; void solve(){ int ans=n+1; int l=0,r=0; map<int,int> m; while(1){ while(r<n&&m.size()<k){ if(data[r]<=k) m[data[r]]++; ...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
n, k = map(int, input().split()) aa = list(map(int, input().split())) cnts = [0] * (k + 1) ans = 1e6 existing = 0 r = 0 for l in range(n - k + 1): while r < n and existing < k: a = aa[r] if a <= k: cnts[a] += 1 if cnts[a] == 1: existing += 1 r += 1 ...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <bits/stdc++.h> using namespace std; using lint = long long int; template<class T = int> using V = vector<T>; template<class T = int> using VV = V< V<T> >; template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); } template<class T, class... Args> void assign(V<T>& v, int n, const Args...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <bits/stdc++.h> using namespace std; #define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++) #define debug(x) cerr<<#x<<":"<<x<<endl const int maxn=(int)1e6+5; int a[maxn]; int main(){ ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); int n,k; cin>>n>>k; map<int,int> mp; rep(i,1,n){ ...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include<iostream> #include<vector> #include<algorithm> using namespace std; static const int INF = 1 << 30; int main(){ int N, K; cin >> N >> K; vector<int> a(N); for(int i = 0; i < N; i++){ cin >> a[i]; a[i]--; } vector<int> num(K, 0); int res = INF; int cnt = 0; int j = 0; for(int i = 0; i < N; i++){ ...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include "bits/stdc++.h" using namespace std; #define Rep(i,n) for(int i=0;i<(int)(n);i++) #define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++) #define REP(i,n) for(ll i=0;i<(ll)(n);i++) #define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--) #define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++) #define RFOR(i,n1,n2) fo...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include "bits/stdc++.h" #define REP(i,num) for(int i=0;i<(num);++i) #define LOOP(i) while(i--) #define ALL(c) c.begin(),c.end() #define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl; #define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;} using namespace std; using ...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,s,n) for(ll i = (s); i < (n); i++) #define rep0(i,n) rep(i,0,n) #define rep1(i,n) rep(i,1,n+1) #define BR "\n" #define SP " " int main() { int N, K; cin >> N >> K; vector<ll> A(N), C(K + 1, 0); rep0(i, N) cin >> A[i]; ll a...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <iostream> #include <algorithm> #include <vector> #include <set> #include <map> using namespace std; #define REP(i,n) for (int i=0;i<(n);++i) #define rep(i,a,b) for(int i=a;i<(b);++i) template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;} template<class T> inline bool c...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <cstdio> #include <vector> #include <algorithm> #include <map> int main() { size_t N, K; scanf("%zu %zu", &N, &K); std::vector<size_t> a(N); for (auto& ai: a) scanf("%zu", &ai); std::map<size_t, int> m; size_t ir = 0; for (; ir < N; ++ir) { if (a[ir] <= K) ++m[a[ir]]; if (m.size() == K...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <iostream> #include <algorithm> #include <vector> #include <queue> #include <map> #include <cmath> #include <iomanip> using namespace std; #define REP(i,n) for (int i=0;i<(n);++i) #define rep(i,a,b) for(int i=a;i<(b);++i) template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return f...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < (int)n; i++) using ll = long long; const int INF = 1e9; int main(){ int n, k; cin >> n >> k; int a[n]; rep(i,n) cin >> a[i]; int l = 0; vector<int> u(n+1); int num = 0; int r = 0; int ans = INF; rep(l,n) { while(r...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
if __name__ == "__main__": N, K = map(lambda x: int(x), input().split()) a = list(map(lambda x: int(x), input().split())) ans = N + 1 idx = 0 num = 0 values = [0] * K for s in range(N): while (idx < N and num < K): v = a[idx] if (v <= K): valu...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
# include "bits/stdc++.h" using namespace std; using LL = long long; using ULL = unsigned long long; const double PI = acos(-1); template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); } template<class T>constexpr T HINF() { return INF<T>() / 2; } template <typename T_char>T_char TL(T_char cX) { re...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <bits/stdc++.h> #define inf (long long)1e9 using namespace std; template <class T> struct SegmentTree { // 1-indexed typedef function<T(T, T)> F; int n; F f; T unit; vector<T> dat; SegmentTree(){}; SegmentTree(int newn, F f, T t) : f(f), unit(t) { init(newn); } void init(int newn) { ...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef vector<ll> vl; typedef pair<ll, ll> PP; #define rep(i, n) for (ll i = 0; i < ll(n); i++) #define all(v) v.begin(), v.end() bool chmin(ll& a, ll b) { if (b < a) { a = b; return 1; } return 0; } bool chmax(ll& a, l...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <bits/stdc++.h> using namespace std; #define int long long #define endl '\n' #define MOD 1000000007 #define maxn 100010 void solve() { int n, k; cin >> n >> k; vector<int> v(n); map<int, int> mp; for (int i = 0; i < n; i++) cin >> v[i]; int ct = 0, ans = n + 10; for (int...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) #define FOR(i,x,n) for(int i=x; i<(n); i++) #define ALL(n) begin(n),end(n) #define MOD (1000000007) #define INF (1e9) #define INFL (1e18) typedef long long ll; typedef unsigned int ui; typedef unsigned long long ull; template<clas...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <algorithm> #include <iostream> #include <map> using namespace std; int main() { int A[100005]; int n, k; cin >> n >> k; for (int i = 0; i < n; ++i) cin >> A[i]; map<int, int> cts; int values_in_window = 0; int m = 100005; for (int f = 0, b = 0; f < n; ++f) { if (!cts[A[f]] and A[f] <=...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <bits/stdc++.h> using namespace std; int n, k, uniq = 0, a[100005]; bool has1[100005]; int freq[100005]; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; has1[a[i]] = true; } for (int i = 1; i <= k; i++) { if (!has1[i]) { cout << 0 << endl; return 0; ...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <iostream> #include <vector> int main() { uint32_t N = 0, K = 0; std::cin >> N >> K; std::vector<uint32_t> A(N); for (auto &&a : A) std::cin >> a; size_t min_len = -1, K_count = 0; std::vector<uint32_t> count(K + 1, 0); for (size_t start = 0, end = 0; start < N; start++) { while (end < N &&...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner scan = new Scanner(System.in); int N = scan.nextInt(); int K = scan.nextInt(); int[]a = new int[N]; Map<Integer, Integer> map = new HashMap<Integer, Integer>(); for...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <bits/stdc++.h> using namespace std; int main(){ int n,K; cin>>n>>K; vector<int> v(n); for(int i=0;i<n;i++){ cin>>v[i],v[i]--; } vector<int> cnt(100100); int c = 0; int p = 0; int ans = 1e9; for(int i=0;i<n;i++){ while(p<n&&c<K){ if(v[p]<K){ cnt[v[p]]++; if(cnt[v[p]]==1) c++; } ...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<vector> #include<map> #include<set> #include<string> #include<queue> #include<stack> using namespace std; #define MOD 1000000007 #define INF (1<<29) #define EPS (1e-10) typedef long long Int; typedef pair<Int, Int> P; #define max(x, y) ((...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <algorithm> #include <utility> #include <functional> #include <cstring> #include <queue> #include <stack> #include <math.h> #include <iterator> #include <vector> #include <string> #include <set> #include <math.h> #include <iostream> #include <random> #include...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#!/usr/bin/env python3 # DSL_3_B: The Smallest Window II class Window: def __init__(self, k): self.k = k self.data = [0] * k self.zeros = set(range(k)) def add(self, i): if self.data[i-1] == 0: self.zeros.remove(i-1) self.data[i-1] += 1 def remove(self...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.*; import java.math.BigInteger; public class Main implements Runnable { static int mod = 1000000007; public static void main(String[] args) { new Thread(null, new Main(), "", 1024 * 1024 * 1024).start();...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#define _USE_MATH_DEFINES #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <string> #include <sstream> #include <iomanip> #include <cmath> #include <cstring> #include <cstdlib> #include <algorithm> #include <stack> #include <queue> #include <vector> #include <list> #include <set> #include <map> #include <b...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <iostream> #include <vector> const int INF = 1 << 25; int main() { int N, K; std::cin >> N >> K; std::vector<int> A(N); for (auto& a : A) { std::cin >> a; --a; } std::vector<int> cnt(K, 0); int unfill = K, r = 0; int ans = INF; for (int l = 0; l < N; ++l) ...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <cstdio> #include <vector> using namespace std; int main(){ int N,K,R=0,k=0; scanf("%d%d",&N,&K); vector<int>v(N),b(K+1); for(int i=0;i<N;i++)scanf("%d",&v[i]); int start=0,stop=0; for(;;){ for(;stop<N&&k<K;stop++){ if(v[stop]<=K&&++b[v[stop]]==1)k++; } if(k<K)break; for(;start<N&&k>=K;start++...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i,n) FOR(i,0,n) #define FOR(i,a,b) for(ll i=a;i<b;i++) #define PB push_back typedef vector<ll> vi; typedef vector<vector<ll>> vvi; const ll INF = (1ll << 60); typedef pair<ll,ll> pii; int main(){ ll N,K; cin>>N>>K; vi a(N); REP(i,N) ci...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <stdio.h> #include <queue> using namespace std; int main(){ int n,k,top=1<<30,now=0,temp,f[100010]; queue<int> q; scanf("%d%d",&n,&k); for(int i=0;i<=k;i++)f[i]=0; for(int i=0;i<n;i++){ scanf("%d",&temp); if(temp<=k){ if(f[temp]==0)now++; f[temp]++; ...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <iostream> using namespace std; using ll = long long; #define for_(i,a,b) for(int i = (a);i < (b);i++) #define rfor_(i,a,b) for(int i = (b)-1;i >= (a);i--) #define rep(i,n) for_(i,0,(n)) #define rrep(i,n) rfor_(i,0,(n)) const int mx = 100005; int N, K; int s, t, l, c; int a[mx], b[mx]; int main(){ cin....
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include<cstdio> #include<iostream> #include<string> #include<algorithm> #include<set> #include<map> #include<vector> #define INF 999999999 using namespace std; int n, s, k, ans; int a[105000]; void solve() { int ret = n + 1; int l = 0, r = 0; map<int,int> m; while (1) { while (r < n && (int)m.size()<k) {...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
N, K = map(int, input().split()) *A, = map(int, input().split()) ans = N+1 t = 0; u = [0]*K; c = 0 for s in range(N): while t < N and c < K: v = A[t] if v <= K: u[v-1] += 1 if u[v-1] == 1: c += 1 t += 1 if c == K: ans = min(ans, t-s) v...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <bits/stdc++.h> using namespace std; int n, k; vector<int> V; bool solve(int ans){ vector<int> freq(k); int tot = 0; for (int i = 0; i < ans; ++i){ int a = V[i]; if (a >= k) continue; if (!freq[a]) tot++; freq[a]++; } for (int i = ans; tot < k && i < n; ++i){ int a = V[i]; if (a < k){ ...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; int a[100002], b[100002]; int main(){ int n, k, ans = inf; scanf("%d%d", &n, &k); for(int i = 1;i <= n;i++)scanf("%d", &a[i]); int l = 0, r = 0, sum = 0; while(r <= n){ if(sum == k)ans = min(ans, r-l); if(sum < k){ if(a[++r] <= k){ if...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define P pair<int,int> #define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I) int main(){ ll N,K,count=0,ans=100001; cin >> N >> K; vector<ll> a(N),counta(100001,0); FOR(i,0,N)cin >> a[i]; ll l=0,r=1; counta[a[0]]++; if(1<=a[0] && a[0]<=K)cou...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include<bits/stdc++.h> using namespace std; #define int long long #ifdef LOCAL_DEBUG #include "LOCAL_DEBUG.hpp" #endif template <class T> struct SegmentTree{ using F = function<T(T,T)>; F f; T inf; int n; vector<T> node; SegmentTree(vector<T> v,T inf,F f):inf(inf),f(f){ n = 1; while(n < v.size()) ...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(n);i++) typedef long long ll; typedef pair<int, int> P; #define MAX 500005 int main(int, char**) { int n, k; cin >> n >> k; vector<int> a(n); rep(i,n) { cin >> a[i]; --a[i]; } int l = 0, r = 0, kind = 0; int ans = n + 1; ma...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; int a[100002], b[100002]; int main(){ int n, k, ans = inf; scanf("%d%d", &n, &k); for(int i = 1;i <= n;i++)scanf("%d", &a[i]); int l = 0, r = 0, sum = 0; while(r <= n){ if(r == n && sum < k)break; if(sum == k)ans = min(ans, r-l); if(sum < ...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <iostream> #include <algorithm> #include <vector> #include <map> using namespace std; template<class like_bool> inline void YES(like_bool condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; } template<class like_bool> inline void Yes(like_bool condition){ if(condition) cout << "Yes" <<...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <set> #include <map> #include <list> #include <queue> #include <stack> #include <cmath> #include <ctime> #include <cstdio> #include <vector> #include <string> #include <bitset> #include <cctype> #include <cstdlib> #include <cstring> #include <utility> #include <numeric> #include <complex> #include <sstream> #i...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int INF = 1e9; int main() { ll N, K; cin >> N >> K; ll M = K * (K + 1) / 2; ll sum = 0; deque<int> deq; int ans = INF; map<int, int> mp; for (int i = 0; i < N; ++i) { int a; cin >> a; if (a > K) a = 0; deq.push_back(a...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define all(x) x.begin(),x.end() const long double PI = acos(-1.0L); const long long MOD = 1000000007LL; //const long long MOD = 998244353LL; typedef long long ll; typedef pair<int, int> pii; ...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <bits/stdc++.h> using namespace std; int N; int K; vector<int> a(100001); bool check(int x) { vector<int> cnt(100001, 0); set<int> all; for ( int i = 0; i < x; i++ ) { if ( a[i] <= K ) all.insert(a[i]); cnt[a[i]]++; } if ( all.size() >= K ) return true; for ( int i = ...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
/*    ∫ ∫ ∫    ノヽ   (_  )  (_    ) (______ )  ヽ(´・ω・)ノ     |  /    UU */ #pragma region macro #include <bits/stdc++.h> typedef long long int64; using namespace std; typedef vector<int> vi; const int MOD = (int)1e9 + 7; const int64 INF = 1LL << 62; const int inf = 1<<30; template<class T>bool chmax(T &a, const T &b) { i...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include<iostream> #include<algorithm> using namespace std; int n,k,cnt[1<<17],ans=1e9,now,a[1<<17],f; int main() { cin>>n>>k; for(int i=0;i<n;i++) { cin>>a[i]; if(a[i]<=k)now+=!cnt[a[i]]; cnt[a[i]]++; while(f<i&&(a[f]>k||cnt[a[f]]>1))cnt[a[f++]]--; if(now==k)ans=min(ans,i-f+1); } cout<<(ans==1e9?0:ans)<...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
# include "bits/stdc++.h" using namespace std; using LL = long long; using ULL = unsigned long long; const double PI = acos(-1); template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); } template<class T>constexpr T HINF() { return INF<T>() / 2; } template <typename T_char>T_char TL(T_char cX) { re...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include<stdio.h> #include<vector> #include<iostream> #include<functional> using namespace std; typedef long long ll; #define REP(i,n) for(int i=0;i<(int)(n);i++) int main(){ ll n,k,x; vector<ll> list; cin >> n >> k; REP(i,n){ cin >> x; list.push_back(x-1); } ll l=0, r=0; l...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <bits/stdc++.h> using namespace std; const int INF=0x3f3f3f3f; int n,s,k,ans=INF; int a[100005],b[100005]; int main() { ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); cin>>n>>k; s=k; for (int i=0;i<n;++i) cin>>a[i]; for (int i=0,j=0;j<=n;) { if (s>0) { if (!b[a[j]] &...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
import sys n,k = map(int, input().split( )) a = list(map(int, input().split( ))) tmp = max(a) tmp2 = max(tmp,n,k)+1 chk = [0]*(tmp2) for i in range(n): chk[a[i]] += 1 if 0 in chk[1:k+1]: print(0) sys.exit() right = n-1 left = 0 L = [] while right < n: while chk[a[right]] > 1 or a[right] > k: ...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include<cstdio> #include<iostream> #include<algorithm> #include<utility> #include<vector> #include<queue> #include<functional> #include<map> #include<set> #include<cstring> #include<string> #include<stack> #include<stdlib.h> #include<math.h> using namespace std; #define int long long typedef pair<int, int> pii; typede...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
def LI(): return list(map(int, input().split())) def II(): return int(input()) def LS(): return input().split() def S(): return input() def LIR(n): return [LI() for i in range(n)] def MI(): return map(int, input().split()) #1:set #1_A """ n,q = map(int, input().split(" ")) group = [[i] for i in range(n)] key = [i for i...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <algorithm> #include <cstdio> #include <iostream> #include <map> #include <cmath> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #include <stdlib.h> #include <stdio.h> #include <bitset> #include <cstring> #include <deque> #include <iomanip> #include <lim...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include<cstdio> #include<vector> #include<algorithm> #include<utility> #include<numeric> #include<iostream> #include<array> #include<string> #include<sstream> #include<stack> #include<queue> #include<list> #include<functional> #define _USE_MATH_DEFINES #include<math.h> #include<map> #define SENTINEL 1000000001 #def...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
# -*- coding: utf-8 -*- """ Sliding Window - The Smallest Window II http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_3_B&lang=jp """ from collections import defaultdict N, K = map(int, input().split()) A = [int(a) for a in input().split()] left, right, num = 0, 0, 0 ans = float('inf') count = defaultdict...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <bits/stdc++.h> using ll = long long; using namespace std; const int inf = 1e9; const ll linf = 1e18; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i], a[i]--; int res = inf; int l = 0, r...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; int a[100002], b[100002]; int main(){ int n, k, ans = inf; scanf("%d%d", &n, &k); for(int i = 1;i <= n;i++)scanf("%d", &a[i]); int l = 0, r = 0, sum = 0; while(r <= n){ if(sum == k)ans = min(ans, r-l); if(sum < k){if(a[++r] <= k && b[a[r]]++...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#define _USE_MATH_DEFINES #include <cstdio> #include <cstdlib> #include <iostream> #include <cmath> #include <algorithm> #include <vector> #include <queue> #include <map> #include <list> using namespace std; typedef pair<long long int, long long int> P; long long int INF = 1e9; int a[110000]; int cnt[110000] = {}; ...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include "bits/stdc++.h" using namespace std; void solve() { int n, k; cin >> n >> k; vector<int> as(n); for (int i = 0; i < n; i++) { cin >> as[i]; } int ans = n + 1, r = -1, cnt = 0; vector<int> bincnt(k + 1); for (int l = 0; l <= n - k; l++) { while (r < l ||...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include<bits/stdc++.h> using namespace std; #define inf INT_MAX #define INF LLONG_MAX #define ll long long #define ull unsigned long long #define M (int)(1e9+7) #define P pair<int,int> #define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++) #define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--) #define rep(i,n) FOR(i,0,n) #d...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; int main(void) { int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } int l = 0, r = 0; int num = 0, ans = INF; map<int, int> mp; while (l < n) { while (r < n && num < k) { if (a[r]...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include<bits/stdc++.h> using namespace std; using UL = unsigned int; using ULL = unsigned long long; using LL = long long; #define rep(i, n) for(UL i = 0; i < (n); i++) struct Problem { void Solve() { UL N, K; scanf("%d%d", &N, &K); vector<UL> A(N); rep(i, N) { scanf("%d", &A[i]); A[i]--; } ...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include<bits/stdc++.h> using namespace std; int n,k,a[111111]; int solve(int m){ int ak[111111]={}; for(int i=0;i<n;i++){ ak[a[i]]++; if(i<m-1)continue; int t=1; for(int j=1;j<=k;j++) if(ak[j]==0){ t=0; break; } ak[a[i-(m-1)]]--; if(t)return 1; } return 0; } int main(){ ...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <climits> #include <iostream> #include <unordered_map> #include <vector> using namespace std; int main() { int N, K, ans = INT_MAX, i = 0; cin >> N >> K; vector<int> a(N); for (int& j : a) cin >> j; unordered_map<int, int> b; for (int j = 0; j < N; ++j) { while (K != b.size() && N != i) { if (K >= ...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pairInt; typedef tuple<int, int, int> tuple3Int; #define FOR(i, n) for (int i = 0; i < int(n); i++) #define FOR1(i, m, n) for (int i = int(m); i < int(n); i++) #define MAX(a, b) ((a) >= (b) ? (a) ...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; vector<int> A(N); for(int i=0; i<N; ++i) cin >> A[i]; map<int, int> cnt; int right = 0; int res = N + 1; for(int left = 0; left < N; ++left) { while(right < N && cnt.size() < K) { if(A[r...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include<iostream> #include<cstring> using namespace std; int main(){ int n, k; cin >> n >> k; int cnt[100001] = {}; int a[n], check = 0; for(int i = 0; i < n; i++){ cin >> a[i]; if(a[i] <= k && cnt[a[i]] == 0) check++; cnt[a[i]]++; } if(check != k){ cout ...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <cstdio> using namespace std; int A[100010], cnt[100010]; int main() { int N, K; scanf("%d%d", &N, &K); for(int i=0; i<N; i++) { scanf("%d", &A[i]); } int r = 0, sum = 0, ans = N+1; for(int l=0; l<N; l++) { while(sum < K && r < N) { if(!cnt[ A[r] ] && A[r] <= K...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <iostream> using namespace std; #define N 100000 #define INF 1000000 #define MIN(X,Y) ((X)<(Y)?(X):(Y)) int main(void){ int ans = INF; int n, k, l, r, a[N]; int flg[N+1], cnt; cin >> n >> k; for (int i=0; i<n; i++) cin >> a[i]; for (int i=1; i<=k; i++) flg[i] = 0; cnt = 0; l = 0; r = -1; ...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <iostream> #include <string> #include <algorithm> #include <functional> #include <vector> #include <utility> #include <cstring> #include <iomanip> #include <numeric> #include <cmath> #include <queue> #include <map> #include <set> using namespace std; typedef long long ll; const int INF = 1<<30; const int MOD ...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include<iostream> using namespace std; typedef long long ll; #define rep(i,n) for(int i=0;i<(n);i++) ll N,K,a[100000],cou[100000]; int main() { cin >> N >> K; rep(i,N)cin >> a[i]; rep(i,N)a[i]--; ll ans = N + 1; ll l = 0,r = 0,used = 0; for(;;) { while(r < N && used < K) { ...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
import java.util.Scanner; public class Main { //http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_3_A //http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2692179#1 -- reference public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); ...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <bits/stdc++.h> using namespace std; template< class T > int slide_smallest2(const vector<T>& v, T k) { map<T, int> m; int l=0, r; int ret = v.size() + 1; for (r = 0; r < v.size(); ++r) { if (v[r] > k) continue; m[v[r]] = r; while (m.size() == k) { ret = min...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<vector> #include<set> #include<queue> #include<cstdlib> #include<algorithm> using namespace std; #define pb push_back #define mp make_pair #define ls(x) (x << 1) #define rs(x) (x<<1|1) #define SZ(x) (int)(x).size() typedef long long LL; ty...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <bits/stdc++.h> #include <cmath> using namespace std; typedef long long ll; //typedef unsigned long long ll; #define rep(i, n) for (int i = 0; i < (n); ++i) //#define rep(i, n) for (ll i = 0; i < (n); ++i) //#define sz(x) ll(x.size()) //typedef pair<ll, int> P; typedef pair<ll, ll> P; //const double INF = 1e...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include "bits/stdc++.h" using namespace std; typedef long long ll; int main() { int n, k; cin >> n >> k; vector<int> a(n); vector<int> cnt(k); int rest = k; for (int i = 0; i < n; i++) { cin >> a[i]; } if (k == 1) { if (find(a.begin(), a.end(), 1) != a.end()) puts("1"); ...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <bits/stdc++.h> using namespace std; struct RMQ { using type = int; static type id() { return INT_MAX; } static type op(const type& l, const type & r) { return min(l, r); } }; template <typename M> class SegmentTree { using T = typename M::type; const int n; vector<T> data; int size(int n) { int res...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#pragma GCC optimize("Ofast") #include <cassert> #include <cstdio> #include <cstdlib> #include <string> #include <algorithm> #include <iostream> #include <queue> #include <vector> #include <bitset> #include <cmath> #include <limits> #include <iostream> #include <map> #include <set> #include <stack> #include <tuple> #in...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int N, K; cin >> N >> K; vector<int> a(N); for (int i = 0; i < N; i++) cin >> a[i]; vector<int> cnt(K+1); int kind = 0; int t = 0, ans = N + 1; for (in...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 30; int N, K, A[100000]; int exist[100001], sum; int main() { cin >> N >> K; for(int i = 0; i < N; i++) cin >> A[i]; int ret = INF, tail = 0; for(int i = 0; i < N; i++) { while(tail < N && sum < K) { sum += exist[A[tail]]++ == 0 ...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include<iostream> #include<algorithm> #include<vector> #include<stack> #include<queue> #include<list> #include<string> #include<cstring> #include<cstdlib> #include<cstdio> #include<cmath> #include<ctime> #include<set> using namespace std; typedef long long ll; const int NIL = -1; const int MAX = 2147483647; const in...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include<bits/stdc++.h> using namespace std; const int N=1e5+10; const int INF=1e9+10; int a[N]; bool in(int a,int b) { return a>0&&a<=b; } int main() { int n,k; ios::sync_with_stdio(false); cin.tie(0); while(cin>>n>>k) { for(int i=0;i<n;i++) { cin>>a[i]; ...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <iostream> #include <vector> int main() { int n, k; std::cin >> n >> k; std::vector<int> nums(n); std::vector<int> counts(k, 0); for (auto &num : nums) { std::cin >> num; } int left{ 0 }, right{ 0 }, count{ 0 }; int min_length = n + 1; while (true) { while (count < k && right < n) { if (nums[ri...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; int a[100002], b[100002]; int main(){ int n, k, ans = inf; scanf("%d%d", &n, &k); for(int i = 1;i <= n;i++)scanf("%d", &a[i]); int l = 0, r = 0, sum = 0; while(r <= n){ if(sum == k)ans = min(ans, r-l); if(sum < k){ r++; if(a[r] <= k){ ...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include<bits/stdc++.h> using namespace std; int main() { int N, K; cin>>N>>K; vector<int> a(N); for(int i=0;i<N;i++) cin>>a[i], a[i]--; vector<int> cnt(K); int num=0, ans=N+1; for(int l=0, r=0;l<N;l++){ while(r<N and num<K){ if(a...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <bits/stdc++.h> using namespace std; #define EACH(i,a) for (auto& i : a) #define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i) #define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i) #define REP(i,n) FOR(i,0,n) #define RREP(i,n) RFOR(i,0,n) #define ALL(a) (a).begin(),(a).end() #define debug(x) cerr << #x << ":" <<...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; int main() { int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] > k) a[i] = 0; } int ans = INF; map<int, int> mp; for (int l = 0, r = 0; l < n; l++) { ...
Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq...
#include <bits/stdc++.h> using namespace std; inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;} template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();} typedef long long ll; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; type...
Problem: Geek Sundaram is extremely anxious. He is in a hectic schedule. He has to study for his assessment the next day, watch FRIENDS tv show (in spite of watching every episode more than 5 times.. :P ), prepare questions for the programming contest and also complete his projects. So his friends try to calm him down ...
for _ in range(input()): a=map(int,raw_input().split()) s=sum(a)-a[4] print 'YES' if s<=a[4] else 'NO'
Problem: Geek Sundaram is extremely anxious. He is in a hectic schedule. He has to study for his assessment the next day, watch FRIENDS tv show (in spite of watching every episode more than 5 times.. :P ), prepare questions for the programming contest and also complete his projects. So his friends try to calm him down ...
t=int(raw_input()) for i in range(t): n,m,p,q,r=map(int,raw_input().split()) if (n+m+p+q)<=r: print "YES" else: print "NO"
Problem: Chef wants to hire a new assistant. He published an advertisement regarding that in a newspaper. After seeing the advertisement, many candidates have applied for the job. Now chef wants to shortlist people for the interviews, so he gave all of them one problem which they must solve in order to get shortlisted....
from math import * def lcm(n): x,c, t,f= 1,0,0,False while (n%2 == 0): c+=2**t f = True t+=1 n = n/2 if f == True: x = c+2**t i = 3 while i<=sqrt(n): f = False c = 0 t = 0 while (n%i == 0): f = True c+=i*...
Problem: Chef wants to hire a new assistant. He published an advertisement regarding that in a newspaper. After seeing the advertisement, many candidates have applied for the job. Now chef wants to shortlist people for the interviews, so he gave all of them one problem which they must solve in order to get shortlisted....
import sys,math test_cases = int(sys.stdin.readline()) def solve_test_case(): n = int(sys.stdin.readline()) i = 1 result = 0 while i < math.sqrt(n): if (n % i == 0): result += i result += n/i i = i+1 if i == math.sqrt(n): result += i print result...
Problem: Chef wants to hire a new assistant. He published an advertisement regarding that in a newspaper. After seeing the advertisement, many candidates have applied for the job. Now chef wants to shortlist people for the interviews, so he gave all of them one problem which they must solve in order to get shortlisted....
from math import sqrt T = int(raw_input()) def computesumoffactors(n): sum = 0 for i in range(1,int(sqrt(n))+1): if n % i: continue if (n/i) != i: sum+=(n/i+i) else: sum+=i return sum while T: N = int(raw_input()) print computesumoffactors(N) T-=1
Problem: Chef wants to hire a new assistant. He published an advertisement regarding that in a newspaper. After seeing the advertisement, many candidates have applied for the job. Now chef wants to shortlist people for the interviews, so he gave all of them one problem which they must solve in order to get shortlisted....
import math T = input() for i in xrange(T): N = input() s = 0 temp = math.sqrt(N) for j in xrange(1,int(temp)+1): if N%j == 0: s += j + N/j if temp == int(temp): s -= int(temp) print s
Problem: Chef wants to hire a new assistant. He published an advertisement regarding that in a newspaper. After seeing the advertisement, many candidates have applied for the job. Now chef wants to shortlist people for the interviews, so he gave all of them one problem which they must solve in order to get shortlisted....
t=int(raw_input()) for i in xrange(t): n=int(raw_input()) s=set() for j in xrange(1,int(n**0.5)+1): if n%j==0: s.add(j) s.add(n/j) print sum(s)
Problem: Chef wants to hire a new assistant. He published an advertisement regarding that in a newspaper. After seeing the advertisement, many candidates have applied for the job. Now chef wants to shortlist people for the interviews, so he gave all of them one problem which they must solve in order to get shortlisted....
import sys for __ in xrange(int(sys.stdin.readline())): n=int(sys.stdin.readline()) i=1 x=1 sum=0 while x: if n%i==0: sum+=i if i!=(n/i): sum+=(n/i) i+=1 if i*i>n: x=0 print sum
Problem: Chef wants to hire a new assistant. He published an advertisement regarding that in a newspaper. After seeing the advertisement, many candidates have applied for the job. Now chef wants to shortlist people for the interviews, so he gave all of them one problem which they must solve in order to get shortlisted....
import sys import math f = sys.stdin c = int(f.readline().strip()) for i in xrange(c): n = int(f.readline().strip()) divisores = [] j = 1 a = math.sqrt(n) while j <= a: if n%j == 0: divisores.append(j) b = n/j if not b in divisores: divis...
Problem: Chef wants to hire a new assistant. He published an advertisement regarding that in a newspaper. After seeing the advertisement, many candidates have applied for the job. Now chef wants to shortlist people for the interviews, so he gave all of them one problem which they must solve in order to get shortlisted....
t = int(raw_input()) MAX = 100001 primes = [] isPrime = [True]*MAX for i in range(2,MAX): if isPrime[i]: primes.append(i) for j in range(2*i, MAX, i): isPrime[j] = False while t: t-=1 n = int(raw_input()) ans = 1 for i in range(len(primes)): cnt = 0 while n%primes[i] == 0: cnt+=1 n /= primes[i]...