QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#214603#3061. Donut DronejinhaoxianWA 401ms36664kbC++142.5kb2023-10-14 21:43:552023-10-14 21:43:55

Judging History

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

  • [2023-10-14 21:43:55]
  • 评测
  • 测评结果:WA
  • 用时:401ms
  • 内存:36664kb
  • [2023-10-14 21:43:55]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,m,q,e[2050][2050],nxt[2050][2050],skp[2050],x,y,z,curx,cury;
string op;
int ansx,ansy;
void upd(int i,int j) {
    if ((e[i][(j+1)%m]>=e[(i+n-1)%n][(j+1)%m])&&(e[i][(j+1)%m]>=e[(i+1)%n][(j+1)%m])) nxt[i][j]=i;
    else if (e[(i+n-1)%n][(j+1)%m]>e[(i+1)%n][(j+1)%m]) nxt[i][j]=(i+n-1)%n;
    else nxt[i][j]=(i+1)%n;
}
void do_walk(int &ansx,int &ansy) {
    ansx=nxt[ansx][ansy];
    ansy=(ansy+1)%m;
}
void do_skip(int &ansx,int &ansy) {
    ansx=skp[ansx];
}
int vis[2050];
void solve(int &ansx,int &ansy,int cnt) {
    memset(vis,0,sizeof(vis));
    int cur=1;
    vis[ansx]=cur;
    while (cnt) {
        cnt--;
        do_skip(ansx,ansy);
        cur++;
        if (vis[ansx]) {
            cnt%=(cur-vis[ansx]);
            break;
        } else {
            vis[ansx]=cur;
        }
    }
    while (cnt) {
        cnt--;
        do_skip(ansx,ansy);
    }
}
void refresh(int x,int y) {
    upd(x,y);
    int curx=x;cury=y;
    do_walk(curx,cury);
    while (cury) do_walk(curx,cury);
    int ll=x+n*m,rr=x+n*m;
    for (int i=(y+m-1)%m;i>=0;i--) {
        if (nxt[(ll-1)%n][i]==ll%n) ll--;
        else if (nxt[ll%n][i]==(ll-1)%n) ll++;
        if (nxt[(rr+1)%n][i]==rr%n) rr++;
        else if (nxt[rr%n][i]==(rr+1)%n) rr--;
        if (rr-ll+1>=n) break;
        if (ll>rr) break;
    }
    for (int i=ll;i<=rr;i++) skp[i%n]=curx;
}
int main() {
    scanf("%d%d",&n,&m);
    for (int i=0;i<n;i++) {
        for (int j=0;j<m;j++) scanf("%d",&e[i][j]);
    }
    for (int i=0;i<n;i++) {
        for (int j=0;j<m;j++) {
            upd(i,j);
        }
    }
    for (int i=0;i<n;i++) {
        skp[i]=i;
        for (int j=0;j<m;j++) skp[i]=nxt[skp[i]][j];
    }
    cin>>q;
    while (q--) {
        cin>>op;
        if (op=="move") {
            cin>>x;
            while (ansy&&x) {
                x--;
                do_walk(ansx,ansy);
            }
            if (!x) cout<<ansx+1<<' '<<ansy+1<<endl;
            else {
                y=x/m;x%=m;
                solve(ansx,ansy,y);
                while (x) {
                    x--;
                    do_walk(ansx,ansy);
                }
                cout<<ansx+1<<' '<<ansy+1<<endl;
            }
        } else {
            cin>>x>>y>>z;
            x--;y--;
            e[x][y]=z;
            refresh((x+n-1)%n,(y+m-1)%m);
            refresh(x,(y+m-1)%m);
            refresh((x+1)%n,(y+m-1)%m);
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5732kb

input:

4 4
1 2 9 3
3 5 4 8
4 3 2 7
5 8 1 6
4
move 1
move 1
change 1 4 100
move 1

output:

4 2
1 3
1 4

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 1ms
memory: 5844kb

input:

3 4
10 20 30 40
50 60 70 80
90 93 95 99
3
move 4
change 2 1 100
move 4

output:

3 1
2 1

result:

ok 2 lines

Test #3:

score: 0
Accepted
time: 3ms
memory: 9864kb

input:

20 30
8 1 7 4 3 1 2 1 5 5 2 7 6 4 7 1 2 9 1 9 9 9 9 6 4 9 1 6 3 10
7 3 5 6 5 3 5 3 1 9 8 8 7 7 6 7 5 10 9 6 5 3 8 2 7 10 6 8 4 3
6 4 3 1 7 7 6 7 2 7 3 6 8 6 3 2 7 8 10 8 6 5 6 10 2 6 5 10 10 9
2 5 10 9 4 9 3 6 10 8 1 7 3 3 7 3 3 6 7 5 1 1 10 6 8 5 4 2 1 8
5 1 2 8 3 4 2 4 4 9 6 3 1 5 9 1 9 3 8 3 7 10...

output:

19 10
18 19
3 24
3 30
3 2
4 3
3 8
7 14
3 21
2 27
3 7
3 8
6 16
5 17
3 24
2 27
3 29
3 8
7 12
6 16
3 22
3 2
7 12
3 19
1 22
4 25
4 3
3 5
7 12
3 20
1 22
2 24
3 2
6 11
3 20
2 24
4 4
3 5
5 10
6 11
4 18
2 21
3 29
3 2
3 5
4 9
6 16
2 25
1 26
2 1
4 6
7 15
2 24
3 2
7 12
3 19
3 28
5 4
9 11
9 12
11 17
10 19
12 21...

result:

ok 1945 lines

Test #4:

score: 0
Accepted
time: 8ms
memory: 5968kb

input:

50 50
126812431 909179109 607682292 96000160 425314080 189788877 721251789 103560861 114082307 888028612 277663589 257100764 842807257 327052508 652365304 770138116 384723035 680037089 675501229 509497026 174936063 991259231 761329528 658883078 806406343 741076652 973854314 192609094 398064987 65322...

output:

46 21
46 21
1 49
47 20
46 37
1 42
45 35
50 50
2 17
1 43
2 38
2 47
50 50
2 38
50 50
2 26
2 17
2 34
2 21
4 9
3 6
1 2
1 30
2 40
2 21
2 35
2 17
2 31
2 32
4 9
2 42
3 12
4 8
2 31
1 3
2 15
1 48
1 20
1 30
2 17
49 49
2 14
2 4
1 30
1 29
2 40
2 24
1 27
1 36
1 27
49 47
3 6
2 32
3 41
49 48
2 34
3 41
47 22
49 28
...

result:

ok 502 lines

Test #5:

score: 0
Accepted
time: 12ms
memory: 10080kb

input:

100 191
178 164 436 292 160 15 447 40 415 308 107 456 61 483 370 222 49 178 96 272 359 232 285 356 320 316 56 450 34 30 300 15 53 269 210 271 443 169 387 273 181 175 38 177 167 447 376 252 434 97 334 389 349 216 293 265 227 273 171 351 68 481 430 249 482 117 206 429 359 61 431 207 163 336 329 490 20...

output:

94 140
94 149
98 91
98 19
97 121
94 169
3 51
98 97
1 37
1 37
3 61
97 10
98 13
93 179
95 146
97 8
97 130
96 6
95 158
98 122
94 181
94 140
97 117
94 176
96 133
100 38
99 29
1 68
3 59
3 46
97 124
93 155
95 139
94 143
10 10
13 63
7 184
8 164
13 62
12 57
15 41
10 10
12 84
8 2
11 89
11 119
12 92
7 166
9 7...

result:

ok 516 lines

Test #6:

score: 0
Accepted
time: 369ms
memory: 36128kb

input:

1999 1971
274359794 615065638 314433231 715787778 486221282 877103113 462895814 602525302 496926569 16482389 7389157 94419868 841896951 423947821 735538885 670514061 398818169 503874450 256795479 71430930 757204344 924882965 721532878 511539013 917383058 160383266 270331386 296482213 104942177 30363...

output:

19 867
17 863
19 472
21 898
27 1104
29 1490
35 1470
28 64
21 24
34 1360
32 1384
10 756
17 915
30 1504
32 1398
22 16
35 1141
15 553
21 378
34 1168
18 455
16 515
33 1299
28 1556
34 1599
35 1443
9 685
32 1572
31 1205
22 386
26 1959
31 1200
20 817
30 1407
17 877
11 737
24 121
30 1546
25 156
10 997
18 44...

result:

ok 4951 lines

Test #7:

score: 0
Accepted
time: 401ms
memory: 36664kb

input:

1999 1972
908570368 576114585 871607413 105528864 717151909 868091308 442016015 96884299 951725816 178293034 660937316 882194661 290229206 116518447 685144293 777163613 825739358 379460279 316897433 343444500 220852674 464535570 629533274 19187139 768795424 839233681 621997087 563642576 573864427 21...

output:

11 50
30 1407
22 1111
23 1496
9 103
7 991
23 1154
1999 536
10 102
1998 414
30 1294
36 1388
19 3
1991 817
17 1891
26 1416
14 134
1991 649
1993 556
12 1559
22 1155
21 1107
1996 268
1996 269
1997 848
1990 611
1997 683
20 1157
11 50
1 251
12 151
14 135
18 1091
36 1358
1999 237
12 1555
8 918
18 1
19 1464...

result:

ok 55 lines

Test #8:

score: 0
Accepted
time: 255ms
memory: 36080kb

input:

1999 1971
5 4 5 5 2 3 2 2 1 1 5 3 4 3 5 4 2 3 4 1 2 3 5 2 3 5 5 5 2 2 1 2 2 3 5 5 4 1 4 1 1 2 1 3 5 1 5 3 4 4 4 1 2 4 3 3 4 2 1 3 4 3 4 2 4 2 4 1 1 3 3 1 3 1 2 4 3 4 5 5 2 5 2 4 5 5 1 5 5 2 1 1 4 4 1 1 2 4 2 4 5 1 3 3 5 2 5 2 2 5 1 2 1 3 4 3 3 5 5 4 4 5 4 5 2 5 2 4 1 1 2 3 2 1 5 3 5 1 5 4 3 3 5 3 5 ...

output:

100 1816
98 151
84 910
92 271
101 1589
91 1067
96 1691
98 413
88 202
100 1658
88 1967
100 147
92 271
87 1293
84 1251
98 134
93 1929
97 294
99 454
99 118
85 1247
99 462
92 1764
86 1279
96 175
98 1688
88 1377
99 1533
97 375
92 1355
89 1023
94 159
92 1773
82 849
93 47
94 1846
99 1805
101 1660
84 1046
1...

result:

ok 4944 lines

Test #9:

score: 0
Accepted
time: 291ms
memory: 36276kb

input:

1999 1972
5 1 2 5 2 3 3 3 4 3 2 3 3 1 4 1 6 5 4 6 2 5 1 1 1 4 5 4 3 1 2 3 5 5 4 5 6 5 1 6 6 2 6 4 4 1 5 5 5 4 2 2 5 5 5 2 1 5 1 6 3 4 2 1 5 3 3 3 2 3 4 1 4 5 5 2 5 3 4 5 3 6 3 3 4 6 5 3 4 1 4 2 6 1 1 5 1 3 3 6 5 2 3 2 6 6 5 1 5 5 3 3 5 4 5 5 2 5 2 5 3 2 1 3 5 1 1 3 4 4 1 6 2 4 6 3 3 3 4 6 4 1 6 3 1 ...

output:

1926 1347
1944 1057
1940 710
1930 1764
1943 42
1931 563
1942 1917
1926 410
1942 1053
1932 1122
1928 335
1940 705
1917 462
1923 371
1922 524
1926 1246
1939 842
1933 940
1932 656
1923 1320
1926 583
1926 1219
1937 1827
1921 1646
1935 13
1941 1070
1941 822
1929 1160
1936 1809
1919 241
1927 387
1933 671
...

result:

ok 51 lines

Test #10:

score: 0
Accepted
time: 280ms
memory: 36284kb

input:

2000 1999
6 6 4 5 4 2 3 1 1 2 5 1 1 2 6 3 1 5 5 4 5 2 4 1 6 6 1 4 2 3 5 6 1 4 6 4 4 3 4 3 6 3 2 4 3 2 1 3 1 2 6 2 6 1 5 4 4 2 5 6 2 3 2 1 3 3 4 3 6 4 1 2 1 4 1 1 1 6 6 3 5 4 4 2 2 3 3 4 2 4 4 4 3 6 6 6 2 6 3 3 6 2 4 5 2 1 5 6 6 3 1 3 4 6 4 4 1 3 5 4 1 6 6 6 6 5 2 5 1 3 2 3 4 1 4 6 5 2 6 6 5 1 5 3 6 ...

output:

1996 429
7 1375
1990 162
2000 1918
1 499
7 1392
1999 1605
3 1859
1992 690
3 1531
1985 101
9 1290
2000 1511
6 1819
1 1540
8 1811
8 1067
1 918
1993 166
2000 1519
11 1081
1996 173
7 1392
1979 129
11 1091
1999 1958
1994 214
8 1483
1997 399
1997 1708
1992 1634
2000 930
3 1172
2000 1195
2 339
1985 97
2000...

result:

ok 2513 lines

Test #11:

score: 0
Accepted
time: 259ms
memory: 36632kb

input:

1998 2000
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 ...

output:

1195 381
979 1816
1732 485
772 1313
1435 1068
1561 1753
1726 696
1915 1877
1993 837
916 1404
1240 403
1633 514
379 723
1588 1116
1762 365
1621 105
1372 1847
679 1301
1270 408
1504 1197
1033 1496
268 267
1033 743
1612 1198
1849 1420
445 80
1495 1613
1135 1082
1633 1309
1507 1479
1261 776
1324 772
198...

result:

ok 3332 lines

Test #12:

score: 0
Accepted
time: 292ms
memory: 36284kb

input:

1998 2000
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 ...

output:

829 1918
541 712
22 1294
1246 527
1918 1368
145 218
1855 1421
616 1809
472 971
1588 923
982 1033
1330 1786
1630 187
637 27
1945 457
1393 1132
397 219
724 1984
1318 337
1231 1954
1156 981
1840 24
532 1075
1303 984
709 45
571 1166
82 1101
271 1384
97 1470
1492 1186
1405 917
931 1108
1357 2
124 1406
16...

result:

ok 1666 lines

Test #13:

score: 0
Accepted
time: 3ms
memory: 5856kb

input:

3 30
2 3 5 4 1 3 4 3 5 1 1 2 4 3 4 5 1 3 2 3 1 3 3 3 2 5 1 3 3 2
5 5 4 5 5 2 1 1 3 5 4 4 2 2 5 1 5 5 3 1 4 5 2 4 3 1 5 1 5 3
4 4 3 3 3 5 3 5 1 3 2 1 5 1 3 4 4 4 4 4 3 1 1 5 5 2 2 5 2 1
5000
change 3 3 1
move 952187187
change 1 27 1
move 974680939
change 3 13 1
change 2 5 2
move 920255431
change 2 20...

output:

3 28
2 17
2 18
1 23
2 24
2 22
2 30
2 4
1 7
2 29
2 29
2 17
2 17
1 9
1 7
3 5
1 3
3 14
2 1
1 16
2 30
1 9
3 6
2 21
3 23
3 21
1 16
3 5
1 13
2 29
1 26
2 4
3 5
3 8
1 16
3 6
1 10
3 30
2 11
2 12
1 26
2 22
1 10
1 9
1 10
3 15
3 1
1 7
3 23
2 29
2 2
2 5
3 15
3 12
3 20
1 11
2 22
3 10
3 3
3 5
3 20
1 24
3 5
1 24
3 ...

result:

ok 1935 lines

Test #14:

score: -100
Wrong Answer
time: 0ms
memory: 5776kb

input:

4 4
4 2 3 1
2 5 5 2
3 1 2 4
1 4 1 3
5000
change 1 1 5
move 973774583
change 2 1 2
move 907682990
change 3 2 3
move 967713529
change 1 3 4
move 957932232
change 3 1 3
change 2 3 3
move 903397861
move 976938118
change 3 1 4
move 981043236
move 979560517
change 2 1 2
change 2 2 1
change 3 1 4
change 3 ...

output:

3 4
2 2
2 3
2 3
4 4
2 2
2 2
1 3
1 1
1 3
1 3
4 4
4 2
1 4
1 4
1 4
1 4
1 1
1 4
1 3
1 1
4 2
1 4
1 1
1 1
4 2
1 1
1 3
3 4
4 1
3 3
3 4
1 1
1 4
1 4
1 4
1 1
1 4
2 2
1 1
2 3
2 3
1 1
1 1
1 1
2 2
2 2
2 2
3 1
3 3
3 3
2 2
3 3
2 2
2 2
1 3
3 1
3 1
1 3
3 1
3 1
1 3
1 4
1 3
1 2
1 4
1 4
1 4
1 3
2 3
1 4
2 4
3 1
3 3
3 3
...

result:

wrong answer 632nd lines differ - expected: '3 1', found: '4 1'