Submission #1114191

# Submission time Handle Problem Language Result Execution time Memory
1114191 2024-11-18T10:12:19 Z NotLinux Sličnost (COI23_slicnost) C++17
34 / 100
3000 ms 10648 KB
// Author : FatihCihan
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(v) v.begin() , v.end()
#define sz(a) (int)a.size()
void solve(){
	int n,k,query;
	cin >> n >> k >> query;
	int p[n] , q[n] , pos[n];
	for(int i = 0;i<n;i++){
		cin >> p[i];
		p[i]--;
	}
	for(int i = 0;i<n;i++){
		cin >> q[i];
		q[i]--;
		pos[q[i]] = i;
	}
	map < int , int > mpa;
	auto calc = [&](int ind , bool typ){// ans for the segment [ind , ind + k - 1]
		// cout << "calc : " << ind << " , " << typ << endl;
		vector < int > v;
		for(int i = ind;i<=ind+k-1;i++){
			v.push_back(pos[p[i]]);
		}
		sort(all(v));
		// cout << "ind : " << ind << endl;
		// cout << "v : ";for(auto itr : v)cout << itr << " ";cout << endl;
		int rp = 0;
		for(int i = 0;i<sz(v);i++){
			while(rp < sz(v) and (v[rp] - v[i]) < k)rp++;
			int lb = max(0ll , v[rp-1] - k + 1);
			int ub = min(n - k , v[i]);
			mpa[rp - i] += (typ ? 1 : -1) * (ub - lb + 1);
			// cout << rp - i << " : " << (ub - lb + 1) << " , " << typ << endl;
		}
	};
	auto answer = [&]{
		while((*(--mpa.end())).second == 0)mpa.erase(--mpa.end());
		cout << (*(--mpa.end())).first << " " << (*(--mpa.end())).second << '\n';
	};
	for(int i = 0;i<n-k+1;i++){
		calc(i , 1);
	}
	answer();
	while(query--){
		int ti;
		cin >> ti;
		ti--;
		if((ti - k + 1) >= 0)calc(ti - k + 1 , 0);
		if((ti + 1) <= (n-k))calc(ti + 1 , 0);
		swap(p[ti] , p[ti + 1]);
		if((ti - k + 1) >= 0)calc(ti - k + 1 , 1);
		if((ti + 1) <= (n-k))calc(ti + 1 , 1);
		answer();
	}
}
signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int testcase = 1;//cin >> testcase;
	while(testcase--)solve();
	cerr << 1000.0 * clock() / CLOCKS_PER_SEC << " ms" << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 508 KB Output is correct
16 Correct 2 ms 592 KB Output is correct
17 Correct 2 ms 592 KB Output is correct
18 Correct 2 ms 848 KB Output is correct
19 Correct 447 ms 744 KB Output is correct
20 Correct 14 ms 592 KB Output is correct
21 Correct 23 ms 640 KB Output is correct
22 Correct 83 ms 848 KB Output is correct
23 Correct 12 ms 760 KB Output is correct
24 Correct 6 ms 592 KB Output is correct
25 Correct 307 ms 592 KB Output is correct
26 Correct 281 ms 592 KB Output is correct
27 Correct 62 ms 624 KB Output is correct
28 Correct 386 ms 592 KB Output is correct
29 Correct 440 ms 592 KB Output is correct
30 Correct 162 ms 972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 508 KB Output is correct
16 Correct 2 ms 592 KB Output is correct
17 Correct 2 ms 592 KB Output is correct
18 Correct 2 ms 848 KB Output is correct
19 Correct 447 ms 744 KB Output is correct
20 Correct 14 ms 592 KB Output is correct
21 Correct 23 ms 640 KB Output is correct
22 Correct 83 ms 848 KB Output is correct
23 Correct 12 ms 760 KB Output is correct
24 Correct 6 ms 592 KB Output is correct
25 Correct 307 ms 592 KB Output is correct
26 Correct 281 ms 592 KB Output is correct
27 Correct 62 ms 624 KB Output is correct
28 Correct 386 ms 592 KB Output is correct
29 Correct 440 ms 592 KB Output is correct
30 Correct 162 ms 972 KB Output is correct
31 Correct 15 ms 3828 KB Output is correct
32 Correct 17 ms 3664 KB Output is correct
33 Correct 37 ms 10648 KB Output is correct
34 Execution timed out 3054 ms 6528 KB Time limit exceeded
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 508 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 504 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 508 KB Output is correct
16 Correct 2 ms 592 KB Output is correct
17 Correct 2 ms 592 KB Output is correct
18 Correct 2 ms 848 KB Output is correct
19 Correct 447 ms 744 KB Output is correct
20 Correct 14 ms 592 KB Output is correct
21 Correct 23 ms 640 KB Output is correct
22 Correct 83 ms 848 KB Output is correct
23 Correct 12 ms 760 KB Output is correct
24 Correct 6 ms 592 KB Output is correct
25 Correct 307 ms 592 KB Output is correct
26 Correct 281 ms 592 KB Output is correct
27 Correct 62 ms 624 KB Output is correct
28 Correct 386 ms 592 KB Output is correct
29 Correct 440 ms 592 KB Output is correct
30 Correct 162 ms 972 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 1 ms 336 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
43 Correct 1 ms 336 KB Output is correct
44 Correct 1 ms 504 KB Output is correct
45 Correct 1 ms 336 KB Output is correct
46 Correct 3 ms 592 KB Output is correct
47 Correct 6 ms 592 KB Output is correct
48 Correct 4 ms 848 KB Output is correct
49 Correct 2095 ms 592 KB Output is correct
50 Correct 57 ms 640 KB Output is correct
51 Correct 826 ms 996 KB Output is correct
52 Correct 764 ms 776 KB Output is correct
53 Correct 60 ms 592 KB Output is correct
54 Correct 30 ms 760 KB Output is correct
55 Correct 1820 ms 756 KB Output is correct
56 Correct 86 ms 644 KB Output is correct
57 Correct 82 ms 760 KB Output is correct
58 Correct 1832 ms 1016 KB Output is correct
59 Correct 1165 ms 956 KB Output is correct
60 Correct 1725 ms 884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 508 KB Output is correct
16 Correct 2 ms 592 KB Output is correct
17 Correct 2 ms 592 KB Output is correct
18 Correct 2 ms 848 KB Output is correct
19 Correct 447 ms 744 KB Output is correct
20 Correct 14 ms 592 KB Output is correct
21 Correct 23 ms 640 KB Output is correct
22 Correct 83 ms 848 KB Output is correct
23 Correct 12 ms 760 KB Output is correct
24 Correct 6 ms 592 KB Output is correct
25 Correct 307 ms 592 KB Output is correct
26 Correct 281 ms 592 KB Output is correct
27 Correct 62 ms 624 KB Output is correct
28 Correct 386 ms 592 KB Output is correct
29 Correct 440 ms 592 KB Output is correct
30 Correct 162 ms 972 KB Output is correct
31 Correct 15 ms 3828 KB Output is correct
32 Correct 17 ms 3664 KB Output is correct
33 Correct 37 ms 10648 KB Output is correct
34 Execution timed out 3054 ms 6528 KB Time limit exceeded
35 Halted 0 ms 0 KB -