Submission #417285

#TimeUsernameProblemLanguageResultExecution timeMemory
417285maomao90Event Hopping 2 (JOI21_event2)C++17
7 / 100
234 ms28452 KiB
#include <bits/stdc++.h> using namespace std; template <class T> inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;} template <class T> inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;} #define REP(i, s, e) for (int i = s; i < e; i++) #define RREP(i, s, e) for (int i = s; i >= e; i--) typedef long long ll; typedef long double ld; #define MP make_pair #define FI first #define SE second typedef pair<int, int> ii; typedef pair<ll, ll> pll; #define MT make_tuple typedef tuple<int, int, int> iii; #define ALL(_a) _a.begin(), _a.end() #define pb emplace_back typedef vector<int> vi; typedef vector<ll> vll; typedef vector<ii> vii; #define INF 1000000005 #define LINF 1000000000000000005 #define MOD 1000000007 #define MAXN 200005 int n, k; ii lr[MAXN]; vi events; set<int> st; map<int, int> mp; int d[MAXN]; vi ans; int v[MAXN * 4]; void update(int p, int x, int u, int lo, int hi) { int mid = lo + hi >> 1; if (lo == hi) { v[u] = x; return; } int lc = u * 2, rc = u * 2 + 1; if (p <= mid) update(p, x, lc, lo, mid); else update(p, x, rc, mid + 1, hi); v[u] = max(v[lc], v[rc]); } void update(int p, int x) { update(p, x, 1, 0, 2 * n); } int query(int s, int e, int u, int lo, int hi) { if (lo >= s && hi <= e) { return v[u]; } int mid = lo + hi >> 1; int lc = u * 2, rc = u * 2 + 1; if (e <= mid) return query(s, e, lc, lo, mid); else if (s > mid) return query(s, e, rc, mid + 1, hi); else return max(query(s, e, lc, lo, mid), query(s, e, rc, mid + 1, hi)); } int query(int s, int e) { return query(s, e, 1, 0, 2 * n); } int main() { scanf("%d%d", &n, &k); REP (i, 0, n) { scanf("%d%d", &lr[i].FI, &lr[i].SE); st.insert(lr[i].FI); st.insert(lr[i].SE); } int ptr = 0; for (auto i : st) { mp[i] = ptr++; } REP (i, 0, n) { lr[i].FI = mp[lr[i].FI]; lr[i].SE = mp[lr[i].SE]; } REP (i, 0, n) { if (events.empty() || lr[events.back()].FI != lr[i].FI || lr[events.back()].SE > lr[i].SE) { mp[lr[i].FI] = events.size(); events.pb(i); } } RREP (i, events.size() - 1, 0) { int l = lr[events[i]].FI, r = lr[events[i]].SE; d[i] = query(r, 2 * n) + 1; update(l, d[i]); } int prvr = -1; REP (i, 0, events.size()) { if (k == 0) break; int l = lr[events[i]].FI, r = lr[events[i]].SE; if (d[i] >= k && l >= prvr) { ans.pb(events[i]); prvr = r; k--; } } if (ans.empty()) { printf("-1\n"); return 0; } else { for (int i : ans) { printf("%d\n", i + 1); } } return 0; } /* 4 2 1 4 3 5 4 9 7 10 12 3 1 4 1 8 1 3 1 2 1 4 3 8 3 5 3 9 6 11 6 10 6 12 6 7 6 1 1 7 2 5 2 4 4 8 4 7 8 9 6 4 1 3 1 2 2 4 4 5 5 6 6 7 */

Compilation message (stderr)

event2.cpp: In function 'void update(int, int, int, int, int)':
event2.cpp:40:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   40 |  int mid = lo + hi >> 1;
      |            ~~~^~~~
event2.cpp: In function 'int query(int, int, int, int, int)':
event2.cpp:57:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   57 |  int mid = lo + hi >> 1;
      |            ~~~^~~~
event2.cpp: In function 'int main()':
event2.cpp:8:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define REP(i, s, e) for (int i = s; i < e; i++)
......
   95 |  REP (i, 0, events.size()) {
      |       ~~~~~~~~~~~~~~~~~~~               
event2.cpp:95:2: note: in expansion of macro 'REP'
   95 |  REP (i, 0, events.size()) {
      |  ^~~
event2.cpp:68:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |  scanf("%d%d", &n, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~
event2.cpp:70:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |   scanf("%d%d", &lr[i].FI, &lr[i].SE);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...