QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#54476 | #3308. Remote Control | EastIsRed | AC ✓ | 300ms | 26588kb | C++23 | 1.4kb | 2022-10-08 21:36:48 | 2022-10-08 21:36:48 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n,q;
int pos[300086][2];
char s[300086];
int fa[300086];
int getfa(int u)
{
if(u==fa[u])
return u;
return fa[u]=getfa(fa[u]);
}
map<pair<int,int>,int>st;
int main()
{
scanf("%d",&n);
scanf("%s",s);
scanf("%d",&q);
for(int i=1;i<=q;i++)
{
int x,y;
scanf("%d%d",&x,&y);
pos[i][0]=x,pos[i][1]=y;
if(st.count(make_pair(x,y)))
fa[i]=st[make_pair(x,y)];
else
{
st[make_pair(x,y)]=i;
fa[i]=i;
}
}
int n1=0,n2=0;
for(int i=0;i<n;i++)
{
int move_temp1=0,move_temp2=0;
if(s[i]=='U')
{
n2--;
move_temp2=-1;
}
else if(s[i]=='D')
{
n2++;
move_temp2=1;
}
else if(s[i]=='L')
{
n1++;
move_temp1=1;
}
else
{
n1--;
move_temp1=-1;
}
if(st.count(make_pair(n1,n2)))
{
if(st.count(make_pair(n1+move_temp1,n2+move_temp2)))
{
fa[st[make_pair(n1,n2)]]=st[make_pair(n1+move_temp1,n2+move_temp2)];
st.erase(make_pair(n1,n2));
}
else
{
int temp=st[make_pair(n1,n2)];
st.erase(make_pair(n1,n2));
st[make_pair(n1+move_temp1,n2+move_temp2)]=temp;
pos[temp][0]=n1+move_temp1,pos[temp][1]=n2+move_temp2;
}
}
}
for(int i=1;i<=q;i++)
{
int f=getfa(i);
printf("%d %d\n",pos[f][0]-n1,pos[f][1]-n2);
}
return 0;
}
/*
8
RRDRUULL
5
-2 1
-2 2
-2 -1
-3 -1
1 1
*/
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 3872kb
input:
8 RRDRUULL 5 -2 1 -2 2 -2 -1 -3 -1 1 1
output:
-1 3 -1 3 1 0 -2 -1 2 2
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 2ms
memory: 3804kb
input:
8 LLDDRRUU 18 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 3 3 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 3 3
output:
1 1 -1 2 1 3 2 3 2 3 2 3 3 1 3 2 3 3 1 1 -1 2 1 3 2 3 2 3 2 3 3 1 3 2 3 3
result:
ok 18 lines
Test #3:
score: 0
Accepted
time: 1ms
memory: 3900kb
input:
1000 ULRULRURDDDLURUURULUDRDDRDLURRRUDDDDDURURUDDDRLLDURDDDLLDLULUURDRRDDDURDDRLRULDLUULDLRDLURUUUUDDRULDRRUDDDDUUULLURDUUUULDLDDUUUDUUUUDDLURLUDDDUDLDLRRUDURDRDLRURLUULDRLRDRDDRDRRDLUUURURLRLDUDLDLRURLURUDRRULDRDDRUDDDRURDRRDLDLRDLRDUDDLLLLRUULRRUDURUUUDDDLRDRDRDRURUDDURUDLRLDLLDDULURDURDLLLUULLDLD...
output:
-105 -4 17 -30 41 80 6 -100 23 28 10 -58 -22 -34 1 24 -46 -79 -43 87 -102 -76 85 25 -42 -3 -71 36 -55 -109 -39 -105 5 -102 82 15 42 -22 81 63 -64 -7 -82 -62 74 9 -41 37 21 18 -109 -38 51 48 10 -46 -37 28 -18 -110 -67 -74 -96 -55 -5 16 -49 -21 -81 -56 -106 27 62 48 21 59 -79 72 4 29 17 -65 87 44 72 1...
result:
ok 1000 lines
Test #4:
score: 0
Accepted
time: 266ms
memory: 26588kb
input:
300000 DDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURULDDLURU...
output:
1 -1 1 -1 1 1 1 -1 1 -1 1 1 1 -1 1 -1 1 1 1 -1 1 -1 1 1 1 -1 1 -1 1 1 1 -1 1 -1 1 1 1 -1 1 -1 1 1 1 -1 1 -1 1 1 1 -1 1 -1 1 1 1 -1 1 -1 1 1 1 -1 1 -1 1 1 1 -1 1 -1 1 1 1 -1 1 -1 1 1 1 -1 1 -1 1 1 1 -1 1 -1 1 1 1 -1 1 -1 1 1 1 -1 1 -1 1 1 1 -1 1 -1 1 1 1 -1 1 -1 1 1 1 -1 1 -1 1 1 1 -1 1 -1 1 1 1 -1 1...
result:
ok 300000 lines
Test #5:
score: 0
Accepted
time: 275ms
memory: 21900kb
input:
200000 UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU...
output:
0 -1 0 -1 0 -1 0 -1 0 -99641 0 -1 0 -1 0 -26077 0 -84323 0 -1 0 -1 0 -1 0 -1 0 -1 0 -52103 0 -1 0 -36581 205447 364884 0 -1 0 -12052 0 -22844 0 -1 0 -1 0 -1 -164302 -26107 0 -8670 0 -39346 0 -33207 0 -1 -177189 -95427 0 -1 0 -5158 0 -1 0 -1 0 -74688 0 -1 0 -28631 0 -1 0 -1 0 -1 0 -1 0 -1 0 -63110 0 ...
result:
ok 300000 lines
Test #6:
score: 0
Accepted
time: 271ms
memory: 21168kb
input:
200000 DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD...
output:
0 33810 0 1 0 1 0 1 0 4542 0 1 18257 -426088 0 1 0 1 0 41965 0 38847 0 74819 -95683 -461933 0 1 0 1 -246860 -426475 0 1 0 1 0 1 0 18746 0 1 0 1 0 20401 0 1 0 1 0 1 0 1 0 12685 0 1 0 1 0 1 -116830 -258364 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 2120 0 1 214262 -444677 0 1 0 12012 0 1 0 74965 0 1 0 1 0 1 0 1 0 ...
result:
ok 300000 lines
Test #7:
score: 0
Accepted
time: 290ms
memory: 21544kb
input:
200000 LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL...
output:
1 0 1 0 6255 0 80569 0 76020 0 63049 0 1 0 1 0 1 0 1 0 1 0 40487 0 1 0 -51749 -236067 55107 0 1 0 1 0 1 0 -408704 44082 75153 0 1 0 1 0 1 0 10026 0 6101 0 64779 0 90932 0 60036 0 1 0 1 0 97986 0 1 0 55850 0 1 0 1 0 82095 0 1 0 95436 0 1 0 1 0 1 0 15016 0 48526 0 97466 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 -...
result:
ok 300000 lines
Test #8:
score: 0
Accepted
time: 300ms
memory: 20984kb
input:
200000 RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...
output:
-1 0 -10380 0 -1 0 -1 0 -87094 0 144065 69971 -48816 0 -70459 0 -1 0 -1 0 -1 0 -32060 0 -1 0 -1 0 -1 0 26609 -215464 -1 0 -1 0 -32043 0 -1 0 -1 0 109198 221466 -1 0 -81134 0 -1 0 -1009 0 -74717 0 -1 0 -1 0 186529 -114263 -93456 0 -1 0 373651 211860 -39834 0 -1 0 -1 0 -56783 0 -1 0 -1 0 -1 0 -1 0 -82...
result:
ok 300000 lines
Test #9:
score: 0
Accepted
time: 96ms
memory: 7536kb
input:
300000 LDLUUUDRRLRLLRRDRRLDDUUUDLULDRUDURRLUDDLLRLDLLRLUDUDUDUURRDRULDUUULULLLUUDUDRLLURLULDRRDUDRDDDDULLRRLRLRRRUURDLDDULRDUUDRRURUDLURDLLDDDDDDLULDDRURRURLULULRDDDLUDRUDLRDULULULDLDLDLDRUDURUDRDDUULLUUDDUUURUDDDDULURLDLDDDRULRDDDDDLURUDRDLDDLLRLURLULDRRDLLURLRDRURRRLURUDULDRRDDLULDUUDRLRRDRULRRDRU...
output:
-176 150 -179 142 -169 152 -179 142 -179 142 -179 142 -165 143 -165 139 -163 151 -162 140 -176 152 -172 141 -174 140 -169 152 -179 142 -175 151 -161 142 -161 153 -166 140 -163 151 -164 147 -178 138 -175 152 -164 142 -162 143 -172 141 -162 143 -173 135 -165 160 -176 150 -165 160 -178 138 -172 141 -16...
result:
ok 300000 lines
Test #10:
score: 0
Accepted
time: 212ms
memory: 10116kb
input:
300000 RLRLDRRRDRDURDRULUDLLDLRRLLRDDDURDLDUDDDULLLULULLURDLDLDULLURUULRLRUULULDDULLLLRRRLRRURDDLLULDDLDRDLDRULRLRLLDDRDDRDDLLDUDUULLRLURURURDLLRUDRULRDRDLUULDURRLURLDULUUULUDRRLRDLUDLUULUURRDDRURLRRDULUDUURDLDDURRRUUUDLUDDRLDDRDUDULDRRLDDUUDLDRRDRRDUDUDLRLULURRLURDDRLRDULLLRRDDUDULDLLLUDUDRUULDRRLU...
output:
-35 60 -31 35 -56 29 54 88 -7 139 63 121 -47 39 75 113 46 76 13 56 -49 -12 -27 78 -74 -39 50 91 15 87 71 -10 -79 103 -99 42 -102 -41 -72 24 71 -21 -82 72 -21 73 -92 92 -39 136 -63 12 68 90 65 69 60 113 36 89 -21 -26 26 -41 50 62 74 67 57 117 -66 -37 -79 36 -80 88 -78 -47 77 65 -98 130 -94 43 -9 48 -...
result:
ok 299999 lines
Test #11:
score: 0
Accepted
time: 277ms
memory: 25688kb
input:
299999 DLDULDRRRULLURDRULRRLLLDULURURDULDLDRUDULRLULURRDLLRULLDURDDLLDUULLULDLULDLDUULLRDUDLULRULRUULLDLLRDUUUDLDLRLDDRDDUDUULUURDLRDRLURDURDRDLRLUDDDLRURRRRLRULULDLDULRLLDDDRLURUUUURDDLULURUDURDDLRDDDULDRURRLRDRUURUULRDRURDUDDURURULLUURRDURDDRRUDRLLUDUDDLLDURRRDRUUUUDLLDRLRLUUDLDRUURLUULUDRDDULDRRR...
output:
-93 -237 -421 -720 -1149 615 323 -210 466 761 639 -451 447 -275 -812 1097 -44 150 -619 861 769 1097 -118 1003 -272 367 141 -179 47 412 -986 -503 175 739 661 -656 -1132 -745 -1158 -769 232 -830 82 345 -32 -821 -1039 641 74 1062 437 980 -518 931 -763 -74 301 21 710 -657 -6 -156 282 -288 -151 910 -767 ...
result:
ok 300000 lines
Test #12:
score: 0
Accepted
time: 285ms
memory: 26328kb
input:
300000 LDULRDDRLUULULDDRDUURDDLULDRDDRUURULULURLDLRUUUUDLDLRLDURRULDURDDULLRRURURRURUDRDUUDDRRLDDLDLRLLULLRUURRDDDLURDRRLDRDDRDURLDLRLULUURULUUURLRRRLLUUULURDULDUDDRDLDLDULUUDDDDDURLLLRLDDDDRRRUDDRLURDUDLLDLUURUURURRDLDURULDLLDURDLRUDRUUDULRRLLRDRLUUULDDLLDRLDRRDDRUUDRRDLLUDLUUUURDULUULDULRUURULLLLU...
output:
-2290 -3354 -379 3430 -2727 4841 6812 -7278 -4709 -647 -9380 1734 -3092 -5840 -5755 151 -9814 -255 5303 8311 1149 -7245 -622 -933 415 -8122 2688 4529 -4953 -3282 -649 1468 -6471 -854 -7751 3014 8595 3175 -2709 -7590 719 -7273 -9418 5043 -1415 -3180 -2528 110 5041 7137 -5921 8855 4505 3523 -3390 7641...
result:
ok 299990 lines
Test #13:
score: 0
Accepted
time: 290ms
memory: 26320kb
input:
299998 UDRDLDDURULRUUUURDULDRRLURUDLLUUUUULULLLUDDRUDDLULRRRLRUDDDULURLLRLRRRDUDUDLDURRLLDURUUDULRRUDRRUDLURRDUURLUURLUDLRURLRLRRRURDDRULRRULLUUDUDRDLUDDRRDRRDULUDUDULDRDLRUUULLRLULURRRRDDRUULDLLDUDDRLDURLULURUDRLRDLULRDLLLDRLDULLRRDLDURDUURLDLLRLLDDURUDRDDLUURDURRULRRRDDLLRRDURRDDULLLURDULLUDULDRLL...
output:
-29462 63974 -7143 21433 -83063 -63984 66627 -29319 -18146 11845 -59252 17775 53907 80630 -81579 -81141 13175 -66407 -89811 -83818 34870 -96523 -5970 23702 63959 -30366 -73315 24745 -38649 79448 -47268 -66619 44129 71303 7769 87812 -30544 -64444 -32104 77017 35367 77935 75650 -86168 -87240 -68450 -2...
result:
ok 299999 lines
Test #14:
score: 0
Accepted
time: 0ms
memory: 3768kb
input:
10 DRLLRUURLR 10 -1 0 0 1 -1 0 -1 -1 -1 -1 -1 0 -1 0 0 1 -1 1 -1 1
output:
0 1 1 3 0 1 -1 0 -1 0 0 1 0 1 1 3 -1 2 -1 2
result:
ok 10 lines
Test #15:
score: 0
Accepted
time: 117ms
memory: 7576kb
input:
300000 LDLUUUDRRLRLLRRDRRLDDUUUDLULDRUDURRLUDDLLRLDLLRLUDUDUDUURRDRULDUUULULLLUUDUDRLLURLULDRRDUDRDDDDULLRRLRLRRRUURDLDDULRDUUDRRURUDLURDLLDDDDDDLULDDRURRURLULULRDDDLUDRUDLRDULULULDLDLDLDRUDURUDRDDUULLUUDDUUURUDDDDULURLDLDDDRULRDDDDDLURUDRDLLLRLURLULDRRDLLURLRDRURRRLURUDULDRRDDLULDUUDRLRRDRULRRDRUDL...
output:
0 4 -6 -18 -10 -5 -2 4 -6 4 -2 4 -10 -5 10 4 12 -16 -10 -5 -2 4 12 -10 -6 -18 12 -4 11 4 -2 4 -2 4 -4 -18 -4 -18 -1 4 -6 -18 2 -18 3 -18 -10 -4 -2 4 12 -13 0 4 -10 -5 12 -5 9 4 9 -18 -2 4 5 -18 -10 -6 -2 4 -6 4 0 4 -6 -18 0 4 -10 -8 -6 -18 11 4 -2 4 -2 4 5 -18 -1 4 7 4 2 -18 -10 -6 -2 4 12 -10 -2 4 ...
result:
ok 300000 lines
Test #16:
score: 0
Accepted
time: 204ms
memory: 10088kb
input:
300000 UUURLRULURDRURDDULDRRURRRUUUDDLDDDRUDRUURRRRUDLULDLRRLDURLUULUDURLRRLRDDRLLLDDURUUULURUDURLRRLLLLLULULRDDDRDUDUDUDUURUDDLUDDLRUURLLURURUURURRUURLLDLLRRULUDRLUUDDUDLUDRRUDRUULLRULRRULLLLRLRURUDULLLLLDDDDRULULRULLRLDRUUDDRLRLDURULDLULUDUUDULLDURRDLDDRLDRLDDRLRRDDDDRUURRLUUURLDDLRUDURLDRLLDURURL...
output:
-86 175 -24 -12 67 15 57 0 -74 35 -25 146 -26 14 -5 127 -125 143 -51 82 -61 23 -18 32 14 45 -125 -6 -33 125 22 16 -88 175 11 93 -20 134 3 16 59 149 -123 11 -27 3 -45 126 -62 25 -15 136 -42 12 26 -6 -113 189 -4 18 36 124 -108 147 -62 -4 59 6 -71 -4 -104 79 -25 164 43 107 30 75 -77 147 65 149 29 161 -...
result:
ok 300000 lines
Test #17:
score: 0
Accepted
time: 284ms
memory: 25736kb
input:
300000 DUDRUDLDRUDRDDURURULDDLRDULDURRULUDRDRLDDLLUURRDLULLLUURLUDURRUDUDLRLULULLULRDLUURUURLLUUDDLRDLUDLLUURRUUDDRLULRDURDULDULDULLLRDUURRDURRLLRLLLLRUULULURLURUULUDDLUUDRRUUDDDULLLLLLDDUDRLRRUDLLRRURDDDDLURLRRLULRDLUULULDLLDULDLRRULURDRDLLLDRURLUUUDDDDLDRDDRLDDLUUULRDDDUULRRRRRURDRUDDULLUULRLLDLRD...
output:
-70 639 -20 903 788 -771 82 -214 998 -446 -796 732 926 -597 -299 809 594 404 532 -60 747 -813 -734 430 278 938 526 -743 817 -198 -594 783 867 39 -641 -665 516 528 1095 694 -275 62 -95 430 725 589 346 586 5 966 22 -386 15 -799 776 616 840 405 -469 6 45 20 647 453 -431 954 679 747 -150 830 -540 1091 -...
result:
ok 300000 lines
Test #18:
score: 0
Accepted
time: 2ms
memory: 3820kb
input:
1 R 1 -1 0
output:
-1 0
result:
ok single line: '-1 0'
Test #19:
score: 0
Accepted
time: 2ms
memory: 3784kb
input:
1 R 1 -1 1
output:
0 1
result:
ok single line: '0 1'
Test #20:
score: 0
Accepted
time: 281ms
memory: 26324kb
input:
300000 RLDDUUULULLLDLUUULDUUUULUUUDLDRDDURDURULURULLLDLRLRDLDULDRLLDRUUDLDRRLRRUDDURRLLDUURRRLURURDRRUUDLDLLRDLLULRLLLLLLURURURRLRUUUUDURDLULLDUUDUDDDDRLURRUDULDLDDLLURLDRLDRLDLUDRLUURRRDLLDDDDDUULUUUDRLLLRDLDRUUUDULDDUDDDURRRRRLLDDLDLLULULDUUDULLDDLDLLRUDDUULULUDULRDRUDDRDLDULDRDRRRUDLDDULRULRDULDR...
output:
-9332 8824 -9068 3493 -6319 1446 8422 7273 7121 5794 6452 9853 2163 -1542 -6115 6088 -3420 -2024 -2180 3951 2774 4058 -789 -542 -4106 -346 -3593 -9927 9631 4255 7595 2087 -3927 -4949 -6053 -649 4258 3076 -1109 7057 -9778 1984 -8549 4775 -3576 9839 -8587 -3366 2359 1443 2620 -1050 -4687 -5952 8309 31...
result:
ok 300000 lines
Test #21:
score: 0
Accepted
time: 279ms
memory: 26336kb
input:
300000 UULDRULLRRUUDDLRRDURDLURDDLDRDUUDULUDRRDLLRULDRDRUURDUDRLRULLDDLRDRDLUDLDRLLRUDURDDDDULDRURUDLRRDDUUDRLDULDLUDLLRULLDLULURLLULULUUDLRDURRUUULUULRDUDLRLUDRLDUULRLURLDDLRRURDRDLUUDDLLLUDRRDRUDULDRUUURUDRRRRDDDDDRRDRRLDDUDRUURUUULDRRRDRRRDRLRULRDRDRDLRUDDUDDURRUURLDRRLRULLLDUDURLUULLLLDDUULRDRDL...
output:
64486 210991 18829 -106476 214874 -91865 -149817 -53298 -2024 -171848 -15238 -13237 -105300 -259208 -51315 90221 -275527 289988 -56061 180666 268267 281262 3407 -97832 -110072 249530 -140676 -103457 -246837 19673 194319 -169313 120225 -9828 156311 -127514 94699 215945 59276 -58088 180920 145130 -286...
result:
ok 300000 lines