在正常提交运行时出现的错误...
在自测中使用测测试样例同样的数据...
结果正确....
求解释
#include<iostream> #include<vector> #include<map> using namespace std; int getMaxScore(map<int,int> scores,int first, int end) { if(first == end) return scores[first-1]; if( first > end) { int tmp = first; first = end; end = tmp; } int maxTmp = 0; for(int idx = first - 1; idx < end ; idx++) { if(maxTmp < scores[idx]) maxTmp = scores[idx]; } return maxTmp; } void update(map<int,int>& scores,int stuA, int score) { int tmp = 0; // int tmp = scores[stuA]; scores[stuA-1] = score; // scores[stuB-1] = tmp; //return tmp; } vector<int> query(map<int,int> scores,vector<vector<int>> querys) { vector<int> vecRet; for(int idx = 0; idx < querys.size(); idx++) { switch (querys[idx][0]) { case 0: vecRet.push_back(getMaxScore(scores,querys[idx][1],querys[idx][2])); break; case 1: update(scores,querys[idx][1],querys[idx][2]); break; default: break; } } return vecRet; } int main() { int studentsNums = 0, opNums = 0, input = 0; char cType; map<int,int> mapScores; vector<int> vecTmp; vector<vector<int>> vecQuery; while(cin >> studentsNums >> opNums) { for(int idx = 0; idx < studentsNums ; idx ++) { cin >> input; mapScores.insert(pair<int,int>(idx,input)); } for(int idx = 0; idx < opNums ; idx ++) { cin >> cType; vecTmp.clear(); switch (cType) { case 'Q': { vecTmp.push_back(0); break; } case 'U': { vecTmp.push_back(1); break; } default: break; } cin >> input; vecTmp.push_back(input); cin >> input; vecTmp.push_back(input); vecQuery.push_back(vecTmp); } break; } //cout<< studentsNums<< " " << opNums<< " "<< vecQuery.size() << endl; vector<int> queryResults = query(mapScores,vecQuery); //cout<<vecQuery.size()<<endl;; for(auto result : queryResults) cout << result <<endl; }
全部评论
(0) 回帖