#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()
{
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[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 |
201 ms |
2896 KB |
Output is correct |
2 |
Correct |
199 ms |
63568 KB |
Output is correct |
3 |
Correct |
173 ms |
63592 KB |
Output is correct |
4 |
Correct |
191 ms |
63540 KB |
Output is correct |
5 |
Correct |
219 ms |
63500 KB |
Output is correct |
6 |
Correct |
194 ms |
63568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
201 ms |
2896 KB |
Output is correct |
2 |
Correct |
199 ms |
63568 KB |
Output is correct |
3 |
Correct |
173 ms |
63592 KB |
Output is correct |
4 |
Correct |
191 ms |
63540 KB |
Output is correct |
5 |
Correct |
219 ms |
63500 KB |
Output is correct |
6 |
Correct |
194 ms |
63568 KB |
Output is correct |
7 |
Correct |
146 ms |
2644 KB |
Output is correct |
8 |
Correct |
1556 ms |
63480 KB |
Output is correct |
9 |
Correct |
399 ms |
63836 KB |
Output is correct |
10 |
Correct |
1646 ms |
63660 KB |
Output is correct |
11 |
Correct |
1676 ms |
63696 KB |
Output is correct |
12 |
Correct |
448 ms |
63848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
157 ms |
2784 KB |
Output is correct |
2 |
Incorrect |
169 ms |
5836 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
157 ms |
2784 KB |
Output is correct |
2 |
Incorrect |
169 ms |
5836 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
179 ms |
3096 KB |
Output is correct |
2 |
Incorrect |
164 ms |
6380 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
179 ms |
3096 KB |
Output is correct |
2 |
Incorrect |
164 ms |
6380 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
170 ms |
2820 KB |
Output is correct |
2 |
Incorrect |
184 ms |
6224 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
170 ms |
2820 KB |
Output is correct |
2 |
Incorrect |
184 ms |
6224 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
186 ms |
3052 KB |
Output is correct |
2 |
Incorrect |
209 ms |
6292 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
186 ms |
3052 KB |
Output is correct |
2 |
Incorrect |
209 ms |
6292 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
148 ms |
2804 KB |
Output is correct |
2 |
Correct |
213 ms |
63704 KB |
Output is correct |
3 |
Correct |
178 ms |
63572 KB |
Output is correct |
4 |
Correct |
184 ms |
63732 KB |
Output is correct |
5 |
Correct |
185 ms |
63732 KB |
Output is correct |
6 |
Correct |
177 ms |
63564 KB |
Output is correct |
7 |
Correct |
141 ms |
2648 KB |
Output is correct |
8 |
Incorrect |
175 ms |
5916 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
148 ms |
2804 KB |
Output is correct |
2 |
Correct |
213 ms |
63704 KB |
Output is correct |
3 |
Correct |
178 ms |
63572 KB |
Output is correct |
4 |
Correct |
184 ms |
63732 KB |
Output is correct |
5 |
Correct |
185 ms |
63732 KB |
Output is correct |
6 |
Correct |
177 ms |
63564 KB |
Output is correct |
7 |
Correct |
141 ms |
2648 KB |
Output is correct |
8 |
Incorrect |
175 ms |
5916 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |