Submission #806491

#TimeUsernameProblemLanguageResultExecution timeMemory
806491vjudge1Event Hopping 2 (JOI21_event2)C++17
7 / 100
202 ms130372 KiB
#ifdef Home #define _GLIBCXX_DEBUG #endif // Home #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; struct node { int l, r, mx = 0; node *left = NULL, *right = NULL; node(int l, int r):l(l), r(r) {} }; void check(node *x) { if(x->left == NULL) { x->left = new node(x->l, (x->l + x->r) / 2); } if(x->right == NULL) { x->right = new node((x->l + x->r) / 2, x->r); } } void update(int pos, int val, node *x) { if(x->l + 1 == x->r) { x->mx = val; return; } check(x); pos < x->left->r ? update(pos, val, x->left) : update(pos, val, x->right) ; x->mx = max(x->left->mx, x->right->mx); } int find(int r, node *x) { if(r <= x->l) { return x->mx; } check(x); int res = 0; if(x->left->r > r && x->left->mx) { res = find(r, x->left); } if(x->right->mx) { res = max(res, find(r, x->right)); } return res; } main() { #ifdef Home freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // Home ios_base::sync_with_stdio(0); cin.tie(0); bool tsk = true; int n, k, mxr = -1; cin >> n >> k; vector < pair < int, int > > V(n); for(int i = 0; i < n; ++ i) { cin >> V[i].first >> V[i].second; tsk &= (!i || V[i - 1].first <= V[i].first); mxr = max(mxr, V[i].second); } if(tsk) { int t = 1; for(; t <= mxr; t <<= 1); node *root = new node(0, t); int dp[n + 10]; for(int i = n; i --> 0;) { dp[i] = 1 + find(V[i].second, root); update(V[i].first, dp[i], root); } if(root->mx < k) { cout << -1; return 0; } for(int i = 0, j = 0; i < n && k; ++ i) { if(j <= V[i].first && k <= dp[i]) { cout << i + 1 << '\n'; -- k; j = V[i].second; } } return 0; } }

Compilation message (stderr)

event2.cpp:55:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   55 | main() {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...