multiset 28分求助
  • 板块P1503 鬼子进村
  • 楼主Ray662
  • 当前回复5
  • 已保存回复5
  • 发布时间2023/1/13 20:12
  • 上次更新2023/10/24 04:23:17
查看原帖
multiset 28分求助
502658
Ray662楼主2023/1/13 20:12
#include <bits/stdc++.h>
#define ll long long
#define _for(i, a, b)  for (int i = (a); i <= (b); i ++ )
#define _all(i, a, b)  for (int i = (a); i >= (b); i -- )
using namespace std;
int n, m;
multiset<int> s;
multiset<int> :: iterator it;
stack<int> d;
int main() {
	ios :: sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	s.insert(0), s.insert(n + 1);
	char opt;
	int x;
	while (m -- ) {
		cin >> opt;
		if (opt == 'D') {
			cin >> x;
			s.insert(x), d.push(x);
		}
		else if (opt == 'R')  s.erase(s.find(d.top())), d.pop();
		else {
			cin >> x;
			it = s.lower_bound(x);
			if (*it == x)  puts("0");
			else  cout << (*it - *( -- it)) - 1 << endl;
		}
	}
	return 0;
}
2023/1/13 20:12
加载中...