#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(0); cin.tie(NULL);cout.tie(NULL)
#define sz(x) (int)((x).size())
#define pb push_back
#define vi vector<int>
#define vb vector<bool>
#define vvb vector<vb>
#define pi pair<int,int>
#define vpi vector<pi>
#define vvi vector<vi>
#define vc vector<char>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pbb() pop_back()
#define f first
#define s second
#define ll long long
#define int long long
#define ull unsigned long long
#define forr(i, a, b) for(int i=a; i<b; i++)
const int N=120000+1, mod=1e9 + 9, inf=1e27+1;
using namespace std;
//vi dx= { 0, 1, 0 , -1} , dy= {-1,0, 1, 0};
void task()
{
int n, k;
cin>>n>>k;
vi pos(n+1, inf);
char ch;
int a, b, added=0;
forr(i, 0, n+k-1)
{
cin>>ch;
if(ch=='S')
{
cin>>a>>b;
if(a>b) swap(a,b);
added++;
if(added==1) pos[a]=added;
pos[b]=added;
}
else if(ch=='Q')
{
cin>>a>>b;
bool ok=false;
//cout<<pos[a]<<" "<<pos[b]<<endl;
if(a==b) ok=true;
if(a==1 and pos[b]!=inf) ok=true;
else if(pos[a]!=inf and pos[b]!=inf and pos[b]<=pos[a]) ok=true;
if(ok) cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
else
{
cin>>a;
if(pos[a]==inf) cout<<1<<endl;
else if(a==1) cout<<added+1<<endl;
else cout<<added-pos[a]+2<<endl;
}
}
}
signed main()
{
fast;
int t;
t=1;
//cin>>t;
while(t--) task();
}
Compilation message
servers.cpp:21:44: warning: overflow in conversion from 'double' to 'long long int' changes value from '1.0e+27' to '9223372036854775807' [-Woverflow]
21 | const int N=120000+1, mod=1e9 + 9, inf=1e27+1;
| ~~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
149 ms |
588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
149 ms |
588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
153 ms |
612 KB |
Output is correct |
2 |
Correct |
184 ms |
1632 KB |
Output is correct |
3 |
Correct |
186 ms |
1600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
153 ms |
612 KB |
Output is correct |
2 |
Correct |
184 ms |
1632 KB |
Output is correct |
3 |
Correct |
186 ms |
1600 KB |
Output is correct |
4 |
Correct |
150 ms |
760 KB |
Output is correct |
5 |
Correct |
181 ms |
4480 KB |
Output is correct |
6 |
Correct |
177 ms |
3692 KB |
Output is correct |
7 |
Correct |
171 ms |
3748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
153 ms |
640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
153 ms |
640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
155 ms |
716 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
155 ms |
716 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
157 ms |
628 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
157 ms |
628 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
181 ms |
620 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
181 ms |
620 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |