求大佬帮我看一下下面的代码什么意思,蒟蒻看不懂。。。
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;
int n, m, q;
int main() {
int t;
scanf("%d", &t);
for (; t--; ) {
scanf("%d%d%d", &n, &m, &q);
vector<pair<int, int>> a;
a.push_back({m, m});
for (; q--; ) {
int x;
scanf("%d", &x);
vector<pair<int, int>> tot;
for (auto [l, r] : a) {
if (x < l)
tot.push_back({l - 1, r});
else if (x > r)
tot.push_back({l, r + 1});
else {
if (l != r)
tot.push_back({l , r});
tot.push_back({1, 1}), tot.push_back({n, n});
}
}
a.clear(); //记录新的一组的贡献
sort(tot.begin(), tot.end());
for (auto [l, r] : tot) {
if (a.empty() || (a.back().second < l)) //若最大的小于上一组, 全更新
a.push_back({l, r});
else //处理重复的情况
a.back().second = max(a.back().second, r);
}
int ans = 0;
for (auto [l, r] : a)
ans += (r - l + 1);
printf("%d ", ans);
}
putchar('\n');
}
}