当时自己犯了很蠢的错误,用Python写一直ac不了,所以搞了两个版本,后来发现都改好了,两个都能AC C++版本: #include <iostream> #include <cstdio> #include <vector> #include <algorithm> #define MAX(a,b) ((a) > (b) ? (a) : (b)) using namespace std; int main(){     int t, res_m, res_f;     cin >> t;     for(int i = 0; i < t; i++){         int n;         res_m = 0;         res_f = 0;         cin >> n;         vector<int> v;         for(int j = 0; j < n; j++){             int x; scanf("%d",&x);             vector<int>::iterator pos_left,pos_right;             pos_left = std::lower_bound(v.begin(), v.end(), x);             pos_right = std::upper_bound(pos_left, v.end(), x);             int lo = pos_left - v.begin();             int hi = pos_right - v.begin();             v.insert(v.begin()+hi, x);             res_f += lo + hi - j;             res_m = MAX(res_m, res_f);         }         cout << res_m << ' ' << res_f << endl;     }     return 0; } Python 版本: import bisect T = int(input()) class my_class(object):     __slots__ = ['array', 'res_m', 'res_f']     def __init__(self, lst):         array = []         res_m, res_f = 0, 0         n = len(lst)         for i, x in enumerate(lst):             pos_left = bisect.bisect_left(array, x)             pos_right = bisect.bisect_right(array, x, pos_left)             res_f += pos_left + pos_right - i             res_m = max(res_m, res_f)             array.insert(pos_right, x)         print(res_m, res_f) for _ in range(T):     n = int(input())     lst = list(map(int, input().split()))     my_class(lst)
点赞 2

相关推荐

白火同学:先说结论,准大三不是特别好找实习,boss沟通300+没有实习是很正常的情况。一是暑期实习时间太短了,二是在这么多准大四都找不到实习,从实习时间和掌握技术层面,企业会优先看他们。 再说简历,其实985本+准大三到这水平的简历也很优秀了,要说的话,项目经历可以再优化一下,可以基本围绕采取STAR原则,分为项目概述、技术架构、技术亮点、实现结果,再发给AI润色一下。 最后说操作,准大三的话,如果想找实习那就多投,不过现在也7月中旬了,时间上已经略晚了。如果7月底实在找不到,也可以多刷点算法,多学点技术,这实习也不至于一定得有,当然有更好。
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务