放个正确代码吧!坑主要在注释那里 #include <iostream> (30316)#include <vector> #include <unordered_map> using namespace std; int main() { int n; cin >> n; vector<int> veca(n); unordered_map<int, int> mpa; for (int i = 0; i < n; i++) { cin >> veca[i]; mpa[veca[i]] = i; } vector<int> vecb(n); unordered_map<int, int> mpb; for (int i = 0; i < n; i++) { cin >> vecb[i]; mpb[vecb[i]] = i; } // 右值对象如果没有加LL强转,相当于还是int,一样会越界 = = long long maxNum = n * (n + 1LL); for (int i = 0; i < n; i++) { int posa = mpa[veca[i]]; int posb = mpb[veca[i]]; int numSame = 0; while (posa < n && posb < n && veca[posa] == vecb[posb]) { numSame++; posa++; posb++; } maxNum -= numSame; } cout << maxNum; }

相关推荐

11-07 16:07
深圳大学 运营
前端飞升:学长,阿里不是卡双非吗,我深也能去吗
点赞 评论 收藏
分享
12-02 20:08
已编辑
门头沟学院 后端工程师
notbeentak...:孩子,说实话,选择很重要,可能你换一个方向会好很多,但是现在时间不太够了,除非准备春招
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务