QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#792131#5113. BridgeAweiWA 907ms24232kbC++202.0kb2024-11-29 00:27:412024-11-29 00:27:43

Judging History

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

  • [2024-11-29 00:27:43]
  • 评测
  • 测评结果:WA
  • 用时:907ms
  • 内存:24232kb
  • [2024-11-29 00:27:41]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;

struct Block{

    static const int N = 1e5 + 50;

    int len, n, m, num;
    int belg[320 * N], nxt[320 * N], ed[N];
    map<LL, int> id;

    void init(int _n, int _m){
        n = _n;
        m = _m;
        len = sqrt(_m);
        num = m / len;
        int num = _m / len;
        for(int i = 1; i <= n; i++){
            ed[i] = i;
            for(int j = 1; j <= num; j++) belg[(i - 1) * num + j] = i;
            for(int j = 1; j <  num; j++) nxt[(i - 1) * num + j] = (i - 1) * num + j + 1;
        }
        return;
    }

    void update(int nx, int x){
        int ny = nx + 1, y = x;
        LL xx = 1LL * (nx - 1) * m + x, yy = 1LL * (ny - 1) * m + y;
        int idx = (nx - 1) * num + x / len + (x % len ? 1 : 0), idy = (ny - 1) * num + y / len + (y % len ? 1 : 0);
        if(id.find(xx) != id.end()) idx = id[xx];
        if(id.find(yy) != id.end()) idy = id[yy];

        int bex = belg[idx], bey = belg[idy];
        swap(ed[bex], ed[bey]);

        for(LL i = xx; i <= min(1LL * (nx - 1) * m + (x / len + (x % len ? 1 : 0)) * len, 1LL * nx * m); i++) id[i] = idy;
        for(LL i = yy; i <= min(1LL * (ny - 1) * m + (y / len + (y % len ? 1 : 0)) * len, 1LL * ny * m); i++) id[i] = idx;

        for(int i = nxt[idx]; i; i = nxt[i]) belg[i] = bey;
        for(int i = nxt[idy]; i; i = nxt[i]) belg[i] = bex;

        swap(nxt[idx], nxt[idy]);
        return;
    }

    int query(int x){
        return ed[x];
    }

}B;

void solve(){
    int n, m, q;
    cin >> n >> m >> q;
    B.init(n, m);  
    for(int i = 1; i <= q; i++){
        int opt, a, b;
        cin >> opt >> a;
        if(opt == 1){
            cin >> b;
            B.update(a, b);
        }else{
            cout << B.query(a) << "\n";
        }
    }
    return;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    while(T--){
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: -100
Wrong Answer
time: 907ms
memory: 24232kb

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:

wrong answer 215th numbers differ - expected: '3', found: '2'