-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathABC369F.cpp
More file actions
64 lines (64 loc) · 1.52 KB
/
ABC369F.cpp
File metadata and controls
64 lines (64 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* @FilePath: \c++\ABC369F.cpp
* @Author: WRT_Partisan
* @Date: 2026-02-02 18:02:55
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
int lowbit(int x) { return x & (-x); }
struct Node
{
int x, y;
} c[200005];
struct BIT
{
int M;
vector<int> s, id;
BIT(int x) : M(x) { s.assign(M + 1, 0), id.assign(M + 1, 0); }
void update(int p, int w, int idx)
{
for (int i = p; i <= M; i += lowbit(i))
if (s[i] < w)
s[i] = w, id[i] = idx;
}
pair<int, int> ask(int p)
{
int res = 0, idx = 0;
for (int i = p; i > 0; i -= lowbit(i))
if (s[i] > res)
res = s[i], idx = id[i];
return {res, idx};
}
};
int n, m, k, x, y, pre[200005], dp[200005];
void dfs(int p)
{
if (pre[p] == -1)
return;
dfs(pre[p]);
for (int i = c[pre[p]].x; i < c[p].x; i++)
cout << 'D';
for (int i = c[pre[p]].y; i < c[p].y; i++)
cout << 'R';
}
signed main()
{
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m >> k;
for (int i = 1; i <= k; i++)
cin >> c[i].x >> c[i].y;
c[++k] = {n, m}, c[++k] = {1, 1};
sort(c + 1, c + k + 1, [](Node a, Node b)
{ return a.x < b.x || (a.x == b.x && a.y < b.y); });
BIT bt(m);
dp[1] = 1, pre[1] = -1, bt.update(1, 1, 1);
for (int i = 2; i <= k; i++)
{
auto t = bt.ask(c[i].y);
dp[i] = t.first + 1, pre[i] = t.second, bt.update(c[i].y, dp[i], i);
}
cout << dp[k] - 2 << "\n";
dfs(k);
return 0;
}