编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#6160 #1024. robot Accepted 100 7487 ms 33764 K C++ 17 / 3.8 K admin 2023-10-14 22:23:13
显示原始代码
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <bitset>
#include <cmath>
#include <queue>
using namespace std;

#define x first

#define y second


typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<double, double> PDD;
typedef pair<LD, int> PLDI;
typedef pair<LD, LD> PLDLD;
typedef pair<PII, int> PIII;
const int N = 1000010, M = 2 * N, U = 200000, P = 13331, INF = 1e9 + 10, mod = 998244353;
const double PI = acos(-1);

int T, n, m, k;
struct Node {
    int l, r;
    int lx, rx, ly, ry;
    int dx, dy;
} tr[N * 4];
char str[N];

void pushup(int x) {
    auto &u = tr[x], &l = tr[x * 2], &r = tr[x * 2 + 1];
    if (l.rx != 0 && r.rx != 0) {
        int nl = l.lx + l.dx, nr = l.rx + l.dx;
        if (max(r.lx, nl) > min(r.rx, nr)) {
            u.lx = 1, u.rx = 0;
            if (nr < r.lx)
                u.dx = r.dx + r.lx;
            else
                u.dx = r.dx + r.rx;
        } else {
            u.lx = max(l.lx, r.lx - l.dx), u.rx = min(l.rx, r.rx - l.dx);
            u.dx = l.dx + r.dx;
        }
    } else if (l.rx == 0 && r.rx != 0) {
        u.lx = 1, u.rx = 0;
        int t = l.dx;
        if (t >= r.lx && t <= r.rx)
            u.dx = t + r.dx;
        else if (t < r.lx)
            u.dx = r.lx + r.dx;
        else
            u.dx = r.rx + r.dx;
    } else {
        u.lx = 1, u.rx = 0;
        u.dx = r.dx;
    }
    //
    if (l.ry != 0 && r.ry != 0) {
        int nl = l.ly + l.dy, nr = l.ry + l.dy;
        if (max(r.ly, nl) > min(r.ry, nr)) {
            u.ly = 1, u.ry = 0;
            if (nr < r.ly)
                u.dy = r.dy + r.ly;
            else
                u.dy = r.dy + r.ry;
        } else {
            u.ly = max(l.ly, r.ly - l.dy), u.ry = min(l.ry, r.ry - l.dy);
            u.dy = l.dy + r.dy;
        }
    } else if (l.ry == 0 && r.ry != 0) {
        u.ly = 1, u.ry = 0;
        int t = l.dy;
        if (t >= r.ly && t <= r.ry)
            u.dy = t + r.dy;
        else if (t < r.ly)
            u.dy = r.ly + r.dy;
        else
            u.dy = r.ry + r.dy;
    } else {
        u.ly = 1, u.ry = 0;
        u.dy = r.dy;
    }
}

void build(int u, int l, int r) {
    tr[u] = { l, r };
    if (tr[u].l == tr[u].r) {
        if (str[l] == 'U')
            tr[u] = { l, r, 2, n, 1, n, -1, 0 };
        else if (str[l] == 'D')
            tr[u] = { l, r, 1, n - 1, 1, n, 1, 0 };
        else if (str[l] == 'L')
            tr[u] = { l, r, 1, n, 2, n, 0, -1 };
        else
            tr[u] = { l, r, 1, n, 1, n - 1, 0, 1 };
        //		cout<<l<<' '<<r<<' '<<tr[u].ly<<' '<<tr[u].ry<<endl;
        return;
    }
    int mid = l + r >> 1;
    build(u * 2, l, mid), build(u * 2 + 1, mid + 1, r);
    pushup(u);
    //	cout<<l<<' '<<r<<' '<<tr[u].ly<<' '<<tr[u].ry<<endl;
}

void modify(int u, int pos, char c) {
    if (tr[u].l == tr[u].r) {
        int l = tr[u].l, r = tr[u].r;
        if (c == 'U')
            tr[u] = { l, r, 2, n, 1, n, -1, 0 };
        else if (c == 'D')
            tr[u] = { l, r, 1, n - 1, 1, n, 1, 0 };
        else if (c == 'L')
            tr[u] = { l, r, 1, n, 2, n, 0, -1 };
        else
            tr[u] = { l, r, 1, n, 1, n - 1, 0, 1 };
        return;
    }
    int mid = tr[u].l + tr[u].r >> 1;
    if (pos <= mid)
        modify(u * 2, pos, c);
    else
        modify(u * 2 + 1, pos, c);
    pushup(u);
}

int get(int u, int d, int type) {
    if (!type) {
        if (tr[u].rx == 0)
            return tr[u].dx;
        else if (d >= tr[u].lx && d <= tr[u].rx)
            return d + tr[u].dx;
        else if (d < tr[u].lx)
            return tr[u].lx + tr[u].dx;
        else
            return tr[u].rx + tr[u].dx;
    } else {
        if (tr[u].ry == 0)
            return tr[u].dy;
        else if (d >= tr[u].ly && d <= tr[u].ry)
            return d + tr[u].dy;
        else if (d < tr[u].ly)
            return tr[u].ly + tr[u].dy;
        else
            return tr[u].ry + tr[u].dy;
    }
}

int query(int u, int l, int r, int d, int type) {
    if (tr[u].l >= l && tr[u].r <= r)
        return get(u, d, type);
    int mid = tr[u].l + tr[u].r >> 1;
    int t = d;
    if (l <= mid)
        t = query(u * 2, l, r, t, type);
    if (r > mid)
        t = query(u * 2 + 1, l, r, t, type);
    return t;
}

int main() {
    //	freopen("5.in","r",stdin);
    //	freopen("5.out","w",stdout);
    scanf("%d", &T);
    while (T--) {
        scanf("%d%d%d%s", &n, &m, &k, str + 1);
        build(1, 1, m);
        // 		cout<<tr[1].ly<<' '<<tr[1].ry<<' '<<tr[1].dy<<endl;
        while (k--) {
            int op;
            scanf("%d", &op);
            if (op == 1) {
                int x, y, l, r;
                scanf("%d%d%d%d", &x, &y, &l, &r);
                int ansx = query(1, l, r, x, 0), ansy = query(1, l, r, y, 1);
                printf("%d %d\n", ansx, ansy);
            } else {
                int pos;
                char op[2];
                scanf("%d%s", &pos, op);
                modify(1, pos, *op);
            }
        }
    }
    return 0;
}
子任务 #1
Accepted
得分:100
测试点 #1
Accepted
得分:100
用时:1721 ms
内存:33704 KiB

输入文件(1.in

10
500000 500000 500000
RRUURLRLLULRULULRUULDULLDLLRLDURLDRLULDDLLDUULRRUULUDRDURLRRLUUDDRULRUDRDL
<25948071 bytes omitted>

答案文件(1.out

359508 479312
332135 370752
361331 453452
154557 445044
455957 270960
94057 120729
395227 1106
<7276087 bytes omitted>

用户输出

359508 479312
332135 370752
361331 453452
154557 445044
455957 270960
94057 120729
395227 110667
115159 123104
412373 289173
627
<6775955 bytes omitted>

系统信息

Exited with return code 0
测试点 #2
Accepted
得分:100
用时:1787 ms
内存:33692 KiB

输入文件(2.in

10
500000 500000 500000
LRLLRURRRRDLLLDDLURUDRURDULURDULUDRDDDLLLRLLRLLURRLRRDUUDLDURRDDDLLRLDRLRD
<25943579 bytes omitted>

答案文件(2.out

327124 391683
2385 455770
423797 136987
390628 259434
201277 484438
472553 273997
111636 12262
<7272167 bytes omitted>

用户输出

327124 391683
2385 455770
423797 136987
390628 259434
201277 484438
472553 273997
111636 122620
454656 52851
170045 37918
205581
<6772299 bytes omitted>

系统信息

Exited with return code 0
测试点 #3
Accepted
得分:100
用时:1919 ms
内存:33764 KiB

输入文件(3.in

10
500000 500000 500000
LLULDLURRRDLURULRRRRLLRLLRLULURUDRRRDRRDDRDRULDDRLRRLLLUDUUULLULDDLUURULLU
<25946287 bytes omitted>

答案文件(3.out

236118 464668
450895 332446
77846 197703
429497 151051
413123 471659
324031 85056
240527 45508
<7275907 bytes omitted>

用户输出

236118 464668
450895 332446
77846 197703
429497 151051
413123 471659
324031 85056
240527 455082
25074 489039
390262 470315
33705
<6775922 bytes omitted>

系统信息

Exited with return code 0
测试点 #4
Accepted
得分:100
用时:800 ms
内存:33660 KiB

输入文件(4.in

2
500 500000 500000
UDUUDUUDUUDUUDUUDUUDUUDUUDUUDUUDUUDUUDUUDUUDUUDUUDUUDUUDUUDUUDUUDUUDUUDUUDUUDU
<22334541 bytes omitted>

答案文件(4.out

1 89
1 126
1 90
1 172
1 342
1 328
1 336
1 410
1 364
1 156
1 178
1 139
1 392
1 426
1 46
<7784362 bytes omitted>

用户输出

1 89
1 126
1 90
1 172
1 342
1 328
1 336
1 410
1 364
1 156
1 178
1 139
1 392
1 426
1 464
1 168
1 446
1 432
1 149
1 444
1 264
1 47
<6784334 bytes omitted>

系统信息

Exited with return code 0
测试点 #5
Accepted
得分:100
用时:1260 ms
内存:33672 KiB

输入文件(5.in

2
50 500000 500000
UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU
<20000185 bytes omitted>

答案文件(5.out

50 27
12 33
50 30
50 35
49 11
50 14
13 8
50 4
50 19
22 21
30 10
29 39
50 4
37 18
50 44
<6273544 bytes omitted>

用户输出

50 27
12 33
50 30
50 35
49 11
50 14
13 8
50 4
50 19
22 21
30 10
29 39
50 4
37 18
50 44
50 36
50 49
36 48
48 41
50 17
50 25
50 39
<5273516 bytes omitted>

系统信息

Exited with return code 0