Submission #242473

#TimeUsernameProblemLanguageResultExecution timeMemory
242473MatesV13Tenis (COI19_tenis)C++11
30 / 100
1072 ms6920 KiB
#include <bits/stdc++.h>
using namespace std;
int n, q, ter[3][100005], rev[3][100005], v[100005], pa, pb, pc;
void provjeri (int idx){
	if (v[idx]) return; v[idx]=1;
	while (pa>rev[0][idx]){pa--; provjeri(ter[0][pa]);}
	while (pb>rev[1][idx]){pb--; provjeri(ter[1][pb]);}
	while (pc>rev[2][idx]){pc--; provjeri(ter[2][pc]);}
	return; 
}
int main (){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> q;
for (int i=0; i<3; i++){
	for (int j=0; j<n; j++){
		cin >> ter[i][j];
		rev[i][ter[i][j]]=j;
	}
}
while (q--){
	int tip; cin >> tip;
	if (tip==1){
		int x; cin >> x; pa=pb=pc=n;
		for (int i=1; i<=n; i++) v[i]=0;
		provjeri(x); bool ok=1;
		for (int i=1; i<=n; i++){
			ok = ok and v[i];
				} 
		if (ok) cout << "DA\n";
		else cout << "NE\n";
	}
	else {
		int p, a, b, posa, posb;
		cin >> p >> a >> b;
		for (int i=0; i<n; i++)
			if (ter[p-1][i]==a){
				posa=i; break;
			}
		for (int i=0; i<n; i++)
			if (ter[p-1][i]==b){
				posb=i; break;
			}
		swap(rev[p-1][a], rev[p-1][b]);
		swap(ter[p-1][posa], ter[p-1][posb]);
	}
}
return 0;
}

Compilation message (stderr)

tenis.cpp: In function 'void provjeri(int)':
tenis.cpp:5:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  if (v[idx]) return; v[idx]=1;
  ^~
tenis.cpp:5:22: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  if (v[idx]) return; v[idx]=1;
                      ^
tenis.cpp: In function 'int main()':
tenis.cpp:34:22: warning: 'posb' may be used uninitialized in this function [-Wmaybe-uninitialized]
   int p, a, b, posa, posb;
                      ^~~~
tenis.cpp:34:16: warning: 'posa' may be used uninitialized in this function [-Wmaybe-uninitialized]
   int p, a, b, posa, posb;
                ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...