이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
using namespace std ;
const int prime = 37 ;
const int mod = 1e9 + 7 ;
const int maxn = 1e4 + 5 ;
int n, l, v[maxn], dist[maxn][maxn], k, q ;
ll pot[maxn], inv[maxn], pref[maxn], val[maxn] ;
void solve(){
for(int i = 1 ; i <= n ; i++){
for(int j = 1 ; j <= n ; j++){ // dist de i p j
if(i == j || i + l - 1 > n || j + l - 1 > n) continue ;
int ctr = 0 ;
for(int k = 0 ; k < l ; k++) if(v[i+k] != v[j+k]) ctr++ ;
dist[i][j] = dist[j][i] = ctr ;
}
}
}
ll exp(ll a, ll b){
ll ans = 1 ;
while(b){
if(b&1) ans = (ans*a)%mod ;
a = (a*a)%mod ;
b >>= 1 ;
}
return ans ;
}
void solve_hash(){
pot[0] = 1LL ;
for(int i = 1 ; i < maxn ; i++) pot[i] = (pot[i-1]*prime)%mod ;
inv[0] = 1LL ; inv[1] = exp(prime, mod-2) ;
for(int i = 2 ; i < maxn ; i++) inv[i] = (inv[i-1]*inv[1])%mod ;
for(int i = 1 ; i <= n ; i++) pref[i] = (pref[i-1] + (v[i]*pot[i]*1LL)%mod)%mod ;
vector<ll> vals ;
for(int i = 1 ; i + l - 1 <= n ; i++){
ll v1 = pref[i+l-1] ;
if(i - 1 >= 1) v1 = (v1 - pref[i-1] + mod)%mod ;
v1 = (v1*inv[i])%mod ;
vals.push_back(v1) ; val[i] = v1 ;
}
sort(vals.begin(), vals.end()) ;
for(int i = 1 ; i + l - 1 <= n ; i++){
int l = lower_bound(vals.begin(), vals.end(), val[i]) - vals.begin() ;
int r = upper_bound(vals.begin(), vals.end(), val[i]) - vals.begin() ;
cout << (r - l - 1) << " " ;
}
cout << "\n" ;
}
int main(){
ios_base::sync_with_stdio(false) ; cin.tie(NULL) ;
cin >> n >> l ;
for(int i = 1 ; i <= n ; i++) cin >> v[i] ;
// for(int i = 1 ; i <= n ; i++){
// for(int j = 1 ; j <= n ; j++){
// cout << dist[i][j] <<" " ;
// }
// cout << "\n" ;
// }
cin >> q ;
cin >> k ;
if(q == 1 && !k){
solve_hash() ;
exit(0) ;
}
solve() ;
for(int i = 1 ; i + l - 1 <= n ; i++){
int ct = 0 ;
for(int j = 1 ; j + l - 1 <= n ; j++) if(i != j && dist[i][j] <= k) ct++ ;
cout << ct << " " ;
}
cout << "\n" ;
for(int i = 1 ; i < q ; i++){
cin >> k ;
for(int i = 1 ; i + l - 1 <= n ; i++){
int ct = 0 ;
for(int j = 1 ; j + l - 1 <= n ; j++) if(i != j && dist[i][j] <= k) ct++ ;
cout << ct << " " ;
}
cout << "\n" ;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |