This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define int ll
#define lc (rt<<1)
#define rc (rt<<1)
#define mid (l+r>>1)
#define rg register
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define DEBUG printf("Debug on line %d\n", __LINE__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int N = 4e3 + 5;
const int INF = 0x3f3f3f3f;
inline int read(){
int n=0, f=1; char ch = getchar();
for(; !isdigit(ch); ch=getchar()) if(ch == '-') f=-1;
for(; isdigit(ch); ch=getchar()) n=n*10+ch-'0';
return n*f;
}
int n, k;
bitset<N> a[N];
signed main(){
n = read(), k = read();
for(int i=1; i<=n; i++){
a[i] = 1<<(i-1);
}
for(int i=1; i<=n+k-1; i++){
char opt; cin >> opt;
if(opt == 'S'){
int x = read(), y = read();
bitset<N> t = a[x] | a[y];
a[x] = t, a[y] = t;
} else if(opt == 'Q'){
int x = read(), y = read();
if(a[x][y-1]) printf("yes\n");
else printf("no\n");
} else if(opt == 'C'){
int x = read();
int ans = 0;
for(int i=1; i<=n; i++){
if(a[i][x-1]) ans++;
}
printf("%lld\n", ans);
}
}
}
/*
6 9
S 1 2
S 1 3
S 3 4
Q 5 1
S 4 5
S 1 6
Q 5 1
Q 1 5
C 1
C 2
C 3
C 4
C 5
C 6
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |