帮 MnZn 分析时间复杂度 or 优化部分分做法。
下面的这段代码期望得分 70 pts。现在求以下问题(如果可以分析的话):
const int N = 2 * 1e5 + 5, inf = 2;
int n, a[N];
bool flag[N];
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
memset(flag, false, sizeof(flag));
cin >> n;
for (int i = 1; i <= n; i ++) cin >> a[i];
while (true) {
int fruit = inf;
bool check = true;
for (int i = 1; i <= n; i ++) {
if (!flag[i]) {
check = false;
break;
}
}
if (check) break;
for (int i = 1; i <= n; i ++) {
if (a[i] != fruit && !flag[i]) {
fruit = a[i];
cout << i << ' ';
flag[i] = true;
}
}
cout << '\n';
}
return 0;
}
mxqz。