이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pl = pair<ll,ll>;
using ppl = pair<pl,pl>;
const ll lim=2e5+5, b = 6005;//b is the block size
ll nxt[lim], jumps[lim], out[lim];
set<pl>s;
ll journey(ll start){
auto it=s.lower_bound(make_pair(start,-1ll));
ll block = it->first;//block is the first position we CANNOT go
ll ans=0;
ll pos = start;
while(out[pos]<block){
ans += jumps[pos];
pos = out[pos];
}
while(nxt[pos]<block){
ans ++;
pos = nxt[pos];
}
return ans;
}
int main(){
ios_base::sync_with_stdio(0),cin.tie(0);
ll n,k;
cin>>n>>k;
vector<ll>dsc;
unordered_map<ll,ll>d;
vector<pl>v;
for(int i=0;i<n;i++){
ll a,b;
cin>>a>>b;
v.emplace_back(a,b);
dsc.push_back(a);
dsc.push_back(b);
}
sort(dsc.begin(),dsc.end());
dsc.erase(unique(dsc.begin(),dsc.end()),dsc.end());
for(int i=0;i<(int)dsc.size();i++)d[dsc[i]]=i+1;
for(auto &p:v)p.first=d[p.first],p.second=d[p.second];
ll l = dsc.size();
fill(nxt,nxt+l+2,1e18);
for(auto p:v)nxt[p.first]=min(nxt[p.first],p.second);
for(int i=l;i>=1;i--)nxt[i]=min(nxt[i],nxt[i+1]);
for(int i=1;i<=l;i+=b){
int last = min(l,i+l-1);
for(int j=last;j>=i;j--){
if(nxt[j]>last){
jumps[j]=0;
out[j]=nxt[j];
}
else{
jumps[j]=jumps[nxt[j]]+1;
out[j]=out[nxt[j]];
}
}
}
s.emplace(0,0);
s.emplace(l+1,l+1);
ll cur = journey(1);
if(cur<k){
cout<<"-1\n";
return 0;
}
vector<ll>ans;
for(int i=0;i<n&&ans.size()<k;i++){
auto it=s.lower_bound(make_pair(v[i].first,-1ll));
if(it->first<v[i].second)continue;
it--;
if(it->second>v[i].first)continue;
ll org_start = it->second;
ll org_this_seg = journey(org_start);
s.insert(v[i]);
ll new_this_seg = journey(org_start) + journey(v[i].second);
if(cur - org_this_seg + new_this_seg + s.size() >=k){
cur -= org_this_seg;
cur += new_this_seg;
ans.push_back(i+1);
}
else{
s.erase(v[i]);
}
}
for(auto x:ans)cout<<x<<"\n";
//for(int i=1;i<=l;i++)cout<<jumps[i]<<" ";
//for(auto x:v)cout<<x.first<<" "<<x.second<<"\n";
//cout<<"\n\n";
}
컴파일 시 표준 에러 (stderr) 메시지
event2.cpp: In function 'int main()':
event2.cpp:69:29: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
69 | for(int i=0;i<n&&ans.size()<k;i++){
| ~~~~~~~~~~^~
event2.cpp:78:51: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'll' {aka 'long long int'} [-Wsign-compare]
78 | if(cur - org_this_seg + new_this_seg + s.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... |