PPMM

代码

#include<cstdio>
using namespace std;
const int N = 1000000 , INF = 2e9;
int n , m , x , head = 1 , tail , p , s;
char opt[5];
inline int read()
{
char ch = getchar();
int res = 0 , f = 1;
for(; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') f = -f;
for(; ch >= '0' && ch <= '9'; ch = getchar()) res = (res << 3) + (res << 1) + ch - '0';
return res * f;
}
inline int my_m(int x , int y , int o)
{
if (!o) return x > y ? x : y;
if (o) return x < y ? x : y;
}
struct tree{
int top;
int tr[(N << 2) + 5][3];
inline void change(int l , int r , int k , int x , int v)
{
if (l == r && l == x)
{
tr[k][0] = tr[k][1] = v;
return;
}
int mid = (l + r) >> 1;
if (x <= mid) change(l , mid , k << 1 , x , v);
else change(mid + 1 , r , k << 1 | 1 , x , v);
tr[k][0] = my_m(tr[k << 1][0] , tr[k << 1 | 1][0] , 0);//Max
tr[k][1] = my_m(tr[k << 1][1] , tr[k << 1 | 1][1] , 1);//Min
}
inline int query(int l , int r , int k , int x , int y , int o)
{
if (l >= x && r <= y) return tr[k][o];
int mid = (l + r) >> 1 , res = INF;
if (!o) res = -res;
if (x <= mid) res = my_m(res , query(l , mid , k << 1 , x , y , o) , o);
if (y > mid) res = my_m(res , query(mid + 1 , r , k << 1 | 1 , x , y , o) , o);
return res;
}
}f;
int main()
{
// freopen("PPMM.in" , "r" , stdin);
// freopen("PPMM.out" , "w" , stdout);
n = read();
m = n;
while (m--)
{
opt[1] = getchar();
while (opt[1] != 'P' && opt[1] != 'M') opt[1] = getchar();
opt[2] = getchar() , opt[3] = getchar();;
if (opt[1] == 'P' && opt[2] == 'U')
{
x = read();
if (p == 1) x = -x;
tail++ , s++;
f.change(1 , n , 1 , tail , x);
}
if (s == 0) continue;
if (opt[1] == 'P' && opt[2] == 'O') head++ , s--;
else if (opt[1] == 'M' && opt[2] == 'I') p ^= 1;
else
if (opt[1] == 'M' && opt[2] == 'A')
{
if (p == 0) printf("%d\n" , f.query(1 , n , 1 , head , tail , 0));//Max
else printf("%d\n" , -1 * f.query(1 , n , 1 , head , tail , 1));//Min
}
}
}
posted @   leiyuanze  阅读(845)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示