#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int rd(){
int x=0,w=1;
char ch=getchar();
for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') w=-1;
for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
return x*w;
}
int maxn=5000;
vector<vector<int>> st(maxn,vector<int>(maxn));
void solve(){
int n,q; cin>>n>>q;
//since it forms a star, meaning that the number v appears in all nodes
//if the edge is used after t[v] happens
//we can do prefix sum to do
vector<int> ti,t(n+5);
for(int i=1;i<=n;i++){
t[i]=-1;
}
for(int i=0;i<n+q-1;i++){
char type; cin>>type;
if(type=='Q'){
int u,v; cin>>u>>v;
if(u==v) cout<<"yes\n";
else if(t[v]==-1 || t[u]==-1) cout<<"no\n";
else{
if(u==1 || t[u]>t[v]) cout<<"yes\n";
else cout<<"no\n";
}
}
else if(type=='S'){
int u,v; cin>>u>>v;
if(u>v) swap(u,v);
t[v]=i;
ti.push_back(i);
}
else{
int v; cin>>v;
if(t[v]==-1) cout<<"1\n";
else{
int ans=2;
auto pos=upper_bound(ti.begin(),ti.end(),t[v]);
int nxt=n-(pos-ti.begin());
ans+=nxt;
cout<<ans<<'\n';
}
}
}
}
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int tt=1; //cin>>tt;
while(tt--){
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
97 ms |
196812 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
97 ms |
196812 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
97 ms |
196836 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
97 ms |
196836 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
108 ms |
196540 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
108 ms |
196540 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
101 ms |
196492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
101 ms |
196492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
98 ms |
196580 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
98 ms |
196580 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
120 ms |
196504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
120 ms |
196504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |