#include <bits/stdc++.h>
using namespace std;
int n,k;
int in[4001][4001];
void slow()
{
for(int i=1;i<=n;i++)
in[i][i]=1;
for(int i=1;i<=n+k-1;i++)
{
char c;
cin>>c;
int x,y;
if(c=='S')
{
cin>>x>>y;
for(int j=1;j<=n;j++)
{
in[x][j]=in[y][j]=max(in[x][j],in[y][j]);
}
}
if(c=='C')
{
cin>>x;
int cnt=0;
for(int j=1;j<=n;j++)
cnt+=in[j][x];
cout<<cnt<<endl;
}
if(c=='Q')
{
cin>>x>>y;
if(in[x][y])cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
}
}
int t[120001];
void subt2()
{
t[1]=1;
int sec=1;
for(int i=1;i<=n+k-1;i++)
{
char c;
cin>>c;
if(c=='S')
{
int x,y;
cin>>x>>y;
t[max(x,y)]=sec++;
}
if(c=='Q')
{
int x,y;
cin>>x>>y;
if(t[y]&&t[y]<t[x])cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
if(c=='C')
{
int x;
cin>>x;
if(t[x]==0)cout<<1<<endl;
else cout<<sec-t[x]<<endl;
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>k;
if(n<=4000)slow();
else subt2();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
153 ms |
2752 KB |
Output is correct |
2 |
Correct |
183 ms |
63592 KB |
Output is correct |
3 |
Correct |
222 ms |
63744 KB |
Output is correct |
4 |
Correct |
200 ms |
63560 KB |
Output is correct |
5 |
Correct |
177 ms |
63572 KB |
Output is correct |
6 |
Correct |
179 ms |
63712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
153 ms |
2752 KB |
Output is correct |
2 |
Correct |
183 ms |
63592 KB |
Output is correct |
3 |
Correct |
222 ms |
63744 KB |
Output is correct |
4 |
Correct |
200 ms |
63560 KB |
Output is correct |
5 |
Correct |
177 ms |
63572 KB |
Output is correct |
6 |
Correct |
179 ms |
63712 KB |
Output is correct |
7 |
Correct |
143 ms |
2892 KB |
Output is correct |
8 |
Correct |
1641 ms |
63620 KB |
Output is correct |
9 |
Correct |
539 ms |
63580 KB |
Output is correct |
10 |
Correct |
1724 ms |
63552 KB |
Output is correct |
11 |
Correct |
1602 ms |
63920 KB |
Output is correct |
12 |
Correct |
354 ms |
63740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
142 ms |
2644 KB |
Output is correct |
2 |
Incorrect |
162 ms |
3076 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
142 ms |
2644 KB |
Output is correct |
2 |
Incorrect |
162 ms |
3076 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
176 ms |
2756 KB |
Output is correct |
2 |
Incorrect |
175 ms |
3036 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
176 ms |
2756 KB |
Output is correct |
2 |
Incorrect |
175 ms |
3036 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
152 ms |
2796 KB |
Output is correct |
2 |
Incorrect |
207 ms |
3092 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
152 ms |
2796 KB |
Output is correct |
2 |
Incorrect |
207 ms |
3092 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
144 ms |
2808 KB |
Output is correct |
2 |
Incorrect |
170 ms |
3048 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
144 ms |
2808 KB |
Output is correct |
2 |
Incorrect |
170 ms |
3048 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
151 ms |
2780 KB |
Output is correct |
2 |
Correct |
194 ms |
63656 KB |
Output is correct |
3 |
Correct |
173 ms |
63716 KB |
Output is correct |
4 |
Correct |
192 ms |
63660 KB |
Output is correct |
5 |
Correct |
177 ms |
63568 KB |
Output is correct |
6 |
Correct |
176 ms |
63708 KB |
Output is correct |
7 |
Correct |
143 ms |
2640 KB |
Output is correct |
8 |
Incorrect |
173 ms |
2964 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
151 ms |
2780 KB |
Output is correct |
2 |
Correct |
194 ms |
63656 KB |
Output is correct |
3 |
Correct |
173 ms |
63716 KB |
Output is correct |
4 |
Correct |
192 ms |
63660 KB |
Output is correct |
5 |
Correct |
177 ms |
63568 KB |
Output is correct |
6 |
Correct |
176 ms |
63708 KB |
Output is correct |
7 |
Correct |
143 ms |
2640 KB |
Output is correct |
8 |
Incorrect |
173 ms |
2964 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |