提交时间:2021-12-06 13:58:23

运行 ID: 33479

#include<bits/stdc++.h> using namespace std; list <pair<int,int> > s;//list,vector,set基本一样时间复杂度 int main() { int n,tpy; scanf("%d", &n); for(int i = 1; i <= n; i++) { scanf("%d", &tpy); s.push_back(make_pair(i,tpy) ); } while(s.size()) { int former = -1; //标记上一次输出的值的下标 for(list <pair<int,int> >::iterator ii=s.begin(); ii!=s.end();) { if((*ii).second != former) { former = (*ii).second; printf("%d ", (*ii).first); ii=s.erase(ii); //直接删除会丢失迭代器 } else ii++; } printf("\n"); } return 0; }