题目
代码
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5+10;
unordered_map<int, int> mp;
int c, m, n;
int res;
struct grid{
int l;
int r;
int pos;
int val;
bool explode;
bool const operator < (const grid& a)
{
return pos < a.pos;
}
} grid[N];
void solve(int i)
{
if(++grid[i].val < 5) return;
res--; grid[i].explode = true;
int left = grid[i].l;
int right = grid[i].r;
grid[left].r = right;
grid[right].l = left;
if(left > 0) solve(left);
if(!grid[right].explode && right < m+1) solve(right);
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> c >> m >> n;
for(int i = 1; i <= m; i++)
{
int x, w;
cin >> x >> w;
grid[i].pos = x;
grid[i].val = w;
}
sort(grid+1, grid+m+1);
for(int i = 1; i <= m; i++)
{
mp[grid[i].pos] = i;
grid[i].l = i-1;
grid[i].r = i+1;
}
res = m;
for(int i = 1; i <= n; i++)
{
int p;
cin >> p;
int pos = mp[p];
//grid[pos].val++;
solve(pos);
cout << res << '\n';
}
}