이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 201010
#define MAXS 20
#define INF 1000000000000000001
#define bb ' '
#define ln '\n'
#define Ln '\n'
int S[MAX];
int E[MAX];
vector<int> st[MAX];
int sp[MAX][MAXS];
int getnum(int l, int r) {
int ans = 0;
int i;
for (i = MAXS - 1; i >= 0; i--) if (sp[l][i] <= r) l = sp[l][i], ans |= (1 << i);
return ans;
}
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
int N, K;
cin >> N >> K;
int i;
vector<int> v;
for (i = 1; i <= N; i++) {
cin >> S[i] >> E[i];
v.push_back(S[i]);
v.push_back(E[i]);
}
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
for (i = 1; i <= N; i++) {
S[i] = lower_bound(v.begin(), v.end(), S[i]) - v.begin() + 1;
E[i] = lower_bound(v.begin(), v.end(), E[i]) - v.begin() + 1;
}
int X = v.size();
for (i = 1; i <= N; i++) st[S[i]].push_back(E[i]);
int mn = X + 1;
for (i = 0; i < MAXS; i++) sp[X + 1][i] = X + 1;
for (i = X; i >= 1; i--) {
for (auto v : st[i]) mn = min(mn, v);
sp[i][0] = mn;
}
int j;
for (i = 1; i < MAXS; i++) for (j = 1; j <= X; j++) sp[j][i] = sp[sp[j][i - 1]][i - 1];
set<pii> st;
st.insert(pii(1, X));
vector<int> ans;
int sum = getnum(1, X);
for (i = 1; i <= N; i++) {
int s = S[i], e = E[i];
auto it = st.lower_bound(pii(s + 1, -1e9));
if (it-- == st.begin()) continue;
auto [l, r] = *it;
if (!(l <= s && e <= r)) continue;
int delta = -getnum(l, r) + getnum(l, s) + getnum(e, r) + 1;
if (sum + delta < K) continue;
sum += delta;
st.erase(it);
st.emplace(l, s);
st.emplace(e, r);
ans.push_back(i);
if (ans.size() == K) break;
}
if (ans.size() < K) {
cout << -1 << ln;
return 0;
}
for (auto v : ans) cout << v << ln;
}
컴파일 시 표준 에러 (stderr) 메시지
event2.cpp: In function 'int main()':
event2.cpp:70:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
70 | if (ans.size() == K) break;
| ~~~~~~~~~~~^~~~
event2.cpp:72:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
72 | 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... |