rt,如果我这么写:
#include<bits/stdc++.h>
using namespace std;
map<int, map<int,int> >Line;
map<int,int> K;
int cnt;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for(int i = 1;i <= n;++i){
int oper,k,b;
cin >> oper >> k >> b;
if(oper == 1)++cnt,++K[k],++Line[k][b];
if(oper == 2) cout << cnt - K[k] << '\n';
if(oper == 3) {
for(map<int,int>::iterator it = K.begin();it != K.end();++it){
if(it -> first == k)cnt -= Line[k][b],K[k] -= Line[k][b],Line[k][b] = 0;
else cnt -= K[it -> first],Line[k][b] = K[k] = 0;
}
}
}
return 0;
}
样例都过不了
但是如果这样写:
#include<bits/stdc++.h>
using namespace std;
map<int, map<int,int> >Line;
map<int,int> K;
int cnt;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for(int i = 1;i <= n;++i){
int oper,k,b;
cin >> oper >> k >> b;
if(oper == 1)++cnt,++K[k],++Line[k][b];
if(oper == 2) cout << cnt - K[k] << '\n';
if(oper == 3) {
for(map<int,int>::iterator it = K.begin();it != K.end();){
if(it -> first == k){
cnt -= Line[k][b],K[k] -= Line[k][b];
Line[k].erase(b);
++it;
if(!K[k]){K.erase(k),Line.erase(k);}
}
else {
int tmp = it -> first;
++it;
cnt -= K[tmp];
K.erase(tmp),Line.erase(tmp);
}
}
if(!K[k]){K.erase(k),Line.erase(k);}
}
}
return 0;
}
100pts,请问这是为什么