QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#617776#5113. Bridgemhw#TL 400ms28772kbC++201.8kb2024-10-06 17:03:372024-10-06 17:03:37

Judging History

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

  • [2024-10-06 17:03:37]
  • 评测
  • 测评结果:TL
  • 用时:400ms
  • 内存:28772kb
  • [2024-10-06 17:03:37]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>

int n, m, b, q;
const int M = 11451419198;
void slv(){
    cin >> n >> m >> q;
    int b = sqrt(m) + 1;

    vector<int> l(m + 2), r(m + 2);

    int cnt = 0;
    for(int i = 1; i <= m; ++i) {
        l[i] = (i - 1) * b + 1, r[i] = i * b;
        if(r[i] >= m) {
            r[i] = m;
            cnt = i;
            break;
        } 
    }

    vector<vector<int> >g(n + 1, vector<int>(cnt + 1));
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= cnt; ++j){
            g[i][j] = i;
        }
    }

    int op, x, y;
    unordered_map<int, int> v1, v2;
    //v1代表有↓,v2代表有↑
    while(q--){
        cin >> op;
        if(op == 2){
            cin >> x;
            for(int j = 1; j <= cnt; ++j){
                x = g[x][j];
            }
            cout << x << '\n';
        } else {
            cin >> x >> y;
            v1[x * M + y] = 1;
            v2[(x + 1) * M + y] = 1;
            int now_b = (y - 1) / b + 1, x1, x2;//影响哪个块
            //x, y

            x1 = x;
            for(int j = y - 1; j >= l[now_b]; --j){
                if(v2[x1 * M + j]) x1--;
                else if(v1[x1 * M + j]) x1++;
            }
            
            //x + 1, y
            x2 = x + 1;
            for(int j = y - 1; j >= l[now_b]; --j){
                if(v2[x2 * M + j]) x2--;
                else if(v1[x2 * M + j]) x2++;
            }
            swap(g[x1][now_b], g[x2][now_b]);
        }
    }
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int _ = 1; // cin >> T;
    while (_--) slv();
    return 0;
}
/*
3 4 13
2 2
1 1 3
2 1
2 2
2 3
1 2 4
2 1
2 2
2 3
1 2 1
2 1
2 2
2 3
*/

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3600kb

input:

3 4 13
2 2
1 1 3
2 1
2 2
2 3
1 2 4
2 1
2 2
2 3
1 2 1
2 1
2 2
2 3

output:

2
2
1
3
3
1
2
3
2
1

result:

ok 10 numbers

Test #2:

score: 0
Accepted
time: 400ms
memory: 28772kb

input:

3 100000 99997
2 2
2 2
2 3
2 3
2 3
2 3
2 3
1 2 11047
1 1 98732
1 2 90045
1 1 43556
2 1
2 3
1 2 17242
1 1 17027
2 1
1 1 94195
2 1
2 2
2 1
2 3
1 1 34124
1 2 14354
1 2 673
1 2 39812
1 2 35520
1 2 16046
2 3
2 2
1 1 25410
2 3
2 1
2 3
2 2
1 2 55684
2 1
1 2 24811
1 2 92268
1 2 60268
2 2
1 1 89272
1 2 19232...

output:

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

result:

ok 60761 numbers

Test #3:

score: 0
Accepted
time: 5ms
memory: 8612kb

input:

100000 5 20
1 40277 1
2 55431
2 22404
2 29137
2 10206
2 72758
2 92880
1 96104 2
2 12641
1 99618 2
2 88481
1 76531 3
1 91957 5
1 23999 2
2 35922
1 69730 5
1 16353 2
1 90312 1
1 75264 5
2 77283

output:

55431
22404
29137
10206
72758
92880
12641
88481
35922
77283

result:

ok 10 numbers

Test #4:

score: 0
Accepted
time: 0ms
memory: 3728kb

input:

3 5 20
2 3
1 2 2
2 3
1 1 4
2 1
1 2 5
1 1 1
2 1
2 2
2 1
2 1
2 2
2 3
2 3
2 1
2 1
2 1
2 3
2 2
2 3

output:

3
2
2
2
3
2
2
3
1
1
2
2
2
1
3
1

result:

ok 16 numbers

Test #5:

score: -100
Time Limit Exceeded

input:

200 100000 99995
1 180 45150
2 137
1 97 78979
1 14 74747
1 151 41036
1 178 88736
1 26 50618
1 132 72623
1 95 37475
2 184
1 31 44675
1 183 14874
1 66 14597
2 191
2 102
1 27 61558
1 36 39304
2 119
2 185
1 156 50000
2 200
2 152
1 17 51778
1 39 39403
2 168
1 50 67213
1 92 56771
2 28
2 196
1 99 29006
2 4...

output:

137
184
191
102
119
185
200
151
168
27
196
43
73
16
28
64
88
106
139
117
90
131
64
64
107
11
38
149
133
184
166
20
95
185
71
85
151
96
106
103
91
45
195
112
82
113
183
178
47
112
12
185
41
153
77
179
44
165
84
111
192
161
144
33
139
9
37
38
177
45
146
83
88
166
1
180
175
180
12
166
186
44
2
115
124
...

result: