QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#584000 | #9356. LRU Algorithm | kevinshan# | WA | 236ms | 6016kb | C++14 | 1.7kb | 2024-09-23 02:58:38 | 2024-09-23 02:58:38 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const int BK = 100003;
const ull MOD = (1ll << 61) - 1;
const int BASE = 1445;
const int N = 5010;
int Case, n, q;
vector<pair<ull, int>> g[BK];
int a[N];
inline ull Mul(ull a, ull b) {
return (__int128)a * b % MOD;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> Case;
while (Case--) {
cin >> n >> q;
vector<int> clr;
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 1, k, x; i <= q; ++i) {
cin >> k;
int bkid = 0;
ull hs = 0;
for (int j = 1, x, la = -1; j <= k; ++j) {
cin >> x;
if (x || la) {
bkid = (1ll * bkid * BASE + x + 1) % BK;
hs = (Mul(hs, BASE) + x + 1) % MOD;
}
la = x;
}
g[bkid].push_back({hs, i});
clr.push_back(bkid);
}
vector<bool> ans(q + 1);
vector<int> buf(1, 0);
for (int t = 1; t <= n; ++t) {
auto it = find(buf.begin(), buf.end(), a[t]);
if (it == buf.end()) { buf.insert(buf.begin(), a[t]); }
else { buf.erase(it); buf.insert(buf.begin(), a[t]); }
int bkid = 0;
ull hs = 0;
for (auto x : buf) {
bkid = (1ll * bkid * BASE + x + 1) % BK;
hs = (Mul(hs, BASE) + x + 1) % MOD;
for (auto [hsval, id] : g[bkid]) if (hsval == hs) ans[id] = 1;
}
}
for (int i = 1; i <= q; ++i) cout << (ans[i] ? "Yes" : "No") << '\n';
for (auto x : clr) g[x].clear();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5944kb
input:
1 7 5 4 3 4 2 3 1 4 1 4 2 2 3 3 3 2 1 4 4 1 3 2 4 3 4 0 0
output:
Yes No No Yes Yes
result:
ok 5 lines
Test #2:
score: -100
Wrong Answer
time: 236ms
memory: 6016kb
input:
105 50 10 23 30 34 20 27 11 21 29 12 7 21 42 45 48 8 15 6 16 19 35 16 14 29 11 31 18 22 4 45 22 14 4 13 40 43 48 27 15 15 15 15 10 15 11 31 37 34 34 50 14 1 25 2 23 6 3 29 21 11 4 12 29 18 39 5 29 21 11 27 20 6 21 10 9 3 34 14 7 49 36 36 43 50 50 35 8 12 29 21 11 27 20 34 30 9 11 27 20 34 30 23 0 0 ...
output:
No No Yes No Yes No No Yes Yes No Yes Yes Yes Yes No Yes No No No Yes Yes Yes No No No No Yes Yes Yes No No No No Yes Yes Yes No No No No No No No No Yes No No No Yes Yes Yes Yes No No Yes No No No Yes Yes Yes Yes No No Yes No No No Yes No Yes No Yes No Yes No No No Yes Yes Yes No No No No No No Yes...
result:
wrong answer 44th lines differ - expected: 'Yes', found: 'No'