BZOJ 1012 最大数

题意:

1.查询序列后q个数字中的最大值

2.在序列尾部插入(n+t)%d,其中t是上一次查询的结果

题解:
首先想到的是用一个线段树去维护整个后Q个数字的区间。其实并不需要这么做,考虑这样一个问题,如果一个数右面有一个比他大的数,那么这个数永远不会成为最大值,写到这里这题基本上就算完成了,一道单调栈+二分的题目。

/*
  ID:Agreement
  LANG:C++
*/
// Invincible
#include <bits/stdc++.h>
#define rep( i , l , r ) for( int i = (l) ; i <= (r) ; ++i )
#define per( i , r , l ) for( int i = (r) ; i >= (l) ; --i )
#define erep( i , u ) for( int i = head[(u)] ; ~i ; i = e[i].nxt )
using namespace std;
inline int _read(){
    register int x = 0 , f = 1;
    register char ch = getchar();
    while( ch > '9' || ch < '0' ) { if( ch == '-' ) f = -1; ch = getchar(); }
    while( ch >= '0' && ch <= '9' ){
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}
const int maxn = 2 * 1e5 + 5;
int N , MOD , t , top , l , x;
int s[maxn] , a[maxn];
char ch[20];
int main(){
    scanf("%d %d" , &N , &MOD);
    while( N-- ){
        scanf("%s%d" , ch , &x);
        if( ch[0] == 'A' ){
            x = (x + t) % MOD;
            s[++l] = x;
            while( top && s[a[top]] < x ) top--;
            a[++top] = l;
        }else{
            int y = lower_bound( a + 1 , a + 1 + top , l - x + 1 ) - a;
            printf("%d\n" , t = s[a[y]]);
        }
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值