using namespace std;
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <utility>
#include <memory.h>
#include <map>
#include <set>
typedef long long LL;
typedef pair<int,int> pii;
#define F first
#define S second
#define pb push_back
#define mkp make_pair
#define iter(x) x.begin(),x.end()
const int maxn = 12e4 + 100;
int n,k;
set <int> st[maxn];
int cnt[maxn];
void brutesolve(){
for (int i=1;i<=n;++i) {st[i].insert(i); cnt[i] = 1;}
for (int _=n+k-1;_--;){
char o;
cin >> o;
if (o == 'S'){
int u,v;
cin >> u >> v;
set <int> ele;
for (auto i:st[u]) {ele.insert(i); ++cnt[i];}
for (auto i:st[v]) {ele.insert(i); ++cnt[i];}
st[u] = ele; st[v] = ele;
}
else if (o == 'Q'){
int a,b;
cin >> a >> b;
cout << (st[a].find(b) != st[a].end() ? "yes\n" : "no\n");
}
else{
int c;
cin >> c;
cout << cnt[c] << '\n';
}
}
}
int bit[maxn];
pii ans[maxn];
int query(int k){
int ret = 0;
for (;k;k-=k&-k) ret += bit[k];
return ret;
}
void update(int k,int val){
for (;k<=n;k+=k&-k) bit[k] += val;
}
void solve(){
bit[1] = 1;
for (int i=1;i<=n;++i) ans[i] = mkp(i,i);
for (int _=n+k-1;_--;){
char o;
cin >> o;
if (o == 'S'){
int u,v;
cin >> u >> v;
if (u > v) swap(u,v);
ans[u] = ans[v] = mkp(ans[u].F,ans[v].S);
update(ans[u].F,1);
update(ans[v].S + 2,-1);
//cout << ans[u].F << ' ' << ans[v].S << '\n';
}
else if (o == 'Q'){
int a,b;
cin >> a >> b;
cout << (b >= ans[a].F and b <= ans[a].S ? "yes\n" : "no\n");
}
else{
int c;
cin >> c;
cout << query(c) << '\n';
}
}
//for (int i=1;i<=n;++i) cout << ans[i].F << ' ' << ans[i].S << '\n';
//for (int i=1;i<=n;++i) cout << query(i) << ' ';
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> k;
//if (n <= 4000) brutesolve(); else
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
27 ms |
6220 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
27 ms |
6220 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
28 ms |
6340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
28 ms |
6340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
6256 KB |
Output is correct |
2 |
Correct |
74 ms |
7748 KB |
Output is correct |
3 |
Correct |
72 ms |
7740 KB |
Output is correct |
4 |
Correct |
71 ms |
7724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
6256 KB |
Output is correct |
2 |
Correct |
74 ms |
7748 KB |
Output is correct |
3 |
Correct |
72 ms |
7740 KB |
Output is correct |
4 |
Correct |
71 ms |
7724 KB |
Output is correct |
5 |
Incorrect |
28 ms |
6212 KB |
Extra information in the output file |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
28 ms |
6324 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
28 ms |
6324 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
6228 KB |
Output is correct |
2 |
Correct |
75 ms |
7728 KB |
Output is correct |
3 |
Correct |
74 ms |
7748 KB |
Output is correct |
4 |
Correct |
69 ms |
7668 KB |
Output is correct |
5 |
Incorrect |
27 ms |
6296 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
6228 KB |
Output is correct |
2 |
Correct |
75 ms |
7728 KB |
Output is correct |
3 |
Correct |
74 ms |
7748 KB |
Output is correct |
4 |
Correct |
69 ms |
7668 KB |
Output is correct |
5 |
Incorrect |
27 ms |
6296 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
28 ms |
6336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
28 ms |
6336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |