이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/***Farhan132***/
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC optimize("fast-math")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<ll> vll;
typedef pair<ll , ll> ii;
typedef vector< ii > vii;
typedef pair < pair < ll , ll > , pair < ll , ll > > cm;
typedef tuple < ll, ll, ll > tp;
#define ff first
#define ss second
#define pb push_back
#define in insert
#define f0(b) for(int i=0;i<(b);i++)
#define f00(b) for(int j=0;j<(b);j++)
#define f1(b) for(int i=1;i<=(b);i++)
#define f11(b) for(int j=1;j<=(b);j++)
#define f2(a,b) for(int i=(a);i<=(b);i++)
#define f22(a,b) for(int j=(a);j<=(b);j++)
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld", &a , &b)
#define pf(a) printf("%lld\n",a)
#define pff(a,b) printf("%lld %lld\n", a , b)
#define bug printf("**!\n")
#define mem(a , b) memset(a, b ,sizeof(a))
#define front_zero(n) __builtin_clzll(n)
#define back_zero(n) __builtin_ctzll(n)
#define total_one(n) __builtin_popcount(n)
#define clean fflush(stdout)
//const ll mod = (ll) 998244353;
const ll mod = (ll) 1e9 + 7;
const ll maxn = (ll)1e8 + 5;
const int nnn = 1048590;
//const int inf = numeric_limits<int>::max()-1;
const int inf = 1e9;
//const ll INF = numeric_limits<ll>::max()-1;
const ll INF = (ll)1e18;
ll dx[]={0,1,0,-1};
ll dy[]={1,0,-1,0};
ll dxx[]={0,1,0,-1,1,1,-1,-1};
ll dyy[]={1,0,-1,0,1,-1,1,-1};
bool USACO = 0;
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll N = 1e5 + 5;
struct seg_tree{
struct typo{
ii p;
void setup(ll n){
p = {n, 0};
}
};
vector < typo > b;
ll n;
void init(ll l, ll r, ll node){
b[node].setup(n);
return;
}
typo merge(typo a, typo b){
typo c;
c.p = min(a.p , b.p);
return c;
}
void build(ll l, ll r, ll node){
if(l == r){
init(l,r,node);
return;
}
ll mid = (l + r)/2;
ll n1 = 2*node;
ll n2 = n1 + 1;
build(l, mid , n1);
build(mid+1, r, n2);
b[node] = merge(b[n1] , b[n2]);
return;
}
void build(ll _n){
n = _n;
b.resize(4*n);
build(1,n,1); // optional
}
void up(ll l, ll r, ll node, ll x, ll y, ii v){
if(y < l || x > r) return;
if(x <= l && y >= r){
b[node].p = min(b[node].p, v);
return;
}
ll mid = (l + r)/2;
ll n1 = 2*node;
ll n2 = n1 + 1;
up(l , mid , n1 , x , y , v);
up(mid + 1, r, n2, x, y , v);
b[node] = merge(b[n1] , b[n2]);
return;
}
void up(ll x, ii v){
up(1,n,1,x,x,v);
return;
}
typo get(ll l, ll r, ll node, ll x, ll y){
if(y < l || x > r) return {{n, 0}};
if(x <= l && y >= r){
return b[node];
}
ll mid = (l + r)/2;
ll n1 = 2*node;
ll n2 = n1 + 1;
return merge(get(l , mid , n1 , x , y) , get(mid + 1, r , n2 , x , y));
}
ll get(ll l, ll r){
return get(1,n,1,l,r).p.ss;
}
/* Final Check!!!
1. Typo, Okay?
2. Init Okay? (Build!!)
3. Merge, Okay?
4. Lazy Needed ? YES | NO (if NO, REMOVE anything related to lazy prop)
5. Dummy?
6. Check Update, Get, etc function's Merge, Lazy Prop , Init :D
7, Even after a WA, check for possible Out Of Bound/MLE/RE cases
*/
}T;
ll par[20][N];
ll l[N], r[N];
ll range(ll x, ll y){
if(y < x) return 0;
ll ans = 0;
auto cur = T.get(x, y);
if(!cur || r[cur] > y) return 0;
ans++;
for(ll i = 19; i >= 0; i--){
if(r[par[i][cur]] <= y) ans += (1 << i), cur = par[i][cur];
}
return ans;
}
void solve(){
ll n , k;
cin >> n >> k;
vector < tuple < ll , ll , ll > > v;
vector < ll > idx;
for(ll i = 1; i <= n; i++){
cin >> l[i] >> r[i];
r[i]--;
idx.pb(l[i]);
idx.pb(r[i]);
idx.pb(r[i]+1);
}
idx.pb(1e9 + 10);
sort(idx.begin(), idx.end());
idx.erase(unique(idx.begin(), idx.end()), idx.end());
ll m = idx.size();
T.build(m);
l[n+1] = r[n+1] = 1e9 + 10;
for(ll i = 1; i <= n+1; i++){
l[i] = lower_bound(idx.begin(), idx.end(), l[i]) - idx.begin() + 1;
r[i] = lower_bound(idx.begin(), idx.end(), r[i]) - idx.begin() + 1;
if(i == n + 1) continue;
v.pb({l[i], 1, i});
v.pb({r[i]+1, 0, i});
T.up(l[i], {r[i], i});
}
sort(v.rbegin(), v.rend());
par[0][n+1] = n + 1;
set < ii > s; s.in({r[n+1], n+1});
for(auto [val, t, i] : v){
if(t) s.in({r[i] , i});
else{
par[0][i] = (*s.begin()).ss;
}
}
set < tuple < ll , ll , ll > > t;
for(ll i = 1; i < 20; i++){
for(ll j = 1; j <= n+1; j++){
par[i][j] = par[i-1][par[i-1][j]];
}
}
ll ans = 1;
s.clear();
auto cur = T.get(1, m);
for(ll i = 19; i >= 0; i--){
if(r[par[i][cur]] < m) ans += (1 << i), cur = par[i][cur];
}
if(ans < k){
cout << "-1\n"; return;
}
s.in({1, m-1});
vector < ll > res;
for(ll i = 1; i <= n; i++){
auto pp = s.upper_bound({l[i], 1e9});
if(pp == s.begin()) continue;
pp--;
auto [L , R] = *pp;
if(!(L <= l[i] && r[i] <= R)) continue;
ans += range(L, l[i]-1) + range(r[i]+1, R) - range(L, R) + 1;
if(ans < k){
ans -= range(L, l[i]-1) + range(r[i]+1, R) - range(L, R) + 1;
continue;
}
s.erase({L, R});
if(L <= l[i]-1) s.in({L, l[i]-1});
if(r[i]+1 <= R) s.in({r[i]+1, R});
res.pb(i);
}
while(res.size() > k) res.pop_back();
for(auto u : res) cout << u << '\n';
return;
}
int main() {
#ifdef LOCAL
freopen("in", "r", stdin);
freopen("out", "w", stdout);
auto start_time = clock();
#else
ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#endif
ll T = 1, CT = 0; //cin >> T;
while(T--){
solve();
}
#ifdef LOCAL
auto end_time = clock();
cerr<< "Execution time: "<<(end_time - start_time)*(int)1e3/CLOCKS_PER_SEC<<" ms\n";
#endif
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
event2.cpp: In function 'void solve()':
event2.cpp:255:20: 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]
255 | while(res.size() > k) res.pop_back();
| ~~~~~~~~~~~^~~
event2.cpp: In function 'int main()':
event2.cpp:272:15: warning: unused variable 'CT' [-Wunused-variable]
272 | ll T = 1, CT = 0; //cin >> T;
| ^~
# | 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... |