和Daidly的题解的代码基本一样,就是过不了样例#2
尝试多种自救(调试,询问)都无果,求$\text{dalao}$
支援一下
#include <bits/stdc++.h>
using namespace std;
int n, p, I[500005], J[500005], ans;
bool book[10][300005];
stack <int> s[10];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> p;
for (int i = 1; i <= n; i++) cin >> I[i] >> J[i];
for (int i = 1; i <= n; i++)
for (int i = 1; i <= n; i++) {
while (!s[I[i]].empty() && J[i] < s[I[i]].top()) {
s[I[i]].pop();
ans++;
}
if (!book[I[i]][J[i]]) {
s[I[i]].push(J[i]);
ans++;
}
book[I[i]][J[i]] = true;
}
cout << ans;
return 0;
}