QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#489204 | #8819. CNOI Knowledge | Yansuan_HCl | WA | 211ms | 17328kb | C++14 | 2.3kb | 2024-07-24 18:55:21 | 2024-07-24 18:55:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define U(i,l,r) for (int i(l),END##i(r); i<=END##i; ++i)
#define D(i,l,r) for (int i(l),END##i(r); i>=END##i; --i)
#define ms(x, v) memset(x, v, sizeof(x))
#define il __attribute__((always_inline))
#define vc vector
#define ar array
#define pb push_back
#define eb emplace_back
#define el '\n'
using ll = long long;
const int N = 1003;
int n; int dist[N][N]; int s[N];
// 子串对应从 everything 到终结点的路径
// struct sam {
// map<int, int> ch;
// int tag, link, len;
// } tr[N * 2]; int ptr, last;
// void init() { ptr = 0; tr[0].link = -1; last = 0; }
// void append(int c) {
// int p = ++ptr; tr[p].len = tr[last].len + 1;
// int u = last; last = p;
// while (u != -1 && !tr[u].ch[c]) {
// tr[u].ch[c] = p;
// u = tr[u].link;
// }
// if (u != -1) {
// int q = tr[u].ch[c];
// if (tr[q].len == tr[u].len + 1) tr[p].link = q;
// else {
// int r = ++ptr; tr[r] = tr[q]; tr[r].tag = 0; tr[r].len = tr[u].len + 1;
// tr[q].link = tr[p].link = r;
// while (u != -1 && tr[u].ch[c] == q) {
// tr[u].ch[c] = r;
// u = tr[u].link;
// }
// }
// }
const ll P = 998244353, BA = 114514;
ll pb[N];
ll hsh[N];
ll f[N][N];
map<pair<ll, int>, int> last;
void insert(int p, int c) {
hsh[p] = hsh[p - 1] * BA + c;
f[p][p] = 1;
int delta = 0, d[N] {};
D (i, p, 1) {
ll h = ((hsh[p] - hsh[i - 1] * pb[p - i + 1]) % P + P) % P;
int j = last[{h, p - i + 1}];
if (j) {
U (k, 0, p - i)
assert(s[j + k] == s[i + k]);
}
assert(j < i);
++d[j]; last[{h, p - i + 1}] = i;
}
D (i, p - 1, 1) {
delta += d[i];
f[i][p] = f[i][p - 1] + (p - i + 1) - delta;
}
}
int ask(int l, int r) {
cout << "? " << l << ' ' << r << endl;
int v; cin >> v;
return v;
}
int main() {
pb[0] = 1; U (i, 1, N - 1) pb[i] = pb[i - 1] * BA % P;
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
ios::sync_with_stdio(0);
cin >> n;
s[1] = 1;
insert(1, 1);
int p = 1;
U (i, 2, n) {
int l = 0, r = i - 1;
while (l < r) {
int mid((l + r + 1) >> 1), cur = ask(mid, i);
if (cur == f[mid][i - 1] + (i - mid + 1))
r = mid - 1;
else
l = mid;
}
if (l) s[i] = s[l];
else s[i] = ++p;
insert(i, s[i]);
}
cout << "!";
U (i, 1, n)
cout << ' ' << s[i];
cout << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5736kb
input:
12 3 6 6 10 10 15 10 21 15 27 20 14 6 9 20 34 43 19 9 5 2 25 8 5 25 9 19
output:
? 1 2 ? 1 3 ? 2 4 ? 1 4 ? 2 5 ? 1 5 ? 3 6 ? 1 6 ? 3 7 ? 1 7 ? 2 7 ? 4 8 ? 6 8 ? 5 8 ? 4 9 ? 2 9 ? 1 9 ? 5 10 ? 7 10 ? 8 10 ? 9 10 ? 5 11 ? 8 11 ? 9 11 ? 6 12 ? 9 12 ? 7 12 ! 1 2 3 4 5 6 2 5 7 7 5 6
result:
ok Accepted. 27 queries used.
Test #2:
score: -100
Wrong Answer
time: 211ms
memory: 17328kb
input:
1000 3 5 2 3 2 7 11 8 5 2 11 3 2 11 5 7 15 8 11 15 8 11 19 7 3 2 19 4 3 2 23 5 3 2 20 5 3 2 23 5 3 2 23 9 5 7 31 14 8 11 31 15 7 5 41 16 8 11 45 15 7 3 2 55 20 7 5 58 21 8 16 11 68 21 8 16 12 69 21 8 16 12 80 26 12 20 16 79 24 12 20 16 89 24 12 20 16 87 26 11 5 8 100 32 11 5 8 100 31 11 5 8 112 31 1...
output:
? 1 2 ? 1 3 ? 2 3 ? 2 4 ? 3 4 ? 2 5 ? 1 5 ? 3 6 ? 4 6 ? 5 6 ? 3 7 ? 5 7 ? 6 7 ? 4 8 ? 6 8 ? 5 8 ? 4 9 ? 6 9 ? 5 9 ? 5 10 ? 7 10 ? 6 10 ? 5 11 ? 8 11 ? 9 11 ? 10 11 ? 6 12 ? 9 12 ? 10 12 ? 11 12 ? 6 13 ? 9 13 ? 11 13 ? 12 13 ? 7 14 ? 10 14 ? 12 14 ? 13 14 ? 7 15 ? 11 15 ? 13 15 ? 14 15 ? 8 16 ? 12 16...
result:
wrong answer Wrong Answer.