이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<float.h>
#include<limits.h>
#include <cassert>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric> //gcd(a,b)
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-loops")
using namespace std;
#define int long long
#define double long double
const int mod=998244353,mxn=2e5+5,lg=22,inf=1e18,minf=-1e18,Mxn=100000;
int n,k,sz;
struct info{int l,r,posl,posr,realid,id;};
bool cmp(info a,info b){return a.r<b.r;}
vector<info>v;
vector<int>compress;
int up[mxn+10][lg+5];
int32_t main(){
fastio
cin>>n>>k;
for(int i=0;i<n;i++){
int a,b;cin>>a>>b;
v.pb({a,b,-1,-1,i,i});
compress.pb(a);
compress.pb(b);
}
sort(all(compress));
unique(all(compress));
for(auto &i:v){
i.posl=lb(all(compress),i.l)-compress.begin()+1;
i.posr=lb(all(compress),i.r)-compress.begin()+1;
}
int cur=0;
sz=compress.size();
vector<info>v2(all(v));
sort(all(v),cmp);
for(int i=0;i<n;i++)v2[v[i].realid].id=i;
int curcnt=0,at=0;
for(int i=0;i<=lg;i++)for(int j=0;j<n;j++)up[j][i]=-1;
for(int i=0;i<n;i++)while(cur<n&&v[cur].r<=v[i].l){
up[cur][0]=i;
cur++;
}
for(int j=1;j<=lg;j++)for(int i=0;i<n;i++)if(up[i][j-1]!=-1)up[i][j]=up[up[i][j-1]][j-1];
for(int i=lg;i>=0;i--)if(up[at][i]!=-1)at=up[at][i],curcnt+=(1ll<<i);
vector<int>ans;
set<int>st;
for(int i=0;i<n;i++){
int upb=inf,l,r;
auto it=st.lb(v2[i].id);
if(it==st.begin())at=0;
else{
it--;
at=(*it);
it++;
}
if(it!=st.begin()&&v[at].posr>v2[i].posl)continue;
l=at;
int add=0;
for(int j=lg;j>=0;j--)if(up[at][j]!=-1&&v[up[at][j]].posr<=v2[i].posl)at=up[at][j],add+=(1ll<<j);
if(it!=st.end())r=(*it);
else r=n-1;
at=v2[i].id;
if(it!=st.end()&&v[at].posr>v[r].posl)continue;
for(int j=lg;j>=0;j--)if(up[at][j]!=-1&&v[up[at][j]].posr<=v[r].posl)at=up[at][j],add+=(1ll<<j);
for(int j=lg;j>=0;j--)if(up[l][j]!=-1&&v[up[l][j]].posr<=v[r].posl)l=up[l][j],add-=(1ll<<j);
if(curcnt+add+1<k)continue;
curcnt+=add+1;
ans.pb(i+1);
st.insert(v2[i].id);
if(ans.size()==k)break;
}
if(ans.size()<k)cout<<-1<<'\n';
else for(int i=0;i<k;i++)cout<<ans[i]<<"\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
event2.cpp: In function 'int32_t main()':
event2.cpp:97:16: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
97 | if(ans.size()==k)break;
| ~~~~~~~~~~^~~
event2.cpp:75:7: warning: unused variable 'upb' [-Wunused-variable]
75 | int upb=inf,l,r;
| ^~~
event2.cpp:99:15: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
99 | if(ans.size()<k)cout<<-1<<'\n';
| ~~~~~~~~~~^~
# | 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... |