This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int n, l;
cin >> n >> l;
map<int, int> nn;
vector<int> nums(n);
vector<vector<int>> ns(n+1);
int d=0;
for (int i = 0; i < n; i++)
{
int a;
cin >> a;
if (nn[a]==0) nn[a] = ++d;
nums[i] = nn[a];
ns[nn[a]].push_back(i);
}
int q;
cin >> q;
vector<int> qs(q);
vector<vector<int>> ans(q, vector<int>(n-l+1, 0));
for (int i = 0; i < q; i++) cin >> qs[i];
vector<int> inter(2*n, 0);
int r = 0;
for (int i = 0; i <= n-l; i++)
{
if (i)
{
for (int ele:ns[nums[i-1]])
{
inter[ele-i+1+n]--;
}
}
while (r-i < l)
{
for (int ele:ns[nums[r]])
{
inter[ele-r+n]++;
}
r++;
}
vector<int> qqs(n+1, 0);
for (int j = n-i; j < n+n-i-l+1; j++) qqs[inter[j]]++;
for (int j = n-1; j >=0; j--) qqs[j] += qqs[j+1];
for (int j = 0; j < q; j++)
{
ans[j][i] = qqs[l-qs[j]]-1;
}
}
for (auto ele:ans)
{
for (int ele2:ele) cout << ele2 << " ";
cout << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |