이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int maxn=100010;
struct event{
ll l, r;
int id;
event(){}
bool operator<(const event& e) const {
if(l != e.l)return l < e.l;
return r < e.r;
}
};
event e[maxn];
int nxt[maxn][18];
bool was[maxn];
int cnt(int i, int j){
int ans = 0;
// int x=i;
for(int k = 17; k >= 0; k--){
if(e[nxt[i][k]].r <= e[j].l){
i=nxt[i][k];
ans+=(1<<k);
}
}
// cout<<'\n'<<x<<' '<<j<<' '<<ans<<'\n';
return ans;
}
int main(){
int n, k;
cin >> n >> k;
e[0].l=e[0].r=e[0].id=0;
e[n + 1].l = 1e10;
e[n + 1].r = 1e10 + 1;
e[n + 1].id = n + 1;
vector<pair<ll,int>> he{{0, 0}, {0, 0}};
for(int i = 1; i <= n; i++){
cin >> e[i].l >> e[i].r;
e[i].id = i;
he.push_back({e[i].l, i + n});
he.push_back({e[i].r, i});
}
sort(he.begin(), he.end());
for(int i=0;i<=n+1;i++){
for(int j=0;j<18;j++)
nxt[i][j] = n + 1;
}
// cout<<"a\n";
int cur = -1;
for(int i = he.size()-1; i >= 0; i--){
// cout<<i<<' '<<he[i].first<<' '<<he[i].second<<' '<<cur<<endl;
if(he[i].second > n){
if(cur < 0 || e[he[i].second - n].r< e[cur].r)
cur = he[i].second - n;
}
else if(cur > 0){
nxt[he[i].second][0]=cur;
for(int j=1;j<18;j++){
nxt[he[i].second][j] = nxt[nxt[he[i].second][j - 1]][j - 1];
}
}
}
vector<int> ans;
set<event> s;
int sum = cnt(0, n + 1);
s.insert(e[0]);
s.insert(e[n + 1]);
for(int i = 1;i <= n && ans.size() < k; i++){
auto R=s.upper_bound(e[i]), L=R;
L--;
if(R->l < e[i].r || L->r > e[i].l)continue;
int x = cnt(L->id, R->id) - cnt(L->id, i) - cnt(i, R->id) - 1;
if(sum - x < k)continue;
sum -= x;
ans.push_back(i);
s.insert(e[i]);
}
if(ans.size() < k){
cout<<-1;
return 0;
}
for(int i:ans)cout<<i<<'\n';
cout<<'\n';
}
컴파일 시 표준 에러 (stderr) 메시지
event2.cpp: In function 'int main()':
event2.cpp:72:40: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
72 | for(int i = 1;i <= n && ans.size() < k; i++){
| ~~~~~~~~~~~^~~
event2.cpp:82:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
82 | if(ans.size() < k){
| ~~~~~~~~~~~^~~
# | 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... |