QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#766421 | #8334. Gene | qilou | TL | 16ms | 3864kb | C++23 | 3.7kb | 2024-11-20 17:16:13 | 2024-11-20 17:16:22 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define ll long long
#define yes cout<<"Yes\n";
#define no cout<<"No\n";
#define ok cout<<"OK\n";
#define pii pair<int,int>
#define endl "\n"
typedef long long LL;
using namespace std;
// const int N=5e5+10;
// int mod=1e9+7;
// int p[N];
// int a[N];
// struct node {
// int l,r,mn,mx,res;
// }tr[N*4];
// int find(int x) {
// if(x==p[x])return x;
// return p[x]=find(p[x]);
// }
// void js(int p,int l,int r) {
// tr[p]={l,r};
// if(l==r) {
// tr[p].mn=tr[p].res=tr[p].mx=a[l];
// return;
// }
// int mid=(l+r)/2;
// js(p,l,mid);
// js(p,mid+1,r);
// tr[p].mn=min(tr[p*2].mn,tr[p*2+1].mn);
// tr[p].mx=max(tr[p*2].mx,tr[p*2+1].mx);
// }
// int findmn(int p,int l,int r,int pl,int pr) {
// if(pl<=r&&r<=pr) {
// return tr[p].mn;
// }
// int mid=(l+r)/2;
// if(pr<=mid)return findmn(p,l,mid,pl,pr);
// else if(pl>mid)return findmn(p,mid+1,r,pl,pr);
// else return min(findmn(p,l,mid,pl,pr),findmn(p,mid+1,r,pl,pr) );
// }
//
// int findmx(int p,int l,int r,int pl,int pr) {
// if(pl<=r&&r<=pr) {
// return tr[p].mx;
// }
// int mid=(l+r)/2;
// if(pr<=mid)return findmx(p,l,mid,pl,pr);
// else if(pl>mid)return findmx(p,mid+1,r,pl,pr);
// else return max(findmx(p,l,mid,pl,pr),findmx(p,mid+1,r,pl,pr) );
// }
//5 7 3 6
const int N=3e5+10;
int dfn[N],low[N];
using ull = unsigned long long;
const ull P = 133331;
struct Hash {
const int n;
std::vector<ull> p, h1, h2;
std::string s;
Hash(std::string s_) : s(s_), n(s_.size() - 1), h1(n + 2), h2(n + 2), p(n + 2) { // idx by 1
p[0] = 1; h1[0] = 0, h2[0] = 0;
for(int i = 1 ; i <= n ; i ++) p[i] = p[i - 1] * P;
for(int i = 1 ; i <= n ; i ++) h1[i] = h1[i - 1] * P + s_[i];
for(int i = n ; i >= 1 ; i --) h2[i] = h2[i + 1] * P + s_[i];
}
ull get(int l, int r) { // s[l] s[l + 1] ... s[r]
return h1[r] - h1[l - 1] * p[r - l + 1];
}
ull get_unnomal(int l, int r, int L, int R) { // s[l] s[l + 1] ... s[r] s[L] s[L + 1]...s[R]
return get(l, r) * p[R - L + 1] + get(L, R);
}
ull get_rev(int l, int r) { // s[r] s[r - 1] ... s[l]
return h2[l] - h2[r + 1] * p[r - l + 1];
}
ull modify(std::string &s, int idx, char c) { // 修改 idx 位为 x的hash值
return h1[n] + p[n - idx] * (c - s[idx]);
}
};
void solve() {
int n,m,q,k;
cin>>n>>q>>m>>k;
vector<Hash> ls;
for(int i=1;i<=n;i++) {
string s;
cin>>s;
s=" "+s;
Hash c(s);
ls.push_back(c);
//cout<<ls[i-1].get(1,2)<<endl;;
}
while (q--)
{
string s;
cin>>s;
//cin>>s;
s=" "+s;
int ans=0;
Hash c(s);
for(auto o:ls){
int cnt=0;
int nowl=1,nowr=m+1;
for(int i=1;nowl<=m&&i<=k+1;i++){
int l=nowl,r=nowr;
while(l<r){
int mid=(l+r)/2;
int pv=c.get(l,mid),mv=o.get(l,mid);
if(pv==mv){
l=mid+1;
}else r=mid;
}
if(l<=m)cnt++;
nowl=l+1;
}
//cout<<cnt<<" "<<s<<endl;
if(cnt<=k)ans++;
}
cout<<ans<<endl;
}
}
signed main(){
#ifdef ACM
freopen("input.in","r",stdin);
freopen("output.out","w",stdout);
#endif
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int T=1;
//init();
//cin>>T;
while(T--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3636kb
input:
6 4 4 1 kaki kika manu nana tepu tero kaka mana teri anan
output:
2 2 1 0
result:
ok 4 number(s): "2 2 1 0"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
8 6 7 3 delphis aduncus peronii plumbea clymene hectori griseus electra delphis helpiii perphii clumeee eleelea ddlpcus
output:
1 1 2 2 1 2
result:
ok 6 numbers
Test #3:
score: 0
Accepted
time: 6ms
memory: 3712kb
input:
300 300 9 10 dmzampmxe bteaudaxb fjfwhhsfq btnfzqtyp ijjrkbyht hkizlvgdc ukwsnhiff hacsdrwyl fbjabnhst ktsxbgbtg jopdbsdsr yxdxxjltd daechsouq klrglgwbn llzhqzlor ckdedutfn lkjxcryoe zvusjevtz cevrcdltg tdmmvvpkj davfsweem spcfhcitm aohsfqrqh lblehevpj soaqryimp tbxlulxmn tnlzbkhda ukfhjykuk eghpuua...
output:
300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 ...
result:
ok 300 numbers
Test #4:
score: 0
Accepted
time: 6ms
memory: 3716kb
input:
300 300 10 10 qoecfhznxd hkoaiunzim lhtzdmbrjs vqesfzpiuv amsgqjxmbq vptwyshswk sofrfmsrpf eplnexhmoh gcjtqavjga azytravylz akpuemdfpq oxkacujrhg bsgieguzuo bojvtfkbdf pmqmrbceej zgpfkqfeyx qkdbfrxqcj effpkigdcw kqyqmgjdzr czlbscrnaq rymhkenugz fuybclhlhj rtmclsdvwy rhfbfqfrfs bpemthjxfi jtcvqyltgj ...
output:
300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 300 ...
result:
ok 300 numbers
Test #5:
score: 0
Accepted
time: 10ms
memory: 3784kb
input:
300 300 11 10 lonodhfyrbj njzuczzviuj usovdmjfjco bljtnmsjhut kkkeybjagck tbuivwfvjit qhjzqocsvod ayobjbagcgv dudupzsvqpe tcapottzyte wdevxapvocr hsvdfaahndr jjplhydycgn srrtpmqmygw gjjbcchwcur uivvuqldryj amlidxfsobz ofpnwqrzhly eolqcyidojx jpiybuplwcf jmxxtjnwsru ivkbixrgnph txjjppqkxgu vmmbwxmvjd...
output:
96 109 114 108 108 95 108 109 113 106 104 94 111 108 95 107 91 99 111 101 105 116 117 109 106 115 116 96 108 95 114 87 94 116 95 97 104 107 91 103 103 92 115 103 120 102 115 103 101 105 108 95 118 106 91 98 99 115 101 106 120 91 118 91 111 99 104 101 104 96 98 116 111 110 107 118 94 96 103 107 108 1...
result:
ok 300 numbers
Test #6:
score: 0
Accepted
time: 8ms
memory: 3716kb
input:
300 300 11 10 bacdccbdbba ccabcddcbdc ddbcccadbab cbdcabcddbd ccddbaacaba addabdbbcba ccbcbadadac cbadacadcbb abddacbcada ccccbdccdda dadcbdbddda acbdccdbcdc bbbbdbcdcbc cdcbabdacda acbcdaaadbc dccbdcddcca abbacddccba cccabdcacda ddcadbabbca babaaabbabd dabdaacaddc cabcacbdcda cdbbbdcddcd cdbdccadda...
output:
287 292 286 279 286 285 289 289 294 284 287 291 287 286 283 275 284 291 289 289 286 291 287 282 290 282 278 288 285 285 285 289 287 283 287 290 287 288 292 288 286 290 290 288 289 285 289 276 286 289 283 279 288 288 288 289 289 286 281 288 291 290 287 289 285 280 289 287 286 295 284 285 286 279 284 ...
result:
ok 300 numbers
Test #7:
score: 0
Accepted
time: 16ms
memory: 3864kb
input:
300 300 15 10 bbjbbbjbjbbjjbb bbjbbbbjbjjjbbb jbjjjjbjbbjbjbb bbjjjbjbbjbbjbb bjbjjjbbbbbbbbb bjbjbjjjbjjjjjj bbbjjbbjjjbjjjb bjbbjbjbjbjjjjj bbbbbjbjjjjbjbj bbbjbbbbjbjjjjb jjjbbbbbbbjjbbj jbbjjjbbbbjbjbb bjjbbjbjbjbjjjj bbjbbjbjbjjbbbb jbjjjjbbbbjjjbj bbbbjbbbbbjjbjj jbjbjjbbjjbjjjb jjbjbjjbbbjjjj...
output:
279 285 291 281 283 277 281 280 282 280 286 290 279 281 279 286 279 281 279 284 283 279 288 276 288 285 285 278 283 281 284 279 286 283 273 286 286 282 282 288 289 275 279 280 286 288 274 273 280 288 280 283 280 280 285 282 277 282 284 280 284 282 291 280 283 280 288 288 287 275 275 286 286 284 281 ...
result:
ok 300 numbers
Test #8:
score: -100
Time Limit Exceeded
input:
300 300 59999 10 qfsnaxtgssrzcvtxmwamjekdujnlymqklnmmwqpgmqljtgtgcitmjkinsdsjijxjtxrvhqjxupgryqcyatbjjzvcosvynyyaohyeqkrrqlbwsabqtkbwtkgnyadcpwwqswkokpkjblkfyrdeugvpvzefduxwtxzdnqvflsagkfwtowcjuseqqzbgrnxapdpvnuiwexirodxtmenhmvyafucenakdqwjfsepgawzpfqozzybdbkqoxyverfgtrezznsvwpjeeiahjcaatwbsuoyxwpwi...