#include "bits/stdc++.h"
#define int long long
#define all(v) v.begin() , v.end()
#define sz(a) (int)a.size()
using namespace std;
const int N = 5005;
void _(){
int n,k,q;
cin >> n >> k >> q;
int a[n+5],b[n+5];
for(int i=1;i<=n;i++) cin >> a[i];
for(int i=1;i<=n;i++) cin >> b[i];
bitset<N> bs[N];
for(int i=1;i+k-1<=n;i++) for(int j=i;j<=i+k-1;j++) bs[i][a[j]]=1;
int ans[n+5][n+5],tot[n+5];
memset(ans,-1,sizeof(ans));
memset(tot,0,sizeof(tot));
for(int i=1;i+k-1<=n;i++){
int res = 0,p = 0;
while(p<n){
p++;
if(bs[i][b[p]]) res++;
if(p>k && bs[i][b[p-k]]) res--;
if(p>=k){
ans[i][p-k+1]=res;
tot[res]++;
}
}
}
for(int i=k;i>=0;i--){
if(tot[i]){
cout << i << ' ' << tot[i] << '\n';
break;
}
}
while(q--){
int ind; cin >> ind;
for(int i=1;i<=n;i++) if(ans[ind+1][i]!=-1) tot[ans[ind+1][i]]--;
if(ind>=k){
for(int i=1;i<=n;i++) if(ans[ind-k+1][i]!=-1) tot[ans[ind-k+1][i]]--;
}
bs[ind+1][a[ind+1]]=0;
if(ind>=k) bs[ind-k+1][a[ind]]=0;
swap(a[ind],a[ind+1]);
bs[ind+1][a[ind+1]]=1;
if(ind>=k) bs[ind-k+1][a[ind]]=1;
int p = 0, res = 0;
while(p<n){
p++;
if(bs[ind+1][b[p]]) res++;
if(p>k && bs[ind+1][b[p-k]]) res--;
if(p>=k){
//cout << ind+1 << ' ' << p-k+1 << ' ' << res << '\n';
ans[ind+1][p-k+1]=res;
tot[res]++;
}
}
if(ind>=k){
p = 0, res = 0;
while(p<n){
p++;
if(bs[ind-k+1][b[p]]) res++;
if(p>k && bs[ind-k+1][b[p-k]]) res--;
if(p>=k){
//cout << ind-k+1 << ' ' << p-k+1 << ' ' << res << '\n';
ans[ind-k+1][p-k+1]=res;
tot[res]++;
}
}
}
for(int i=k;i>=0;i--){
if(tot[i]){
cout << i << ' ' << tot[i] << '\n';
break;
}
}
}
}
int32_t main(){
cin.tie(0); ios::sync_with_stdio(0);
int tc=1;//cin >> tc;
while(tc--) _();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
3408 KB |
Output is correct |
2 |
Correct |
3 ms |
3408 KB |
Output is correct |
3 |
Correct |
4 ms |
3552 KB |
Output is correct |
4 |
Correct |
3 ms |
3408 KB |
Output is correct |
5 |
Correct |
3 ms |
3408 KB |
Output is correct |
6 |
Correct |
4 ms |
3408 KB |
Output is correct |
7 |
Correct |
4 ms |
3408 KB |
Output is correct |
8 |
Correct |
3 ms |
3408 KB |
Output is correct |
9 |
Correct |
4 ms |
3408 KB |
Output is correct |
10 |
Correct |
5 ms |
3556 KB |
Output is correct |
11 |
Correct |
4 ms |
3408 KB |
Output is correct |
12 |
Correct |
4 ms |
3408 KB |
Output is correct |
13 |
Correct |
4 ms |
3408 KB |
Output is correct |
14 |
Correct |
4 ms |
3408 KB |
Output is correct |
15 |
Correct |
4 ms |
3408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
3408 KB |
Output is correct |
2 |
Correct |
3 ms |
3408 KB |
Output is correct |
3 |
Correct |
4 ms |
3552 KB |
Output is correct |
4 |
Correct |
3 ms |
3408 KB |
Output is correct |
5 |
Correct |
3 ms |
3408 KB |
Output is correct |
6 |
Correct |
4 ms |
3408 KB |
Output is correct |
7 |
Correct |
4 ms |
3408 KB |
Output is correct |
8 |
Correct |
3 ms |
3408 KB |
Output is correct |
9 |
Correct |
4 ms |
3408 KB |
Output is correct |
10 |
Correct |
5 ms |
3556 KB |
Output is correct |
11 |
Correct |
4 ms |
3408 KB |
Output is correct |
12 |
Correct |
4 ms |
3408 KB |
Output is correct |
13 |
Correct |
4 ms |
3408 KB |
Output is correct |
14 |
Correct |
4 ms |
3408 KB |
Output is correct |
15 |
Correct |
4 ms |
3408 KB |
Output is correct |
16 |
Correct |
225 ms |
190820 KB |
Output is correct |
17 |
Correct |
233 ms |
188264 KB |
Output is correct |
18 |
Correct |
194 ms |
188848 KB |
Output is correct |
19 |
Correct |
191 ms |
191060 KB |
Output is correct |
20 |
Correct |
261 ms |
198968 KB |
Output is correct |
21 |
Correct |
212 ms |
184712 KB |
Output is correct |
22 |
Correct |
196 ms |
197732 KB |
Output is correct |
23 |
Correct |
230 ms |
182080 KB |
Output is correct |
24 |
Correct |
248 ms |
191920 KB |
Output is correct |
25 |
Correct |
219 ms |
180688 KB |
Output is correct |
26 |
Correct |
234 ms |
195160 KB |
Output is correct |
27 |
Correct |
221 ms |
184000 KB |
Output is correct |
28 |
Correct |
207 ms |
183520 KB |
Output is correct |
29 |
Correct |
189 ms |
195424 KB |
Output is correct |
30 |
Correct |
178 ms |
190276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
3408 KB |
Output is correct |
2 |
Correct |
3 ms |
3408 KB |
Output is correct |
3 |
Correct |
4 ms |
3552 KB |
Output is correct |
4 |
Correct |
3 ms |
3408 KB |
Output is correct |
5 |
Correct |
3 ms |
3408 KB |
Output is correct |
6 |
Correct |
4 ms |
3408 KB |
Output is correct |
7 |
Correct |
4 ms |
3408 KB |
Output is correct |
8 |
Correct |
3 ms |
3408 KB |
Output is correct |
9 |
Correct |
4 ms |
3408 KB |
Output is correct |
10 |
Correct |
5 ms |
3556 KB |
Output is correct |
11 |
Correct |
4 ms |
3408 KB |
Output is correct |
12 |
Correct |
4 ms |
3408 KB |
Output is correct |
13 |
Correct |
4 ms |
3408 KB |
Output is correct |
14 |
Correct |
4 ms |
3408 KB |
Output is correct |
15 |
Correct |
4 ms |
3408 KB |
Output is correct |
16 |
Correct |
225 ms |
190820 KB |
Output is correct |
17 |
Correct |
233 ms |
188264 KB |
Output is correct |
18 |
Correct |
194 ms |
188848 KB |
Output is correct |
19 |
Correct |
191 ms |
191060 KB |
Output is correct |
20 |
Correct |
261 ms |
198968 KB |
Output is correct |
21 |
Correct |
212 ms |
184712 KB |
Output is correct |
22 |
Correct |
196 ms |
197732 KB |
Output is correct |
23 |
Correct |
230 ms |
182080 KB |
Output is correct |
24 |
Correct |
248 ms |
191920 KB |
Output is correct |
25 |
Correct |
219 ms |
180688 KB |
Output is correct |
26 |
Correct |
234 ms |
195160 KB |
Output is correct |
27 |
Correct |
221 ms |
184000 KB |
Output is correct |
28 |
Correct |
207 ms |
183520 KB |
Output is correct |
29 |
Correct |
189 ms |
195424 KB |
Output is correct |
30 |
Correct |
178 ms |
190276 KB |
Output is correct |
31 |
Runtime error |
23 ms |
9808 KB |
Execution killed with signal 11 |
32 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
3408 KB |
Output is correct |
2 |
Correct |
3 ms |
3408 KB |
Output is correct |
3 |
Correct |
4 ms |
3552 KB |
Output is correct |
4 |
Correct |
3 ms |
3408 KB |
Output is correct |
5 |
Correct |
3 ms |
3408 KB |
Output is correct |
6 |
Correct |
4 ms |
3408 KB |
Output is correct |
7 |
Correct |
4 ms |
3408 KB |
Output is correct |
8 |
Correct |
3 ms |
3408 KB |
Output is correct |
9 |
Correct |
4 ms |
3408 KB |
Output is correct |
10 |
Correct |
5 ms |
3556 KB |
Output is correct |
11 |
Correct |
4 ms |
3408 KB |
Output is correct |
12 |
Correct |
4 ms |
3408 KB |
Output is correct |
13 |
Correct |
4 ms |
3408 KB |
Output is correct |
14 |
Correct |
4 ms |
3408 KB |
Output is correct |
15 |
Correct |
4 ms |
3408 KB |
Output is correct |
16 |
Correct |
5 ms |
3408 KB |
Output is correct |
17 |
Incorrect |
5 ms |
3408 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
3408 KB |
Output is correct |
2 |
Correct |
3 ms |
3408 KB |
Output is correct |
3 |
Correct |
4 ms |
3552 KB |
Output is correct |
4 |
Correct |
3 ms |
3408 KB |
Output is correct |
5 |
Correct |
3 ms |
3408 KB |
Output is correct |
6 |
Correct |
4 ms |
3408 KB |
Output is correct |
7 |
Correct |
4 ms |
3408 KB |
Output is correct |
8 |
Correct |
3 ms |
3408 KB |
Output is correct |
9 |
Correct |
4 ms |
3408 KB |
Output is correct |
10 |
Correct |
5 ms |
3556 KB |
Output is correct |
11 |
Correct |
4 ms |
3408 KB |
Output is correct |
12 |
Correct |
4 ms |
3408 KB |
Output is correct |
13 |
Correct |
4 ms |
3408 KB |
Output is correct |
14 |
Correct |
4 ms |
3408 KB |
Output is correct |
15 |
Correct |
4 ms |
3408 KB |
Output is correct |
16 |
Correct |
225 ms |
190820 KB |
Output is correct |
17 |
Correct |
233 ms |
188264 KB |
Output is correct |
18 |
Correct |
194 ms |
188848 KB |
Output is correct |
19 |
Correct |
191 ms |
191060 KB |
Output is correct |
20 |
Correct |
261 ms |
198968 KB |
Output is correct |
21 |
Correct |
212 ms |
184712 KB |
Output is correct |
22 |
Correct |
196 ms |
197732 KB |
Output is correct |
23 |
Correct |
230 ms |
182080 KB |
Output is correct |
24 |
Correct |
248 ms |
191920 KB |
Output is correct |
25 |
Correct |
219 ms |
180688 KB |
Output is correct |
26 |
Correct |
234 ms |
195160 KB |
Output is correct |
27 |
Correct |
221 ms |
184000 KB |
Output is correct |
28 |
Correct |
207 ms |
183520 KB |
Output is correct |
29 |
Correct |
189 ms |
195424 KB |
Output is correct |
30 |
Correct |
178 ms |
190276 KB |
Output is correct |
31 |
Correct |
5 ms |
3408 KB |
Output is correct |
32 |
Incorrect |
5 ms |
3408 KB |
Output isn't correct |
33 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
3408 KB |
Output is correct |
2 |
Correct |
3 ms |
3408 KB |
Output is correct |
3 |
Correct |
4 ms |
3552 KB |
Output is correct |
4 |
Correct |
3 ms |
3408 KB |
Output is correct |
5 |
Correct |
3 ms |
3408 KB |
Output is correct |
6 |
Correct |
4 ms |
3408 KB |
Output is correct |
7 |
Correct |
4 ms |
3408 KB |
Output is correct |
8 |
Correct |
3 ms |
3408 KB |
Output is correct |
9 |
Correct |
4 ms |
3408 KB |
Output is correct |
10 |
Correct |
5 ms |
3556 KB |
Output is correct |
11 |
Correct |
4 ms |
3408 KB |
Output is correct |
12 |
Correct |
4 ms |
3408 KB |
Output is correct |
13 |
Correct |
4 ms |
3408 KB |
Output is correct |
14 |
Correct |
4 ms |
3408 KB |
Output is correct |
15 |
Correct |
4 ms |
3408 KB |
Output is correct |
16 |
Correct |
225 ms |
190820 KB |
Output is correct |
17 |
Correct |
233 ms |
188264 KB |
Output is correct |
18 |
Correct |
194 ms |
188848 KB |
Output is correct |
19 |
Correct |
191 ms |
191060 KB |
Output is correct |
20 |
Correct |
261 ms |
198968 KB |
Output is correct |
21 |
Correct |
212 ms |
184712 KB |
Output is correct |
22 |
Correct |
196 ms |
197732 KB |
Output is correct |
23 |
Correct |
230 ms |
182080 KB |
Output is correct |
24 |
Correct |
248 ms |
191920 KB |
Output is correct |
25 |
Correct |
219 ms |
180688 KB |
Output is correct |
26 |
Correct |
234 ms |
195160 KB |
Output is correct |
27 |
Correct |
221 ms |
184000 KB |
Output is correct |
28 |
Correct |
207 ms |
183520 KB |
Output is correct |
29 |
Correct |
189 ms |
195424 KB |
Output is correct |
30 |
Correct |
178 ms |
190276 KB |
Output is correct |
31 |
Runtime error |
23 ms |
9808 KB |
Execution killed with signal 11 |
32 |
Halted |
0 ms |
0 KB |
- |