#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;
cout<<sec-t[x]+1<<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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
160 ms |
3596 KB |
Output is correct |
2 |
Correct |
184 ms |
64608 KB |
Output is correct |
3 |
Correct |
215 ms |
64604 KB |
Output is correct |
4 |
Correct |
184 ms |
64652 KB |
Output is correct |
5 |
Correct |
190 ms |
64608 KB |
Output is correct |
6 |
Correct |
243 ms |
64680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
160 ms |
3596 KB |
Output is correct |
2 |
Correct |
184 ms |
64608 KB |
Output is correct |
3 |
Correct |
215 ms |
64604 KB |
Output is correct |
4 |
Correct |
184 ms |
64652 KB |
Output is correct |
5 |
Correct |
190 ms |
64608 KB |
Output is correct |
6 |
Correct |
243 ms |
64680 KB |
Output is correct |
7 |
Correct |
217 ms |
3576 KB |
Output is correct |
8 |
Correct |
1690 ms |
64436 KB |
Output is correct |
9 |
Correct |
460 ms |
64568 KB |
Output is correct |
10 |
Correct |
1609 ms |
64288 KB |
Output is correct |
11 |
Correct |
1817 ms |
64440 KB |
Output is correct |
12 |
Correct |
375 ms |
64720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
144 ms |
3536 KB |
Output is correct |
2 |
Incorrect |
167 ms |
4648 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
144 ms |
3536 KB |
Output is correct |
2 |
Incorrect |
167 ms |
4648 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
144 ms |
3604 KB |
Output is correct |
2 |
Incorrect |
176 ms |
4816 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
144 ms |
3604 KB |
Output is correct |
2 |
Incorrect |
176 ms |
4816 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
150 ms |
3508 KB |
Output is correct |
2 |
Incorrect |
190 ms |
4752 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
150 ms |
3508 KB |
Output is correct |
2 |
Incorrect |
190 ms |
4752 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
150 ms |
3468 KB |
Output is correct |
2 |
Incorrect |
202 ms |
4688 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
150 ms |
3468 KB |
Output is correct |
2 |
Incorrect |
202 ms |
4688 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
149 ms |
3548 KB |
Output is correct |
2 |
Correct |
183 ms |
64668 KB |
Output is correct |
3 |
Correct |
194 ms |
64800 KB |
Output is correct |
4 |
Correct |
193 ms |
64744 KB |
Output is correct |
5 |
Correct |
181 ms |
64596 KB |
Output is correct |
6 |
Correct |
177 ms |
64688 KB |
Output is correct |
7 |
Correct |
147 ms |
3584 KB |
Output is correct |
8 |
Incorrect |
162 ms |
4688 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
149 ms |
3548 KB |
Output is correct |
2 |
Correct |
183 ms |
64668 KB |
Output is correct |
3 |
Correct |
194 ms |
64800 KB |
Output is correct |
4 |
Correct |
193 ms |
64744 KB |
Output is correct |
5 |
Correct |
181 ms |
64596 KB |
Output is correct |
6 |
Correct |
177 ms |
64688 KB |
Output is correct |
7 |
Correct |
147 ms |
3584 KB |
Output is correct |
8 |
Incorrect |
162 ms |
4688 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |