QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#347515 | #4631. Interesting String Problem | ucup-team1209 | Compile Error | / | / | C++20 | 3.1kb | 2024-03-09 14:06:46 | 2024-03-09 14:06:48 |
Judging History
answer
#include<bits/stdc++.h>
using std::cin;
using std::cout;
using ll = long long;
const int N = 500005 * 2;
int n, q;
int c[N][26], mx[N], fail[N], tot = 1;
inline int append(int id, int w) {
int p = id, now = ++ tot;
for(mx[now] = mx[p] + 1;p && !c[p][w];p = fail[p])
c[p][w] = now;
if(!p)
fail[now] = 1;
else {
int q = c[p][w];
if(mx[q] == mx[p] + 1) {
fail[now] = q;
} else {
int x = ++tot; mx[x] = mx[p] + 1;
memcpy(c[x], c[q], sizeof(c[0])), fail[x] = fail[q];
for(fail[q] = fail[now] = x;p && c[p][w] == q;p = fail[p])
c[p][w] = x;
}
}
return now;
}
int head[N], next[N];
int size[N];
inline void link(int fa, int x) {
next[x] = head[fa], head[fa] = x;
}
inline ll su_(ll min, ll max) {
return (min + max) * (max - min + 1) / 2;
}
struct pr {
int min, max, cnt, p;
ll sum;
inline void init() {
sum = (ll) cnt * su_(min, max);
}
};
pr bak[N];
ll pre[N];
int cnt;
int right[N];
const int M = 500005 * 21 * 3;
int ls[M], rs[M], su[M], sc;
inline void add(int & x, int p, int l = 1, int r = n) {
if(!x) x = ++ sc;
su[x] += 1;
if(l == r) return ;
int mid = (l + r) >> 1;
if(p <= mid)
add(ls[x], p, l, mid);
else
add(rs[x], p, mid + 1, r);
}
inline int merge(int x, int y) {
if(!x || !y) return x | y;
int z = ++ sc;
su[z] = su[x] + su[y];
ls[z] = merge(ls[x], ls[y]);
rs[z] = merge(rs[x], rs[y]);
return z;
}
inline int kth(int x, int k, int l = 1, int r = n) {
if(l == r) return l;
int mid = (l + r) >> 1;
if(su[ls[x]] >= k) {
return kth(ls[x], k, l, mid);
} else {
return kth(rs[x], k - su[ls[x]], mid + 1, r);
}
}
int root[N], s[N];
inline void dfs0(int x) {
s[x] = right[x];
for(int i = head[x];i;i = next[i]) {
dfs0(i);
size[x] += size[i];
if(!s[x]) s[x] = s[i];
}
}
char S[N];
inline void dfs1(int x) {
bak[++cnt] = {mx[fail[x]] + 1, mx[x], size[x], x};
if(right[x]) add(root[x], right[x]);
bak[cnt].init();
std::vector<std::pair<int, int>> go;
for(int i = head[x];i;i = next[i]) {
go.emplace_back(S[s[i] + mx[x]], i);
}
sort(go.begin(), go.end());
for(auto z : go) {
dfs1(z.second);
root[x] = merge(root[x], root[z.second]);
}
}
int pos[N];
int main() {
std::ios::sync_with_stdio(false), cin.tie(0);
cin >> (S + 1);
n = strlen(S + 1);
int rt = 1;
for(int i = n;i >= 1;--i) {
pos[i] = rt = append(rt, S[i] - 'a');
++ size[pos[i]];
right[pos[i]] = i;
}
for(int i = 2;i <= tot;++i) link(fail[i], i);
dfs0(1);
dfs1(1);
for(int i = 1;i <= cnt;++i) pre[i] = pre[i - 1] + bak[i].sum;
cin >> q;
for(int i = 1;i <= q;++i) {
ll k; cin >> k;
int l = 1, r = cnt + 1;
for(;l + 1 < r;) {
int mid = (l + r) >> 1;
if(pre[mid - 1] < k) {
l = mid;
} else {
r = mid;
}
}
k -= pre[l - 1];
pr s = bak[l];
int L = s.min, R = s.max + 1;
for(;L + 1 < R;) {
int mid = (L + R) >> 1;
if((ll) s.cnt * su_(s.min, mid - 1) < k) {
L = mid;
} else {
R = mid;
}
}
k -= (ll) s.cnt * su_(s.min, L - 1);
ll pc = (k - 1) / L + 1;
cout << kth(root[s.p], pc) + k - (pc - 1) * L - 1 << '\n';
}
}
詳細信息
answer.code: In function ‘int main()’: answer.code:102:13: error: no match for ‘operator>>’ (operand types are ‘std::istream’ {aka ‘std::basic_istream<char>’} and ‘char*’) 102 | cin >> (S + 1); | ~~~ ^~ ~~~~~~~ | | | | | char* | std::istream {aka std::basic_istream<char>} In file included from /usr/include/c++/13/sstream:40, from /usr/include/c++/13/complex:45, from /usr/include/c++/13/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:127, from answer.code:1: /usr/include/c++/13/istream:325:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(void*&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]’ (near match) 325 | operator>>(void*& __p) | ^~~~~~~~ /usr/include/c++/13/istream:325:7: note: conversion of argument 1 would be ill-formed: answer.code:102:19: error: cannot bind non-const lvalue reference of type ‘void*&’ to an rvalue of type ‘void*’ 102 | cin >> (S + 1); | ~~~^~~~ /usr/include/c++/13/istream:201:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]’ (near match) 201 | operator>>(unsigned long long& __n) | ^~~~~~~~ /usr/include/c++/13/istream:201:7: note: conversion of argument 1 would be ill-formed: answer.code:102:19: error: invalid conversion from ‘char*’ to ‘long long unsigned int’ [-fpermissive] 102 | cin >> (S + 1); | ~~~^~~~ | | | char* answer.code:102:19: error: cannot bind rvalue ‘(long long unsigned int)(((char*)(& S)) + 1)’ to ‘long long unsigned int&’ /usr/include/c++/13/istream:197:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long long int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]’ (near match) 197 | operator>>(long long& __n) | ^~~~~~~~ /usr/include/c++/13/istream:197:7: note: conversion of argument 1 would be ill-formed: answer.code:102:19: error: invalid conversion from ‘char*’ to ‘long long int’ [-fpermissive] 102 | cin >> (S + 1); | ~~~^~~~ | | | char* answer.code:102:19: error: cannot bind rvalue ‘(long long int)(((char*)(& S)) + 1)’ to ‘long long int&’ /usr/include/c++/13/istream:192:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]’ (near match) 192 | operator>>(unsigned long& __n) | ^~~~~~~~ /usr/include/c++/13/istream:192:7: note: conversion of argument 1 would be ill-formed: answer.code:102:19: error: invalid conversion from ‘char*’ to ‘long unsigned int’ [-fpermissive] 102 | cin >> (S + 1); | ~~~^~~~ | | | char* answer.code:102:19: error: cannot bind rvalue ‘(long unsigned int)(((char*)(& S)) + 1)’ to ‘long unsigned int&’ /usr/include/c++/13/istream:188:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]’ (near match) 188 | operator>>(long& __n) | ^~~~~~~~ /usr/include/c++/13/istream:188:7: note: conversion of argument 1 would be ill-formed: answer.code:102:19: error: invalid conversion from ‘char*’ to ‘long int’ [-fpermissive] 102 | cin >> (S + 1); | ~~~^~~~ | | | char* answer.code:102:19: error: cannot bind rvalue ‘(long int)(((char*)(& S)) + 1)’ to ‘long int&’ /usr/include/c++/13/istream:184:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]’ (near match) 184 | operator>>(unsigned int& __n) | ^~~~~~~~ /usr/include/c++/13/istream:184:7: note: conversion of argument 1 would be ill-formed: answer.code:102:19: error: invalid conversion from ‘char*’ to ‘unsigned int’ [-fpermissive] 102 | cin >> (S + 1); | ~~~^~~~ | | | char* answer.code:102:19: error: cannot bind rvalue ‘(unsigned ...