信奥初赛题2

· · 个人记录

选择题

  1. 下面哪几个是质数()A.(61)_{16}    B.(11,1110,0101)_2     C.(9997)_{10}    D.(2314627)_8
  2. 下面的伪代码实现了什么功能()A.冒泡排序 B.选择排序 C.希尔排序 D.基数排序\mathbf{for}\ i\leftarrow 1\ \mathbf{to}\ n-1 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ith\leftarrow i \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \mathbf{for}\ j\leftarrow 1\ \mathbf{to}\ n \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \mathbf{if} A_j<A_{ith} \ \ \ \ \ \ \ \ ith\leftarrow j \ \ \ \ \ \ \ \ \ \ \ \ \ swap\ A_i\ and\ A_{ith}\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \

    \

  3. 下面说法正确的是哪几项()A.快速排序比桶排序要快 B.费马小定理可以用欧拉定理推导出来 C.C++ 是面向对象的编程语言 D.CSP-J 是CCF举办的编程能力认证。

    程序填空

  • ” M\ \ i\ \ j “ 表示把第 i 个点所在的列到第 j 个点所在的列的后面。

  • “ C\ \ i\ \ j ” 表示询问 i 和 j 之间有几个点,如果 i 和 j 不在同一行回答 -1。

数据范围:

1\le T \le 5 \times 10^5

1\le i,j \le 3 \times 10^4

01 #include<bits/stdc++.h>
02 #define endl '\n'
03 #define int long long
04 using namespace std;
05 const int N=3e4+1;
06 ① list{
07 public:
08     int son[N],left[N],sum[N];
09 private:
10     int game_over(int);
11     int pop(int);
12     void died(int);
13     void ③(int,int);
14     bool dance(②);
15 };
16 int list::game_over(int x){
17     if(x==son[x])return x;
18     int root=game_over(son[x]);
19     left[x]+=left[son[x]];
20     return son[x]=root;
21 }
22 int list::pop(int x){
23     return left[x];
24 }
25 void list::died(int n){
26     for(int i=1;i<=n;i++)
27         son[i]=i,left[i]=0,sum[i]=1;
28 }
29 void list::③(int x,int y){
30     int sonx=game_over(x),sony=game_over(y);
31     left[sonx]+=sum[sony];
32     son[sonx]=④;
33     sum[sony]=⑤;
34     sum[sonx]=0; 
35 }
36 bool list::dance(int x,int y){
37     return game_over(x)==game_over(y);
38 }
39 int n,;
40 list f;
41 signed main() {
42     ios::sync_with_stdio(false);    cin.tie(nullptr);
43     cin>>n;
44     f.died(⑥);
45     for(int i=1; i<=n; i++) {
46         char ch;    int x,y;
47         cin>>ch>>x>>y;
48         if(ch=='M') f.sleep(x,y);
49         else if(⑦)
50                 cout<<abs(f.pop(x)-f.pop(y))-1<<endl;
51         else cout<<-1<<endl;
52     }
53     return 0;
54 }

填空题