QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#837080 | #8701. Border | xrlong | 0 | 0ms | 0kb | C++14 | 3.5kb | 2024-12-29 15:11:53 | 2024-12-29 15:11:55 |
answer
#include <bits/stdc++.h>
using namespace std;
using llt = long long;
using llf = long double;
using ull = unsigned long long;
#define endl '\n'
#ifdef LOCAL
FILE *InFile = freopen("in_out/in.in", "r", stdin), *OutFile = freopen("in_out/out.out", "w", stdout);
#elif !defined(PAI)
FILE *InFile = stdin, *OutFile = stdout;
#endif
const int N = 500003, MOD = 1e9 + 3579, Bs = 2333, Inf = 0x3f3f3f3f;
int n, m, cp[N], q; char d[N];
ull PBs[N];
vector<int> pp[N];
struct Q{
int l, r, k, id, ans;
} cq[N];
class Seg{
private:
struct Node{
int mi = Inf, v;
}nd[N];
bool tag[N];
#define lson (t << 1)
#define rson (t << 1 | 1)
#define mid (l + r >> 1)
void Upd(int t){
nd[t].mi = min(nd[lson].mi, nd[rson].mi);
}
void Dwn(int t){
if(tag[t]){
tag[lson] = tag[rson] = 1;
nd[lson].mi = nd[rson].mi = Inf;
tag[t] = 0;
}
}
void on(int l, int r, int p, int t){
if(l == r) nd[t].mi = nd[t].v;
else{
Dwn(t);
if(p <= mid) on(l, mid, p, lson);
else on(mid + 1, r, p, rson);
Upd(t);
}
}
int mi(int l, int r, int L, int R, int t){
if(l == L && r == R) return nd[t].mi;
Dwn(t);
if(R <= mid) return mi(l, mid, L, R, lson);
else if(L > mid) return mi(mid + 1, r, L, R, rson);
else return min(mi(l, mid, L, mid, lson), mi(mid + 1, r, mid + 1, R, rson));
}
void bld(int l, int r, int t){
if(l == r) nd[t].v = cp[l];
else bld(l, mid, lson), bld(mid + 1, r, rson);
}
#undef lson
#undef rson
#undef mid
public:
int Mi(int l, int r){
return mi(1, m, l, r, 1);
}
void On(int p){
on(1, m, p, 1);
}
void Bld(){
bld(1, m, 1);
}
void Clr(){
tag[1] = 1;
}
} seg;
class HS{
private:
ull hs[N]; int nl = 0, p = 0;
ull Get(int l, int r){
return (hs[r] - hs[l - 1] * PBs[r - l + 1] % MOD + MOD) % MOD;
}
public:
void In(){
deque<char> s;
for(int i = 1; i <= n; ++i){
char c = d[i];
if('A' <= c && c <= 'Z'){
c = c - 'A' + 'a';
s.emplace_back(c);
}else
s.emplace_front(c), ++nl;
}
int len = s.size();
for(int i = 0; i < len; ++i) hs[i + 1] = (hs[i] * Bs + s[i]) % MOD;
}
void Nxt(){
++p;
if('a' <= d[p] && d[p] <= 'z') --nl;
}
ull operator()(int l, int r){
return Get(nl + l, nl + r);
}
} Hs;
bool Chk(int k,int ln){
if(k == ln) return 1;
int p = k + 1; ull hs = Hs(1, k);
while(p + k <= ln){
if(Hs(p, p + k - 1) != hs) return 0;
p += k;
}
return Hs(1, ln - p + 1) == Hs(p, ln);
}
int main(){
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
cin >> n >> d + 1 >> m;
PBs[0] = 1;
for(int i = 1; i <= n; ++i) PBs[i] = PBs[i - 1] * Bs % MOD;
Hs.In();
for(int i = 1; i <= m; ++i){
cin >> cp[i];
pp[cp[i]].emplace_back(i);
}
seg.Bld();
cin >> q;
for(int i = 1; i <= q; ++i) cin >> cq[i].k >> cq[i].l >> cq[i].r, cq[i].id = i;
sort(cq + 1, cq + q + 1, [](const Q &a, const Q &b){return a.k < b.k;});
auto nw = cq + 1, qed = cq + q +1;
int np = 1;
for(int i = 1; i <= n; ++i){
Hs.Nxt();
int t = (i - 1) / np * np;
if(Hs(1, i - t) != Hs(t + 1, i)){
do ++np; while(!Chk(np, i));
seg.Clr();
for(int j = np; j <= i; j += np)
for(auto k : pp[j])
seg.On(k);
}else if(i % np == 0)
for(auto k : pp[i])
seg.On(k);
while(nw != qed && nw->k == i)
nw->ans = seg.Mi(nw->l, nw->r), ++nw;
}
sort(cq + 1, cq + q + 1, [](const Q &a, const Q &b){return a.id < b.id;});
for(int i = 1; i <= n; ++i)
cout << (cq[i].ans >= Inf ? -1 : cq[i].ans) << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Memory Limit Exceeded
Test #1:
score: 0
Memory Limit Exceeded
input:
cbaababaabacbaababaabacbaabacbaababaabacbaaba dabbababbabaabbafabbgbaabfebaabzababbayaabcac
output:
result:
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%