AcWing 5722. 十滴水
原题链接
困难
作者:
νοιδ
,
2024-07-24 09:03:35
,
所有人可见
,
阅读 22
考场写的(属于是乱写)应该就是模拟了一下,结果过了
#include <iostream>
#include <cstdio>
#include <map>
using namespace std;
int c, m, n;
int x, w;
int p;
map<int, int> A;
map<int, int>::iterator it;
void explode(map<int, int>::iterator& ph){
map<int, int>::iterator it1, it2;
if (ph == A.begin()) it1 = A.end();
else{
ph --;
it1 = ph;
ph ++;
}
ph ++;
it2 = ph;
ph --;
A.erase(ph->first);
if (it1 != A.end()) it1->second ++;
if (it2 != A.end()) it2->second ++;
if (it1 != A.end() && it1->second >= 5) explode(it1);
if (it2 != A.end() && A.find(it2->first) != A.end() && it2->second >= 5) explode(it2);
}
int main(){
cin >> c >> m >> n;
for (int i = 0; i < m; i ++ ){
scanf("%d%d", &x, &w);
A[x] = w;
}
while (n --){
scanf("%d", &p);
A[p]++;
it = A.find(p);
if (it->second >= 5){
explode(it);
}
cout << A.size() << endl;
}
return 0;
}