牛客小白月赛113 C题题解
连续数组
https://ac.nowcoder.com/acm/contest/105825/C
#include <bits/stdc++.h> using namespace std;
int main() { int q; cin >> q;
unordered_map<long long, int> hash;
long long min1 = 1000000000LL + 1, maxVal = 0;
while (q--) {
int k;
cin >> k;
int arr[k];
for (int i = 0; i < k; i++) {
cin >> arr[i];
if (i > 0 && arr[i] <= arr[i - 1]) {
cout << "NO" << endl;
return 0;
}
hash[arr[i]]++;
if (hash[arr[i]] > 1) {
cout << "NO" << endl;
return 0;
}
if (arr[i] < min1) min1 = arr[i];
if (arr[i] > maxVal) maxVal = arr[i];
}
}
for (long long i = min1; i <= maxVal; i++) {
if (hash[i] != 1) {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
return 0;
}
这道题就是直接找到最小值和最大值,判断这个区间每个数字出现有且仅有一次,个人认为hash function的对应可以做