제출 #417125

#제출 시각아이디문제언어결과실행 시간메모리
417125pavementEvent Hopping 2 (JOI21_event2)C++17
1 / 100
803 ms103800 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #ifdef _WIN32 #define getchar_unlocked _getchar_nolock #endif #define int long long #define mp make_pair #define mt make_tuple #define pb push_back #define ppb pop_back #define eb emplace_back #define g0(a) get<0>(a) #define g1(a) get<1>(a) #define g2(a) get<2>(a) #define g3(a) get<3>(a) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef double db; typedef long long ll; typedef long double ld; typedef pair<int, int> ii; typedef tuple<int, int, int> iii; typedef tuple<int, int, int, int> iiii; typedef tree<iii, null_type, greater<iii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; int N, K, L[500005], R[500005], A[500005], ft2[500005], ft3[500005]; vector<int> ans, v; set<ii> cfm, ft[500005]; set<iii> S; vector<iii> tmp; bool intersect(int a, int b, int c, int d) { if (a > c) swap(a, c), swap(b, d); return b > c; } inline int ls(int x) { return x & -x; } ii qry(int p) { ii ret = mp(LLONG_MAX, LLONG_MAX); for (; p <= 2 * N; p += ls(p)) if (!ft[p].empty()) ret = min(ret, *ft[p].begin()); return ret; } void potadd(int x) { for (int p = L[x]; p; p -= ls(p)) ft[p].emplace(R[x], x); } void potdel(int x) { for (int p = L[x]; p; p -= ls(p)) { assert(ft[p].find(mp(R[x], x)) != ft[p].end()); ft[p].erase(mp(R[x], x)); } } int ft2_qry(int p) { int r = 0; for (; p; p -= ls(p)) r += ft2[p]; return r; } void ft2_upd(int p, int v) { for (; p <= 2 * N; p += ls(p)) ft2[p] += v; } int ft3_qry(int p) { p = 2 * N - p + 1; int r = 0; for (; p; p -= ls(p)) r += ft3[p]; return r; } void ft3_upd(int p, int v) { p = 2 * N - p + 1; for (; p <= 2 * N; p += ls(p)) ft3[p] += v; } void addseg(int x) { int lim; auto it = S.lower_bound(mt(R[x], 0ll, 0ll)); if (it == S.end()) lim = LLONG_MAX; else lim = g0(*it); vector<set<iii>::iterator> todel; while (1) { if (it == S.begin()) break; --it; if (intersect(g0(*it), g1(*it), L[x], R[x])) { ft2_upd(g1(*it), -1); ft3_upd(g0(*it), -1); potadd(g2(*it)); todel.pb(it); } else break; } for (auto i : todel) S.erase(i); ft2_upd(R[x], 1); ft3_upd(L[x], 1); S.emplace(L[x], R[x], x); potdel(x); auto tmp = qry(R[x]); if (tmp.second != LLONG_MAX && tmp.first <= lim) addseg(tmp.second); } main() { ios::sync_with_stdio(0); cin.tie(0); cin >> N >> K; for (int i = 1; i <= N; i++) cin >> L[i] >> R[i], v.pb(L[i]), v.pb(R[i]); sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); for (int i = 1; i <= N; i++) { L[i] = lower_bound(v.begin(), v.end(), L[i]) - v.begin() + 1; R[i] = lower_bound(v.begin(), v.end(), R[i]) - v.begin() + 1; tmp.eb(R[i], L[i], i); } sort(tmp.begin(), tmp.end()); int lastr = LLONG_MIN; for (int i = 1; i <= N; i++) potadd(i); for (auto [r, l, i] : tmp) { if (lastr <= l) { addseg(i); lastr = r; } } if (S.size() < K) return cout << "-1\n", 0; for (int i = 1; i <= N; i++) { auto it = cfm.lower_bound(mp(R[i], 0ll)); bool yep = 1; if (it != cfm.begin()) { --it; if (intersect(it->first, it->second, L[i], R[i])) yep = 0; } if (!yep) continue; A[i] = ft2_qry(L[i]) + ft3_qry(R[i]) + 1; auto tmp = qry(R[i]); auto it2 = S.lower_bound(mt(R[i], 0ll, 0ll)); if (tmp.second != LLONG_MAX && (it2 == S.end() || tmp.first <= g0(*it2))) A[i]++; if (A[i] >= K) { cfm.emplace(L[i], R[i]); ans.pb(i); addseg(i); } } assert(ans.size() >= K); for (int i = 0; i < K; i++) cout << ans[i] << '\n'; }

컴파일 시 표준 에러 (stderr) 메시지

event2.cpp:107:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  107 | main() {
      | ^~~~
event2.cpp: In function 'int main()':
event2.cpp:128:15: warning: comparison of integer expressions of different signedness: 'std::set<std::tuple<long long int, long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
  128 |  if (S.size() < K) return cout << "-1\n", 0;
      |      ~~~~~~~~~^~~
In file included from /usr/include/c++/10/ext/pb_ds/detail/pat_trie_/pat_trie_.hpp:45,
                 from /usr/include/c++/10/ext/pb_ds/detail/container_base_dispatch.hpp:90,
                 from /usr/include/c++/10/ext/pb_ds/assoc_container.hpp:48,
                 from event2.cpp:2:
event2.cpp:147:20: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
  147 |  assert(ans.size() >= K);
      |         ~~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...