QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#629534 | #9319. Bull Farm | Andyqian7 | WA | 137ms | 6764kb | C++20 | 4.3kb | 2024-10-11 13:00:13 | 2024-10-11 13:00:25 |
Judging History
answer
#include <bits/stdc++.h>
#define LL unsigned long long
#define rep(i, s, e) for (int i = s; i <= e; i++)
using namespace std;
const int N = 2048;
int n, l, q, t[N][N];
struct node
{
int a, b, no, ans;
friend bool operator<(node x, node y)
{
return x.no < y.no;
}
};
void qr(int &x)
{
x = (getchar() - 48) * 50 + getchar() - 48;
}
struct BIT
{
vector<LL> t;
BIT()
{
t.resize(N >> 6);
}
bool operator[](size_t n)
{
int ind = n >> 6, bit = n & 63;
return t[ind] >> bit & 1;
}
void set(size_t n, bool val)
{
int ind = n >> 6, bit = n & 63;
t[ind] |= 1lu << bit;
}
BIT operator~()
{
BIT cpy = *this;
for (int i = 0; i < N >> 6; i++)
{
cpy.t[i] = ~cpy.t[i];
}
return cpy;
}
void operator|=(const BIT &b)
{
for (int i = 0; i < N >> 6; i++)
{
t[i] |= b.t[i];
}
}
void operator&=(const BIT &b)
{
for (int i = 0; i < N >> 6; i++)
{
t[i] &= b.t[i];
}
}
int _Find_first()
{
int ind = 0;
while (ind << 6 < N && !t[ind])
ind++;
if (ind < N)
return ind << 6 | __builtin_ctzll(t[ind]);
return N;
}
int _Find_next(int n)
{
int ind = n >> 6, bit = n & 63;
int tmp = t[ind];
tmp ^= 1lu << bit;
tmp ^= tmp & ((1lu << bit) - 1);
if (tmp)
{
return ind << 6 | __builtin_ctzll(tmp);
}
ind++;
while (ind << 6 < N && !t[ind])
ind++;
if (ind < N)
return ind << 6 | __builtin_ctzll(t[ind]);
return N;
}
};
int main()
{
int T;
scanf("%d", &T);
while (T--)
{
scanf("%d%d%d\n", &n, &l, &q);
rep(i, 1, l)
{
rep(j, 1, n)
{
qr(t[i][j]);
}
getchar();
}
BIT back[N], pre[N];
rep(i, 1, n)
{
back[i].set(i, 1), pre[i].set(i, 1);
}
vector<node> v[N];
rep(i, 1, q)
{
int a, b, c;
qr(a), qr(b), qr(c), getchar();
v[c].push_back({a, b, i});
}
for (auto &[a, B, _, ans] : v[0])
{
ans = back[a][B];
}
BIT back1[N], pre1[N];
auto add = [&](int a, int b)
{
BIT newbacka = back1[b], newpreb = pre1[a];
newbacka &= ~back1[a], newpreb &= ~pre1[b];
for (int i = newbacka._Find_first(); i < N; i = newbacka._Find_next(i))
{
pre[i] |= pre1[a];
}
for (int i = newpreb._Find_first(); i < N; i = newpreb._Find_next(i))
{
back[i] |= back1[b];
}
};
rep(i, 1, l)
{
int cnt[N] = {};
rep(j, 1, n)
cnt[t[i][j]]++;
int c = 0, emp;
rep(j, 1, n) c += !cnt[j];
rep(i, 1, n)
back1[i] = back[i],
pre1[i] = pre[i];
if (c <= 1)
{
if (!c)
{
rep(j, 1, n)
{
add(j, t[i][j]);
}
}
else
{
vector<int> C;
rep(j, 1, n)
{
if (!cnt[j])
emp = j;
if (cnt[t[i][j]] == 2)
C.push_back(j);
}
for (auto c : C)
add(c, emp);
}
}
for (auto &[a, B, _, ans] : v[i])
{
ans = back[a][B];
}
}
vector<node> all;
rep(i, 0, l)
{
for (auto j : v[i])
all.push_back(j);
}
sort(all.begin(), all.end());
for (auto i : all)
{
putchar(i.ans + 48);
}
puts("");
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 6176kb
input:
2 5 2 4 0305040201 0404040404 030300 020500 050102 020501 6 2 4 030603010601 010203060504 030202 060402 050602 060401
output:
1011 0100
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 6184kb
input:
1 3 3 6 020202 030301 030201 020102 030203 010201 010303 020303 010202
output:
010101
result:
ok single line: '010101'
Test #3:
score: -100
Wrong Answer
time: 137ms
memory: 6764kb
input:
200 10 10 5000 01060:04020305080709 0103070:060204050908 09070503080401060:02 050308010204090:0607 03010502040607080:09 03080109020504060:07 06050:09040302080107 07080305010409060:02 030809010:0204060507 0:060908070201050304 060700 090:03 09080: 070405 010703 0:0100 080601 030600 070206 0:0:09 08040...
output:
011110001101001101111111111111110101111110110111000110110110100011010101011101111111111101001101111110111111110111111111111101011111111110011111111101111111110001100101010111111111111110111011001111111101111111111111101111111111111111011011010100111110100011110111011100111111101110111111010001110110...
result:
wrong answer 1st lines differ - expected: '011110001101101111111111111111...1111111111111111101111111111111', found: '011110001101001101111111111111...1111111111111110100111111111011'