比赛 不平凡的世界 评测结果 AAAAAAAAAA
题目名称 不平凡的boss 最终得分 100
用户昵称 膜拜神犇王梦迪 运行时间 1.582 s
代码语言 C++ 内存使用 2.69 MiB
提交时间 2015-11-05 11:49:04
显示代码纯文本
  1. #include <algorithm>
  2. #include <cstdio>
  3. #include <queue>
  4. #include <set>
  5. using namespace std;
  6. const int kN = 1e5+10;
  7. const int INF = 1e9+10;
  8. int N;
  9. struct Mon {
  10. int a, b, c;
  11. bool operator < (const Mon & m) const {
  12. if (a != m.a) return a < m.a;
  13. if (b != m.b) return b < m.b;
  14. if (c != m.c) return c < m.c;
  15. return false;
  16. }
  17. }mon[kN];
  18.  
  19.  
  20. int renb[kN], tmpbcnt[kN];
  21.  
  22. struct Solver2 {
  23. int bval[kN];
  24. bool inq[kN];
  25. set<int> q;
  26. priority_queue<pair<int, pair<int, int> > > ans;
  27. int find_pre(set<int>::iterator it) {
  28. if (it == q.begin()) return 0;
  29. --it;
  30. return *it;
  31. }
  32. int find_suf(set<int>::iterator it) {
  33. // printf("i = %d\n", *it);
  34. ++it;
  35. if (it == q.end()) return 0;
  36. // printf("suf = %d\n", *it);
  37. return *it;
  38. }
  39. void insert(int a, int b) {
  40. bval[a] = b;
  41. set<int>::iterator ait = q.insert(a).first; inq[a] = true;
  42. int r = find_suf(ait);
  43. if (r && b <= bval[r]) {
  44. inq[a] = false;
  45. q.erase(ait);
  46. return;
  47. }
  48. int l = find_pre(ait);
  49. while (l && bval[l] <= b) {
  50. inq[l] = false;
  51. q.erase(q.find(l));
  52. l = find_pre(ait);
  53. }
  54. ans.push(make_pair(-(renb[l]+bval[a]), make_pair(l, a)));
  55. ans.push(make_pair(-(renb[a]+bval[r]), make_pair(a, r)));
  56. }
  57. int get() {
  58. while(true) {
  59. pair<int, pair<int, int> > t = ans.top();
  60. int ret = t.first, i = t.second.first, j = t.second.second;
  61. // printf("find_suf[%d] = %d\n", i, find_suf(q.find(i)));
  62. if (inq[i] && inq[j] && find_suf(q.find(i)) == j) {
  63. return -ret;
  64. } else {
  65. ans.pop();
  66. }
  67. }
  68. }
  69. }sol2;
  70.  
  71. int main() {
  72. freopen("playwithboss.in", "r", stdin);
  73. freopen("playwithboss.out", "w", stdout);
  74. scanf("%d", &N);
  75. for (int i = 1; i <= N; i++) {
  76. scanf("%d %d %d", &mon[i].a, &mon[i].b, &mon[i].c);
  77. renb[i] = mon[i].b;
  78. }
  79. sort(renb+1, renb+1+N);
  80. for (int i = 1; i <= N; i++) {
  81. mon[i].b = lower_bound(renb+1, renb+1+N, mon[i].b) - renb;
  82.  
  83. if (tmpbcnt[mon[i].b]) mon[i].b = ++tmpbcnt[mon[i].b];
  84. else tmpbcnt[mon[i].b] = mon[i].b;
  85. }
  86. sort(mon+1, mon+1+N);
  87. sol2.insert(0, INF);
  88. sol2.insert(N+1, 0);
  89. int ans = mon[N].a;
  90. for (int i = N; i >= 1; i--) {
  91. sol2.insert(mon[i].b, mon[i].c);
  92. ans = min(ans, mon[i-1].a + sol2.get());
  93. }
  94. printf("%d\n", ans);
  95. return 0;
  96. }