이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define MAXN 10000
#define MAXQ 100
int n, l, a[MAXN + 3], q, mapToSortedUniqQuery[MAXN + 3];
int ans[MAXQ + 3][MAXN + 3];
vector<int> queries, sortedUniqQueries;
int main() {
cin >> n >> l;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
cin >> q;
for (int i = 0; i < q; i++) {
int num;
cin >> num;
queries.push_back(num);
sortedUniqQueries.push_back(num);
}
// Populate mapToSortedUniqQuery
sort(sortedUniqQueries.begin(), sortedUniqQueries.end());
sortedUniqQueries.erase(unique(sortedUniqQueries.begin(), sortedUniqQueries.end()), sortedUniqQueries.end());
for (int k = 1; k <= n; k++) {
mapToSortedUniqQuery[k] = lower_bound(sortedUniqQueries.begin(), sortedUniqQueries.end(), k) - sortedUniqQueries.begin() + 1;
}
memset(ans, 0, sizeof(ans));
for (int d = 1; (1 + d) + (l - 1) <= n; d++) {
int currentDiff = 0;
for (int i = 1; i < l; i++) {
currentDiff += (a[i] != a[i + d]);
}
int leftPtr = 1;
for (int i = l; i + d <= n; i++) {
currentDiff += (a[i] != a[i + d]);
while (i - leftPtr + 1 > l) {
currentDiff -= (a[leftPtr] != a[leftPtr + d]);
leftPtr += 1;
}
// cout << "currentDiff " << leftPtr << " " << d << " " << currentDiff << " " << mapToSortedUniqQuery[currentDiff] << endl;
ans[mapToSortedUniqQuery[currentDiff]][leftPtr] += 1;
ans[mapToSortedUniqQuery[currentDiff]][leftPtr + d] += 1;
}
}
// Apply the prefix sum
for (int idx = 1; idx <= n - l + 1; idx++) {
for (int qIndex = 1; qIndex <= sortedUniqQueries.size(); qIndex++) {
ans[qIndex][idx] += ans[qIndex - 1][idx];
}
}
for (int i = 0; i < q; i++) {
int queryIndex = mapToSortedUniqQuery[queries[i]];
for (int j = 1; j <= n - l + 1; j++) {
if (j > 1) {
cout << " ";
}
cout << ans[queryIndex][j];
}
cout << endl;
}
}
컴파일 시 표준 에러 (stderr) 메시지
lot.cpp: In function 'int main()':
lot.cpp:57:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for (int qIndex = 1; qIndex <= sortedUniqQueries.size(); qIndex++) {
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |