STL场
D - Cutting Woods
set 自带排序功能,map也是
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 2e5 + 9;
const int mod = 998244353;
ll n, m, k, l, Q;
set <int> s;
set <int>::iterator it;
void work()
{
cin >> l >> Q;
s.insert(0);s.insert(l);
while(Q--)
{
cin >> m >> k;
if(m == 1) s.insert(k);
else
{
it = s.lower_bound(k);
//auto it = s.lower_bound(k);如果懒得定义迭代器,可以用自动变量 auto,接收返回的迭代器
int ans = *it;
--it;
cout << (ans - *it) << endl;
}
}
}
int main()
{
ios::sync_with_stdio(0);
//int TT;cin>>TT;while(TT--)
work();
return 0;
}
E - Sorting Queries
优先队列模拟
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 2e5 + 9;
const int mod = 998244353;
ll n, m, k, l, Q;
ll a[maxn];
priority_queue <int, vector<int>, greater<int> > q;
void work()
{
cin >> Q;
int l = 1, r = 0;
for(int i = 1; i <= Q; ++i)
{
ll x, op;
cin >> op;
if(op == 1)
{
cin >> x;
a[++r] = x;
}
else if(op == 2)
{
if(q.empty())
{
cout << a[l] << endl;
++l;
}
else
{
cout << q.top() << endl;
q.pop();
}
}
else
{
for(int i = l; i <= r; ++i)
q.push(a[i]);
l = r + 1;
}
}
}
int main()
{
ios::sync_with_stdio(0);
//int TT;cin>>TT;while(TT--)
work();
return 0;
}