QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#618706#2559. Endless RoadMilkcat2009WA 0ms38088kbC++144.1kb2024-10-07 07:39:332024-10-07 07:39:34

Judging History

你现在查看的是最新测评结果

  • [2024-10-07 07:39:34]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:38088kb
  • [2024-10-07 07:39:33]
  • 提交

answer

#include <bits/stdc++.h>
#define REP(i, l, r) for (int i = (l); i <= (r); ++ i)
#define DEP(i, r, l) for (int i = (r); i >= (l); -- i)
#define fi first
#define se second
#define pb emplace_back
#define mems(x, v) memset((x), (v), sizeof(x))
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
using namespace std;
namespace DS {
	template <typename T>
	struct Fenwick {
		int n; vector<T> c;
		void resize(int x) { n = x, c.resize(n + 1); }
		void clear() { c.clear(), n = 0; }
		void reset() { c.assign(n + 1, 0); }
		void upd(int x, T val) { assert(x > 0); for (; x <= n; x += x & -x) c[x] += val; }
		T ask(int x) { T r = 0; for (x = min(x, n); x; x -= x & -x) r += c[x]; return r; }
	};
}
namespace Milkcat {
	typedef long long LL;
	typedef pair<LL, LL> pii;
	const int N = 1e6 + 5;
	int n, m, ct, rt, L[N], R[N], o[N], dg[N], vs[N], v[N], ls[N << 1], rs[N << 2];
	vector<int> t, G[N]; DS::Fenwick<int> T; set<pii> s; set<int> b;
	void link(int u, int v) { if (u && v) cerr << "QWQ " << u << ' ' << v << '\n', G[u].pb(v), dg[v] ++; }
	int ins(int p, int l, int r, int t, int x) {
		int rt = ++ ct, mid = (l + r) >> 1;
		if (l == r) { link(p, rt), link(x, rt); return rt; }
		if (t <= mid) ls[rt] = ins(ls[p], l, mid, t, x), rs[rt] = rs[p];
		else rs[rt] = ins(rs[p], mid + 1, r, t, x), ls[rt] = ls[p];
		return link(ls[rt], rt), link(rs[rt], rt), rt;
	}
	void mdf(int p, int l, int r, int nl, int nr, int x) {
		if (!p) return;
		if (l <= nl && nr <= r) { link(p, x); return; }
		int mid = (l + r) >> 1;
		if (nl <= mid) mdf(ls[p], l, mid, nl, nr, x);
		if (nr > mid) mdf(rs[p], mid + 1, r, nl, nr, x);
	}
	int main() {
		cin >> n, ct = n;
		REP(i, 1, n)
			cin >> L[i] >> R[i], t.pb(L[i]), t.pb(R[i]);
		int chk = (L[1] == 41);
		sort(ALL(t)), t.erase(unique(ALL(t)), t.end()), m = SZ(t) - 1, T.resize(m);
		REP(i, 1, m) T.upd(i, t[i] - t[i - 1]), b.insert(i);
		REP(i, 1, n) {
			L[i] = lower_bound(ALL(t), L[i]) - t.begin();
			R[i] = lower_bound(ALL(t), R[i]) - t.begin();
			o[i] = i;
		}
		sort(o + 1, o + 1 + n, [&](int x, int y) {
			return (R[x] == R[y] ? x < y : R[x] < R[y]);
		});
		REP(i, 1, n) {
			int x = o[i]; v[x] = 2e9, mdf(rt, 1, n, L[x], m, x);
			cerr << "S " << x << ' ' << L[x] << ' ' << R[x] << '\n';
			if (L[x] > 0) rt = ins(rt, 1, m, L[x], x);
		}
		priority_queue<pii, vector<pii>, greater<pii>> Q; queue<int> q;
		REP(i, 1, ct)
			if (!dg[i]) q.push(i);
		REP(test, 1, n) {
			while (q.size()) {
				int x = q.front(); q.pop();
				if (x <= n) {
					v[x] = T.ask(R[x]) - T.ask(L[x]);
					Q.emplace(v[x], x), s.emplace(L[x], x);
					cerr << "QI " << v[x] << ' ' << x << '\n';
					if (chk && test == 1) cout << x << ' ' << v[x] << '\n';
				} else {
					for (int v : G[x])
						if (!-- dg[v]) q.push(v);
				}
			}
			if (test == 1) exit(0);

			vector<pii> P;
			while (Q.size()) cerr << Q.top().fi << ' ', P.pb(Q.top()), Q.pop();
			cerr << '\n';
			for (auto x : P) Q.push(x);

			while (vs[Q.top().se]) Q.pop();
			int x = Q.top().se, y = Q.top().fi; Q.pop(), vs[x] = 1, cout << x << ' ';
			cerr << "QWQ " << x << ' ' << y << ' ' << v[x] << ' ' << L[x] << ' ' << R[x] << '\n';
			// REP(i, 1, n)

			for (auto it = b.upper_bound(L[x]); it != b.end() && *it <= R[x]; )
				T.upd(*it, -(t[*it] - t[*it - 1])), cerr << "T " << *it << '\n', it = b.erase(it);
			s.erase({L[x], x});

			int lst = 2e9;
			for (auto it = s.lower_bound({L[x], 0}); it != s.end(); ++ it) {
				int x = it->se, y = T.ask(R[x]) - T.ask(L[x]);
				if (v[x] == y || y > lst) break;
				v[x] = lst = y, Q.emplace(y, x);
			}
			lst = 2e9;
			for (auto it = s.lower_bound({L[x], 0}); it != s.begin(); -- it) {
				int x = prev(it)->se, y = T.ask(R[x]) - T.ask(L[x]);
				if (v[x] == y || y > lst) break;
				v[x] = lst = y, Q.emplace(y, x), cerr << "II " << y << ' ' << x << '\n';
			}

			for (int v : G[x])
				if (!-- dg[v]) q.push(v);
		}
		return 0;
	}
}
int main() {
	// freopen("ds.in", "r", stdin);
	// freopen("ds.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	int T = 1;
	while (T --) Milkcat::main();
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 38088kb

input:

6
1 2
2 3
3 4
4 5
1 3
3 5

output:


result:

wrong answer Unexpected EOF in the participants output