QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#782406#5113. Bridgeguodong#WA 311ms11192kbC++173.0kb2024-11-25 19:59:342024-11-25 19:59:45

Judging History

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

  • [2024-11-25 19:59:45]
  • 评测
  • 测评结果:WA
  • 用时:311ms
  • 内存:11192kb
  • [2024-11-25 19:59:34]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
#define For(i,a,b) for(int i = a; i <= b; ++i)
unordered_map<int,int> M;
int n,m;
int pos(int x,int y){
    return (x - 1) * m + y;
}
vector<vector<vector<pair<int,int>>>> block;
const int N = 1e5 + 10;
struct que{
    int opt;
    int a,b;
}Q[N];
signed main(){
    #ifdef NICEGUODONG
        freopen("data.in","r",stdin);
    #endif
    ios::sync_with_stdio(false);
    int q;
    cin >> n >> m >> q;
    int len = sqrt(m + 2);
    int blocknum = ((m + len - 1) / len);
    block.resize(n + 1,vector<vector<pair<int,int>>>(blocknum));
    auto id = [&](int c){return (c - 1) / len;};
    For(i,1,q){
        int opt,a,b = 0;
        cin >> opt;
        if(opt == 1)
            cin >> a >> b;
        else
            cin >> a;
        Q[i] = que{opt,a,b};
        // pair<int,int> = {ans,id}
        if(opt == 1){
            block[a][id(b)].emplace_back(make_pair(b,a));
            M[pos(a,b)] = a;
            block[a + 1][id(b)].emplace_back(make_pair(b,a + 1));
            M[pos(a + 1,b)] = a + 1;
        }
    }

    For(i,1,n){
        for(int j = 0; j < blocknum; ++j){
            auto &blo = block[i][j];   
            sort(blo.begin(),blo.end());
            int blostart = (j * len + 1);
            int bloend = min((j * len + 1 + len - 1),m);

            if(blo.size() == 0 || blo[blo.size() - 1].first != bloend) blo.emplace_back(make_pair(bloend,i));
            if(blo[0].first != blostart) blo.emplace_back(make_pair(blostart,i));
            M[pos(i,blostart)] = i;M[pos(i,bloend)] = i;
            sort(blo.begin(),blo.end());
        }
    }
    For(i,1,q){
        int opt = Q[i].opt;
        int a,b;
        if(opt == 1){
            a = Q[i].a; b = Q[i].b;
            int loca = M[pos(a,b)];
            int locap = M[pos(a + 1,b)];
            int num = id(b);
            vector<pair<int,int>> tmpa,tmpb;
            auto &bloa = block[loca][num];
            auto &bloap = block[locap][num];
            for(int j = bloa.size() - 1; j >= 0; --j){
                if(bloa[j].first >= b){
                    tmpa.push_back(bloa[j]);
                    M[pos(bloa[j].second,bloa[j].first)] = a + 1;
                    bloa.pop_back();
                }
            }
            
            for(int j = bloap.size() - 1; j >= 0; --j){
                if(bloap[j].first >= b){
                    tmpb.push_back(bloap[j]);
                    M[pos(bloap[j].second,bloap[j].first)] = a;
                    bloap.pop_back();
                }
            }
            reverse(tmpa.begin(),tmpa.end()); reverse(tmpb.begin(),tmpb.end());
            for(auto &x : tmpa) bloap.emplace_back(x);
            for(auto &x : tmpb) bloa.emplace_back(x);
        }
        else{
            a = Q[i].a;
            for(int i = 0; i < blocknum; ++i){
                a = block[a][i][block[a][i].size() - 1].second;
            }
            cout << a << '\n';
        }
    }
    return 0;
}

详细

Test #1:

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

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: 311ms
memory: 11192kb

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 216th numbers differ - expected: '2', found: '1'