QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#792271 | #5113. Bridge | Awei | WA | 819ms | 24264kb | C++20 | 2.0kb | 2024-11-29 08:36:07 | 2024-11-29 08:36:09 |
Judging History
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 + (m % len ? 1 : 0);
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.contains(xx)) idx = id[xx];
if(id.contains(yy)) 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 + 1LL * (x / len + (x % len ? 1 : 0)) * len, 1LL * nx * m); i++) id[i] = idy;
for(LL i = yy; i <= min(1LL * (ny - 1) * m + 1LL * (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;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5632kb
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: 819ms
memory: 24264kb
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: '1'