이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fast cin.tie(0)->sync_with_stdio(0);
#define int long long
#define inf ((int)1e18)
using namespace std;
int32_t main(){
fast
int n, k, q;
cin >> n >> k >> q;
vector <pair<int, int> > arr, ranges;
for(int i = 0; i < n; i++) {
int x, t, a, b;
cin >> x >> t >> a >> b;
arr.push_back({x, t});
}
sort(arr.begin(), arr.end());
int l = 0, r = -1, cnt = 0;
vector <int> have(k + 1);
while(r < n - 1) {
r++;
auto [pos, type] = arr[r];
if(!have[type]) cnt++;
have[type]++;
while(cnt == k) {
auto [tpos, ttype] = arr[l];
have[ttype]--;
if(!have[ttype]) cnt--;
// add to ranges
ranges.push_back({tpos, pos});
l++;
}
}
if(ranges.empty()) {
for(int i = 0; i < q; i++) {
cout << -1 << "\n";
}
return 0;
}
vector <pair<int, int> > qq;
for(int i = 0; i < q; i++) {
int x, t;
cin >> x >> t;
qq.push_back({x, i});
}
sort(qq.begin(), qq.end());
vector <int> ans(q);
auto calc = [&](int rind, int pos) {
if(rind == ranges.size()) return inf;
auto [l, r] = ranges[rind];
return max(abs(pos - l), abs(pos - r));
};
int now = 0;
for(auto [pos, ans_ind] : qq) {
while(calc(now + 1, pos) < calc(now, pos)) {
now++;
}
ans[ans_ind] = calc(now, pos);
}
for(auto it:ans) {
cout << it << "\n";
}
}
컴파일 시 표준 에러 (stderr) 메시지
new_home.cpp: In lambda function:
new_home.cpp:49:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | if(rind == ranges.size()) return inf;
| ~~~~~^~~~~~~~~~~~~~~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |