Educational Codeforces Round 112 (Rated for Div. 2) E. Boring Segments
阿新 • • 發佈:2021-08-07
比賽中板子錯了 心態炸裂 (比正解多了個二分 對了也是tle
但是 顯然可以不用二分 直接雙指標瞎搞,按區間長度排序,雙指標r++就+1,l++就-1.
我看見 你const int maxn = 1e6 + 7; int n, t, m; struct line { int l, r, w; } ls[maxn]; bool cmp(line l1, line l2) { return l1.w < l2.w; } int solve_() { build(1, 1, m); int l = 1, r = 1, ans = 1e7; updata(1, ls[1].l, ls[1].r, 1); for (; l <= n;) { while (query(1, 1, m) == 0 && r < n) ++r, updata(1, ls[r].l, ls[r].r, 1); if (query(1, 1, m)) ans = min(ans, ls[r].w - ls[l].w); updata(1, ls[l].l, ls[l].r, -1); l++; } return ans; } void solve() { scanf("%d%d", &n, &m); if (n == 1) { cout << 0 << endl; return; } for (int i = 1; i <= n; i++) { scanf("%d%d%d", &ls[i].l, &ls[i].r, &ls[i].w); if (ls[i].l != 1) ls[i].l++; } sort(ls + 1, ls + 1 + n, cmp); cout << solve_() << endl; }