info c[N]; voidupd(int x, info v){ while (x < N) { cmax(c[x], v); x += x & -x; } } info query(int x){ info res{}; while (x) { res = max(res, c[x]); x -= x & -x; } return res; }
pii a[N]; vector<int> pt[N]; int dp[N], pre[N]; voidsolve(){ int h, w, n; cin >> h >> w >> n; for (int i = 1; i <= n; i++) { int r, c; cin >> r >> c; a[i] = {r, c}; pt[r].push_back(i); }
for (int r = 1; r <= h; r++) { sort(all(pt[r]), [&](int i, int j) { return a[i] < a[j]; }); for (auto i : pt[r]) { auto [_, c] = a[i]; auto [v, j] = query(c); dp[i] = dp[j] + 1; pre[i] = j; upd(c, {dp[i], i}); } }
auto [res, cur] = query(N - 1); vector<int> path; while (cur > 0) { path.push_back(cur); cur = pre[cur]; }
// debug(res, path); string ans = "";
reverse(all(path)); a[n + 1] = {h, w}; path.push_back(n + 1); int x = 1, y = 1;
for (auto id : path) { while (x < a[id].first) x++, ans += "D"; while (y < a[id].second) y++, ans += "R"; }