标签:turn printf getchar while oid amp print ++ pen
#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
}
}
}
标签:turn printf getchar while oid amp print ++ pen
原文地址:https://www.cnblogs.com/leiyuanze/p/12337021.html