//Dalao厉害,第四题完全没想到用二分; //我考试时写的第三题O(n),想法可能简单点 #include <iostream> #include <vector> #include <algorithm> #include <utility> using namespace std; int main() {     int n;     cin >> n;     for (int i = 0; i < n; ++i) {         int people;         cin >> people;         vector<int> point(people, 0);         vector<long long> pres(people, 1);         vector<pair<int, int> > mark(people, make_pair(0, 0));         for (int j = 0; j < people; ++j) cin >> point[j];         if (people == 0) {             cout << 0 << endl;             continue;         }         if (people == 1) {             cout << 1 << endl;             continue;         }         if (people == 2) {             if (point[0] == point[1]) cout << 2 << endl;             else cout << 3 << endl;             continue;         }         for (int j = 0; j < people; ++j) {                 int left = j - 1 < 0 ? people - 1 : j - 1;                 int right = (j + 1) % people;                 if (point[j] > point[left]) mark[j].first = 1;                 if (point[j] > point[right]) mark[j].second = 1;         }         for (int j = 0; j < people; ++j) {             if (mark[j].first == 0 && mark[j].second == 0) {                 int left = j - 1 < 0 ? people - 1 : j - 1;                 while (mark[left].second == 1) {                     pres[left] = max(pres[left], pres[(left+1)%people] + 1);                     left = left - 1 < 0 ? people - 1 : left - 1;                 }                 int right= (j + 1) % people;                 while (mark[right].first == 1) {                     pres[right] = max(pres[right], pres[right-1<0?people-1:right-1] + 1);                     right = (right + 1) % people;                 }             }         }         long long result = 0;         for (int j = 0; j < people; ++j) result += pres[j];         cout << result << endl;     }     return 0; }
点赞 1

相关推荐

10-24 11:10
山西大学 Java
若梦难了:哥们,面试挂是很正常的。我大中厂终面挂,加起来快10次了,继续努力吧。
点赞 评论 收藏
分享
Bug压路:老哥看得出来你是想多展示一些项目,但好像一般最多两个就够了😂页数一般一页,多的也就2页;这些项目应该是比较同质化的,和评论区其他大佬一样,我也觉得应该展示一些最拿手的(质量>数量)😁😁😁专业技能部分也可以稍微精简一些
点赞 评论 收藏
分享
牛客网
牛客企业服务