이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusive
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }
using ll=long long;
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,ll>;
long long LLINF = 1e18;
int INF = 1e9+1e6;
#define MAXN (100006)
int n,k,p[MAXN][17],co;
pi A[MAXN];
vector<spi> v, u;
set<dpi> events;
ll solve(ll x,ll y) {
// bsearch for last event that ends before y
ll st=-1,en=siz(v);
while(en-st>1) {
ll mid=(st+en)>>1;
if(v[mid].s.s <= y) st = mid;
else en = mid;
}
if(st == -1 || v[st].s.f < x) return 0;
ll ans = 1, i = v[st].f;
// DEC(j,16,0) if(p[i][j] != -1 && A[p[i][j]].f >= x) i = p[i][j], ans += 1<<j;
DEC(i,st-1,0) {
if(v[i].s.f < x) break;
++ ans;
}
return ans;
}
int main() {
FAST
cin>>n>>k;
FOR(i,1,n)cin>>A[i].f>>A[i].s, v.eb(i, A[i]);
sort(all(v), [](spi x,spi y){return pi(x.s.f,-x.s.s)<pi(y.s.f,-y.s.s);});
DEC(i,n-1,0) if(u.empty() || u.back().s.s > v[i].s.s) {
u.eb(v[i]);
}
v.clear(); while(u.size()) v.eb(u.back()), u.pop_back();
deque<int> dq;
for(auto i:v) {
if(dq.empty()) {
p[i.f][0] = -1;
} else {
while(dq.size() > 1 && A[dq[1]].s <= i.s.f) dq.pop_front();
p[i.f][0] = dq[0];
}
dq.eb(i.f);
}
FOR(j,1,16) FOR(i,1,n) if(p[i][j-1] != -1) p[i][j]=p[p[i][j-1]][j-1]; else p[i][j] = -1;
events.ins(dpi(pi(0, 1), -1)), events.ins(dpi(pi(1e9, int(1e9) + 1), -1));
co = solve(1, 1e9);
if(co < k) {
cout<<"-1\n";
return 0;
}
FOR(i,1,n) {
auto it = prev(events.upper_bound(dpi(pi(A[i].f, LLINF),LLINF)));
if(it->f.s > A[i].f) continue;
++ it;
if(it->f.f < A[i].s) continue;
int tmp = solve(prev(it)->f.s, it->f.f);
int wow = solve(prev(it)->f.s, A[i].f) + solve(A[i].s, it->f.f) + 1;
if(co - tmp + wow < k) continue;
co += wow - tmp;
events.ins(dpi(A[i], i));
if(events.size() == k+2) break;
}
if(events.size() != k+2) {
assert(0);
} else {
vector<int> ind;
for(auto i:events) if(i.s != -1) ind.eb(i.s);
sort(all(ind));
for(auto i:ind) cout<<i<<'\n';
}
}
컴파일 시 표준 에러 (stderr) 메시지
event2.cpp: In function 'll solve(ll, ll)':
event2.cpp:42:14: warning: unused variable 'i' [-Wunused-variable]
42 | ll ans = 1, i = v[st].f;
| ^
event2.cpp: In function 'int main()':
event2.cpp:86:20: warning: comparison of integer expressions of different signedness: 'std::set<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
86 | if(events.size() == k+2) break;
| ~~~~~~~~~~~~~~^~~~~~
event2.cpp:88:19: warning: comparison of integer expressions of different signedness: 'std::set<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
88 | if(events.size() != k+2) {
| ~~~~~~~~~~~~~~^~~~~~
# | 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... |