#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for (int i=0; i<n; ++i)
bitset<120000> a[120002];
void solve() {
int n,q; cin>>n>>q;
forn(i,n) a[i].set(i);
vector<string> a(n);
vector<int> last(n);
forn(i,n) last[i]=i;
forn(i,n) a[i]+=i;
forn(Q,n-1+q) {
char c;
cin>>c;
if (c=='S') {
int u,v; cin>>u>>v; --u,--v;
if (u!=last[u]) a[u]=a[last[u]];
if (v!=last[v]) a[v]=a[last[v]];
if (a[u].size()<a[v].size()) swap(u,v);
for (auto x:a[v]) a[u]+=x;
a[v]=a[u];
//last[u]=last[v]=u;
//for (auto x:a[u]) cout<<x<<' '; cout<<" ";
//for (auto x:a[v]) cout<<x<<' '; cout<<'\n';
} else if (c=='Q') {
int u,x; cin>>u>>x; --u, --x;
u=last[u];
cout << ((a[u].find(x)<n)?"yes\n":"no\n");
} else {
int x; cin>>x; --x;
cout<<0<<'\n';
}
}
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
solve();
return 0;
}
Compilation message
servers.cpp: In function 'void solve()':
servers.cpp:36:26: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
36 | cout << ((a[u].find(x)<n)?"yes\n":"no\n");
| ~~~~~~~~~~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
892 KB |
Output is correct |
2 |
Incorrect |
32 ms |
16956 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
892 KB |
Output is correct |
2 |
Incorrect |
32 ms |
16956 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
840 KB |
Output is correct |
2 |
Runtime error |
186 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
840 KB |
Output is correct |
2 |
Runtime error |
186 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
852 KB |
Output is correct |
2 |
Incorrect |
223 ms |
488436 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
852 KB |
Output is correct |
2 |
Incorrect |
223 ms |
488436 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
864 KB |
Output is correct |
2 |
Runtime error |
231 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
864 KB |
Output is correct |
2 |
Runtime error |
231 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
852 KB |
Output is correct |
2 |
Incorrect |
228 ms |
488480 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
852 KB |
Output is correct |
2 |
Incorrect |
228 ms |
488480 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
900 KB |
Output is correct |
2 |
Incorrect |
30 ms |
16852 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
900 KB |
Output is correct |
2 |
Incorrect |
30 ms |
16852 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |