正文
增加 22 行删除 22 行
12345678910119 行未改动21222324252627282930313233348 行未改动43444546474849505124 行未改动767778798081828384858687888990919293949536 行未改动1321331341351361371381391406 行未改动14714814915015115215315415515616 行未改动17317417517617717817918018125 行未改动207208209210211212213214215216217218219220221222223224225226105 行未改动全部展开33233333433533633733833934029 行未改动37037137237337437537637737825 行未改动40440540640740840941041141211 行未改动42442542642742842943043143251 行未改动| 题目编号 | 题目名称 | 考察知识点 | 预估难度 || :----: | :----: | :----: | :----: || $\textbf A$ | 回文子串 | 二分、哈希/马拉车 | 绿 || $\textbf B$ | 消消乐 | 区间DP | 蓝 || $\textbf C1$ | 隐藏的排列(easy version) | ??? | 绿 || $\textbf C2$ | 隐藏的排列(hard version) | 随机化 | 蓝 || $\textbf D$ | 有向图 | 线段树/块状链表 | 紫 |## A.[回文子串](https://www.luogu.com.cn/problem/T750352)首先不难发现,字符串 $T$ 可以通过 $S=s_1s_2 \cdots s_{n-1}s_n$ 进行若干次操作得到的充要条件是 $\exists i \in [1,n]$ 使得 $T = s_is_{i-1} \cdots s_1s_ns_{n-1} \cdots s_{i+1}$ 或 $T = s_is_{i+1} \cdots s_{n-1}s_ns_1 \cdots s_{i-1}$。9 行未改动string s;int n , a[N];int main(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);string ss;cin >> ss;ss = ss + ss;n = ss.size();s = " #";s += ss[0];for (int i = 1;i < n;i++){s += '#';s += ss[i];}8 行未改动}}int ans = 0;for (int i = 1;i <= n;i++){--a[i];if (a[i] > n / 4){if (a[i] % 2 == (n / 4) % 2) a[i] = n / 4;else a[i] = n / 4 - 1;}24 行未改动考虑 $bitset$ 优化,定义 $f_i$ 为前面的 $f$ 组成的bitset , $g_i$ 为以 $i$ 为结尾有哪些位置可以删空,则前面的区间 $dp$ 可以优化。```#include <iostream>#include <bitset>using namespace std;const int N = 4e3 + 5;bitset <N> f[N] , g[N];int n , h[N];string s;int main(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin >> s;n = s.size();s = ' ' + s;for (int i = 2;i <= n;i++) f[i][i - 1] = g[i - 1][i] = 1;for (int k = 2;k <= n;k++){for (int i = 1;i + k - 1 <= n;i++){int j = i + k - 1;f[i][j] = g[j][i] = ((f[i] << 1) & g[j]).any();36 行未改动#include <random>using namespace std;const int N = 5e5 + 5;int n , a[N];vector <int> b[N];mt19937 rnd((unsigned long long)(new char));int ask(int x , int y){cout << "? " << x << ' ' << y << '\n';cout.flush();6 行未改动n = 500000;int maxn = 0 , id = 0 , x , y;do{x = rnd() % n + 1;}while (ask(x , rnd() % n + 1) < n - 6000);for (int i = 1;i <= n;i++){b[ask(x , i)].push_back(i);}for (int i = 1;i <= n;i++){16 行未改动}cout << "! ";for (int i = 1;i <= n;i++) cout << a[i] << ' ';cout << '\n';cout.flush();return 0;}```25 行未改动const int maxn=1e6+5;int n,B,ans;int a[maxn],b[maxn];int blockhead,blocktail,tot,cnt;//hd:第一个块的编号,tot:块的编号,cnt:点的编号struct ys{int a,b,pre,nxt;}g[maxn];struct node{int nxt,pre,maxa,maxb,hd,tl,siz;}bl[maxn];//块inline int get(int a,int b){int pos=1;for(int i=blockhead;i;i=bl[i].nxt){if(bl[i].maxa<=a && bl[i].maxb<=b)//pos+=bl[i].siz;else{for(int j=bl[i].hd,c=0;j;j=g[j].nxt,c++)105 行未改动全部展开}signed main(){ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);cin>>n,B=sqrt(n);for(int i=1;i<=n;i++)cin>>a[i];for(int i=1;i<=n;i++)29 行未改动void pushdown(int x){if (t[x].lazya){t[x << 1].vala = t[x << 1 | 1].vala = 0;t[x << 1].lazya = t[x << 1 | 1].lazya = 1;}if (t[x].lazyb){t[x << 1].valb = t[x << 1 | 1].valb = 0;t[x << 1].lazyb = t[x << 1 | 1].lazyb = 1;}25 行未改动int mid = l + r >> 1 , ret = 0;pushdown(x);if (a <= mid) ret += query(x << 1 , a , b , flag);if (mid < b) ret += query(x << 1 | 1 , a , b , flag);return ret;}void updatea(int x , int a , int b){int l = t[x].l , r = t[x].r;if (a == 1 && b == t[x].vala){11 行未改动else{updatea(x << 1 , a , tmp);updatea(x << 1 | 1 , 1 , b - tmp);}pushup(x);}void updateb(int x , int a , int b){int l = t[x].l , r = t[x].r;if (a == 1 && b == t[x].valb){51 行未改动12345678910119 行未改动21222324252627282930313233348 行未改动43444546474849505124 行未改动767778798081828384858687888990919293949536 行未改动1321331341351361371381391406 行未改动14714814915015115215315415515616 行未改动17317417517617717817918018125 行未改动207208209210211212213214215216217218219220221222223224225226105 行未改动全部展开33233333433533633733833934029 行未改动37037137237337437537637737825 行未改动40440540640740840941041141211 行未改动42442542642742842943043143251 行未改动| 题目编号 | 题目名称 | 考察知识点 | 预估难度 || :----: | :----: | :----: | :----: || $\textbf A$ | 回文子串 | 二分、哈希/马拉车 | 绿 || $\textbf B$ | 消消乐 | 区间DP | 蓝 || $\textbf C1$ | 隐藏的排列(easy version) | ??? | 绿 || $\textbf C2$ | 隐藏的排列(hard version) | 随机化 | 蓝 || $\textbf D$ | 有向图 | 线段树/块状链表 | 紫 |## A.[回文子串](https://www.luogu.com.cn/problem/T750352)首先不难发现,字符串 $T$ 可以通过 $S=s_1s_2 \cdots s_{n-1}s_n$ 进行若干次操作得到的充要条件是 $\exists i \in [1,n]$ 使得 $T = s_is_{i-1} \cdots s_1s_ns_{n-1} \cdots s_{i+1}$ 或 $T = s_is_{i+1} \cdots s_{n-1}s_ns_1 \cdots s_{i-1}$。9 行未改动string s;int n , a[N];int main(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);string ss;cin >> ss;ss = ss + ss;n = ss.size();s = " #";s += ss[0];for (int i = 1;i < n;i++){s += '#';s += ss[i];}8 行未改动}}int ans = 0;for (int i = 1;i <= n;i++){--a[i];if (a[i] > n / 4){if (a[i] % 2 == (n / 4) % 2) a[i] = n / 4;else a[i] = n / 4 - 1;}24 行未改动考虑 $bitset$ 优化,定义 $f_i$ 为前面的 $f$ 组成的bitset , $g_i$ 为以 $i$ 为结尾有哪些位置可以删空,则前面的区间 $dp$ 可以优化。```#include <iostream>#include <bitset>using namespace std;const int N = 4e3 + 5;bitset <N> f[N] , g[N];int n , h[N];string s;int main(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin >> s;n = s.size();s = ' ' + s;for (int i = 2;i <= n;i++) f[i][i - 1] = g[i - 1][i] = 1;for (int k = 2;k <= n;k++){for (int i = 1;i + k - 1 <= n;i++){int j = i + k - 1;f[i][j] = g[j][i] = ((f[i] << 1) & g[j]).any();36 行未改动#include <random>using namespace std;const int N = 5e5 + 5;int n , a[N];vector <int> b[N];mt19937 rnd((unsigned long long)(new char));int ask(int x , int y){cout << "? " << x << ' ' << y << '\n';cout.flush();6 行未改动n = 500000;int maxn = 0 , id = 0 , x , y;do{x = rnd() % n + 1;}while (ask(x , rnd() % n + 1) < n - 6000);for (int i = 1;i <= n;i++){b[ask(x , i)].push_back(i);}for (int i = 1;i <= n;i++){16 行未改动}cout << "! ";for (int i = 1;i <= n;i++) cout << a[i] << ' ';cout << '\n';cout.flush();return 0;}```25 行未改动const int maxn=1e6+5;int n,B,ans;int a[maxn],b[maxn];int blockhead,blocktail,tot,cnt;//hd:第一个块的编号,tot:块的编号,cnt:点的编号struct ys{int a,b,pre,nxt;}g[maxn];struct node{int nxt,pre,maxa,maxb,hd,tl,siz;}bl[maxn];//块inline int get(int a,int b){int pos=1;for(int i=blockhead;i;i=bl[i].nxt){if(bl[i].maxa<=a && bl[i].maxb<=b)//pos+=bl[i].siz;else{for(int j=bl[i].hd,c=0;j;j=g[j].nxt,c++)105 行未改动全部展开}signed main(){ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);cin>>n,B=sqrt(n);for(int i=1;i<=n;i++)cin>>a[i];for(int i=1;i<=n;i++)29 行未改动void pushdown(int x){if (t[x].lazya){t[x << 1].vala = t[x << 1 | 1].vala = 0;t[x << 1].lazya = t[x << 1 | 1].lazya = 1;}if (t[x].lazyb){t[x << 1].valb = t[x << 1 | 1].valb = 0;t[x << 1].lazyb = t[x << 1 | 1].lazyb = 1;}25 行未改动int mid = l + r >> 1 , ret = 0;pushdown(x);if (a <= mid) ret += query(x << 1 , a , b , flag);if (mid < b) ret += query(x << 1 | 1 , a , b , flag);return ret;}void updatea(int x , int a , int b){int l = t[x].l , r = t[x].r;if (a == 1 && b == t[x].vala){11 行未改动else{updatea(x << 1 , a , tmp);updatea(x << 1 | 1 , 1 , b - tmp);}pushup(x);}void updateb(int x , int a , int b){int l = t[x].l , r = t[x].r;if (a == 1 && b == t[x].valb){51 行未改动