QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#932077 | #2743. Seats | KiharaTouma | 0 | 90ms | 35084kb | C++14 | 4.6kb | 2025-03-12 08:07:12 | 2025-03-12 08:07:12 |
Judging History
answer
//qoj2743
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
const int dx[5] = {0, 0, -1, 1, 0}, dy[5] = {0, -1, 0, 0, 1};
int n, m, mx;
vector<int> a[N];
pair<int, int> pos[N];
int t[N*4], tag[N*4], cnt[N*4];
void psd(int p){
t[p<<1] += tag[p];
t[p<<1|1] += tag[p];
tag[p<<1] += tag[p];
tag[p<<1|1] += tag[p];
tag[p] = 0;
}
void upd(int p){
if(t[p<<1] < t[p<<1|1]){
t[p] = t[p<<1];
cnt[p] = cnt[p<<1];
} else if(t[p<<1] > t[p<<1|1]){
t[p] = t[p<<1|1];
cnt[p] = cnt[p<<1|1];
} else {
t[p] = t[p<<1];
cnt[p] = cnt[p<<1] + cnt[p<<1|1];
}
}
void build(int p, int l, int r){
// printf("%d %d %d\n", p, l, r);
if(l == r){
t[p] = tag[p] = 0;
cnt[p] = 1;
} else {
int mid = l + r >> 1;
build(p<<1, l, mid);
build(p<<1|1, mid+1, r);
upd(p);
}
}
void add(int p, int l, int r, int ql, int qr, int v){
// if(p == 1) printf("%d %d %d\n", ql, qr, v);
if(qr < l || r < ql){
return;
} else if(ql <= l && r <= qr){
t[p] += v;
tag[p] += v;
} else {
int mid = l + r >> 1;
psd(p);
add(p<<1, l, mid, ql, qr, v);
add(p<<1|1, mid+1, r, ql, qr, v);
upd(p);
}
}
void upd(int x, int y, int op){
add(1, 1, mx, a[x][y], min(a[x-1][y], a[x][y-1])-1, op);
add(1, 1, mx, a[x][y], min(a[x+1][y], a[x][y-1])-1, op);
add(1, 1, mx, a[x][y], min(a[x-1][y], a[x][y+1])-1, op);
add(1, 1, mx, a[x][y], min(a[x+1][y], a[x][y+1])-1, op);
add(1, 1, mx, max(a[x-1][y], a[x][y-1]), a[x][y]-1, op);
add(1, 1, mx, max(a[x+1][y], a[x][y-1]), a[x][y]-1, op);
add(1, 1, mx, max(a[x-1][y], a[x][y+1]), a[x][y]-1, op);
add(1, 1, mx, max(a[x+1][y], a[x][y+1]), a[x][y]-1, op);
}
void give_initial_chart(int H, int W, vector<int> R, vector<int> C){
n = H;
m = W;
mx = n * m;
build(1, 1, mx);
for(int i = 0; i <= m + 1; ++ i){
a[0].push_back(mx + 1);
a[n+1].push_back(mx + 1);
}
for(int i = 1; i <= n; ++ i){
a[i].resize(m + 2);
a[i][0] = a[i][m+1] = mx + 1;
}
for(int i = 0; i < mx; ++ i){
a[R[i]+1][C[i]+1] = i + 1;
pos[i+1] = make_pair(R[i] + 1, C[i] + 1);
}
for(int i = 1; i <= n; ++ i){
for(int j = 1; j <= m; ++ j){
printf("%d ", a[i][j]);
upd(i, j, 1);
}
puts("");
}
}
int swap_seats(int aa, int bb){
++ aa;
++ bb;
int xa = pos[aa].first, ya = pos[aa].second;
int xb = pos[bb].first, yb = pos[bb].second;
vector<pair<int, int> > cg;
for(int i = 0; i < 5; ++ i){
int xx = xa + dx[i], yy = ya + dy[i];
if(xx >= 1 && xx <= n && yy >= 1 && yy <= m){
cg.push_back(make_pair(xx, yy));
}
xx = xb + dx[i], yy = yb + dy[i];
if(xx >= 1 && xx <= n && yy >= 1 && yy <= m){
cg.push_back(make_pair(xx, yy));
}
}
sort(cg.begin(), cg.end());
for(int i = 0; i < cg.size(); ++ i){
if(!i || cg[i] != cg[i-1]){
upd(cg[i].first, cg[i].second, -1);
}
}
swap(a[xa][ya], a[xb][yb]);
swap(pos[aa], pos[bb]);
for(int i = 0; i < cg.size(); ++ i){
if(!i || cg[i] != cg[i-1]){
upd(cg[i].first, cg[i].second, 1);
}
}
return cnt[1];
}
#ifndef ONLINE_JUDGE
int main(){
// give_initial_chart(2, 3, {0, 1, 1, 0, 0, 1}, {0, 0, 1, 1, 2, 2});
// printf("%d\n", swap_seats(0, 5));
// printf("%d\n", swap_seats(0, 5));
// give_initial_chart(1, 5, {0, 0, 0, 0, 0}, {0, 1, 2, 3, 4});
// printf("%d\n", swap_seats(0, 1));
// printf("%d\n", swap_seats(0, 3));
// printf("%d\n", swap_seats(4, 0));
// give_initial_chart(3, 3, {0, 1, 0, 1, 2, 0, 2, 2, 1}, {1, 2, 2, 0, 2, 0, 0, 1, 1});
give_initial_chart(3, 3, {2, 1, 0, 0, 0, 2, 1, 1, 2}, {2, 2, 2, 1, 0, 1, 1, 0, 0});
// printf("%d\n", cnt[1]);
printf("%d\n", swap_seats(6, 0));
printf("%d\n", swap_seats(5, 7));
printf("%d\n", swap_seats(6, 4));
printf("%d\n", swap_seats(3, 2));
printf("%d\n", swap_seats(0, 2));
printf("%d\n", swap_seats(0, 2));
printf("%d\n", swap_seats(7, 0));
printf("%d\n", swap_seats(7, 0));
printf("%d\n", swap_seats(3, 2));
printf("%d\n", swap_seats(3, 6));
printf("%d\n", swap_seats(0, 2));
printf("%d\n", swap_seats(3, 5));
printf("%d\n", swap_seats(2, 6));
printf("%d\n", swap_seats(2, 0));
printf("%d\n", swap_seats(8, 6));
// return 0;
}
#endif
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 16ms
memory: 35084kb
input:
3 3 5000 2 2 1 2 0 2 0 1 0 0 2 1 1 1 1 0 2 0 6 0 5 7 6 4 3 2 0 2 0 2 7 0 7 0 3 2 3 6 0 2 3 5 2 6 2 0 8 6 0 6 1 3 1 8 8 1 4 2 1 8 2 5 1 3 7 0 6 5 6 3 2 8 8 2 1 3 8 5 6 3 8 0 4 8 6 8 7 8 4 3 3 6 5 0 8 5 1 7 2 6 1 2 5 4 5 1 7 6 8 4 7 3 6 8 8 3 0 3 6 3 0 8 0 5 7 2 0 3 7 5 4 5 3 5 1 0 0 8 7 0 2 5 5 8 7 4...
output:
Unauthorized output
result:
wrong output format Expected integer, but "Unauthorized" found
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Wrong Answer
Test #33:
score: 0
Wrong Answer
time: 90ms
memory: 34124kb
input:
101 101 5000 0 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 0 10 0 11 0 12 0 13 0 14 0 15 0 16 0 17 0 18 0 19 0 20 0 21 0 22 0 23 0 24 0 25 0 26 0 27 0 28 0 29 0 30 0 31 0 32 0 33 0 34 0 35 0 36 0 37 0 38 0 39 0 40 0 41 0 42 0 43 0 44 0 45 0 46 0 47 0 48 0 49 0 50 0 51 0 52 0 53 0 54 0 55 0 56 0 57 0 58 0 ...
output:
Unauthorized output
result:
wrong output format Expected integer, but "Unauthorized" found
Subtask #5:
score: 0
Wrong Answer
Test #44:
score: 0
Wrong Answer
time: 26ms
memory: 35084kb
input:
1 3 50000 0 1 0 2 0 0 0 2 2 0 2 1 0 1 1 0 0 1 1 2 1 2 1 2 0 2 1 0 0 2 2 0 1 2 2 1 2 0 0 1 0 2 1 2 1 0 1 0 1 2 0 1 1 0 0 2 0 2 2 1 0 2 1 0 1 2 2 1 2 1 1 2 0 1 1 2 0 1 0 2 1 2 0 2 2 1 2 0 1 2 1 0 1 0 2 1 1 0 1 0 2 1 1 2 0 2 2 0 1 0 2 0 0 2 1 0 0 2 1 2 2 1 0 1 0 2 1 0 2 1 2 0 1 2 0 1 2 0 2 1 2 0 0 2 1 ...
output:
Unauthorized output
result:
wrong output format Expected integer, but "Unauthorized" found
Subtask #6:
score: 0
Skipped
Dependency #1:
0%