Advertisement
Galebickosikasa

Untitled

Oct 12th, 2020
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
  2. #pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx")
  3. // #pragma comment(linker, "/stack:200000000"]
  4.  
  5. #include <iostream>
  6. #include <vector>
  7. #include <cmath>
  8. #include <algorithm>
  9. #include <unordered_set>
  10. #include <unordered_map>
  11. #include <set>
  12. #include <map>
  13. #include <queue>
  14. #include <deque>
  15. #include <bitset>
  16. #include <stack>
  17. #include <random>
  18. #include <fstream>
  19. #include <sstream>
  20. #include <chrono>
  21.  
  22. #define fi first
  23. #define se second
  24. #define pb push_back
  25. #define ll long long
  26. #define ld long double
  27. #define hm unordered_map
  28. #define pii pair<int, int>
  29. #define sz(a) (int)a.size()
  30. #define all(a) a.begin(), a.end()
  31. #define cinv(v) for (auto& x: v) cin >> x
  32. #define fr(i, n) for (int i = 0; i < n; ++i)
  33. #define fl(i, l, n) for (int i = l; i < n; ++i)
  34.  
  35. // #define int ll
  36.  
  37. template <typename T1, typename T2> inline bool chkmin(T1 &x, const T2 &y) {if (x > y) {x = y; return 1;} return 0;}
  38. template <typename T1, typename T2> inline bool chkmax(T1 &x, const T2 &y) {if (x < y) {x = y; return 1;} return 0;}
  39.  
  40. using namespace std;
  41.  
  42. #ifdef __LOCAL
  43. #define dbg(x) cerr << #x << " : " << x << '\n'
  44. const int maxn = 20;
  45. #else
  46. #define dbg(x)
  47. const int maxn = 3e5 + 20;
  48. #endif
  49.  
  50. //tg: @galebickosikasa
  51.  
  52. ostream& operator << (ostream& out, vector<int>& v) {
  53. for (auto& x: v) out << x << ' ';
  54. return out;
  55. }
  56.  
  57. ostream& operator << (ostream& out, pii& v) {
  58. out << v.fi << ", " << v.se;
  59. return out;
  60. }
  61.  
  62. ostream& operator << (ostream& out, vector<pii>& v) {
  63. for (auto& x: v) out << x << " ";
  64. return out;
  65. }
  66.  
  67. istream& operator >> (istream& in, pii& a) {
  68. in >> a.fi >> a.se;
  69. return in;
  70. }
  71.  
  72. const ll inf = (ll) 2e9;
  73. const ld pi = asin (1) * 2;
  74. const ld eps = 1e-8;
  75. const ll mod = (ll)1e9 + 7;
  76. const ll ns = 97;
  77.  
  78. mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
  79.  
  80. struct qs {
  81. int l, r, i;
  82.  
  83. bool operator < (const qs& other) const {
  84. if (r != other.r) return r < other.r;
  85. return l < other.l;
  86. }
  87. };
  88.  
  89. vector<int> g[maxn];
  90. int m;
  91.  
  92. inline int check (vector<qs>& goo, int x) {
  93. fr (i, m) g[i].clear ();
  94. set <int> s;
  95. fr (i, m) s.insert (i);
  96. for (auto& r: goo) {
  97. auto it = s.lower_bound (r.l);
  98. if (it != s.end () && *it <= r.r) {
  99. g[*it].pb (r.i);
  100. if (sz (g[*it]) >= x) {
  101. s.erase (it);
  102. }
  103. } else return 0;
  104. }
  105. return 1;
  106. }
  107.  
  108. inline int BS (vector<qs>& goo) {
  109. int l = 0, r = (int)3e5;
  110. while (r - l > 1) {
  111. int m = (r + l) / 2;
  112. if (check (goo, m)) r = m;
  113. else l = m;
  114. }
  115. check (goo, r);
  116. return r;
  117. }
  118.  
  119. signed main () {
  120. ios_base::sync_with_stdio(false);
  121. cin.tie(nullptr);
  122. cout.tie(nullptr);
  123. int n;
  124. cin >> n >> m;
  125. vector<qs> goo (n);
  126. for (auto& x: goo) cin >> x.l >> x.r;
  127. for (auto& x: goo) --x.l, --x.r;
  128. fr (i, n) goo[i].i = i;
  129. sort (all (goo));
  130. int mx = BS (goo);
  131. check (goo, mx);
  132. cout << mx << '\n';
  133. fr (i, m) {
  134. cout << sz (g[i]) << ' ';
  135. for (auto& x: g[i]) cout << x + 1 << ' ';
  136. cout << '\n';
  137. }
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144. }
  145.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement