码迷,mamicode.com
首页 > 其他好文 > 详细

[Cogs] 最大数maxnumber

时间:2018-03-11 19:13:13      阅读:718      评论:0      收藏:0      [点我收藏+]

标签:blank   poi   return   stream   log   bre   tchar   AC   getchar   

http://cogs.pro:8080/cogs/problem/problem.php?pid=1844

Luogu 的数据真zhizhang

Cogs AC

传错参数WA一下午,气炸

#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

#define gc getchar()
#define LL long long

const LL oo = 2147483647;
const int N = 2e5 + 10;

LL n, Mod, Answer, tot;
LL Max[N << 2];

#define lson jd << 1
#define rson jd << 1 | 1 

void Build_tree(int l, int r, int jd) {
    Max[jd] = -oo;
    if(l == r) return ;
    int mid = (l + r) >> 1;
    Build_tree(l, mid, lson);
    Build_tree(mid + 1, r, rson);
}

void Poi_G(int l, int r, int jd, int x, LL num) {
    if(l == r) {Max[jd] = num; return ;}
    int mid = (l + r) >> 1;
    if(x <= mid) Poi_G(l, mid, lson, x, num);
    else Poi_G(mid + 1, r, rson, x, num);
    Max[jd] = max(Max[lson], Max[rson]);
}

void Sec_A(int l, int r, int jd, int x, int y) {
    if(x <= l && r <= y) {Answer = max(Answer, Max[jd]); return ;}
    int mid = (l + r) >> 1;
    if(x <= mid) Sec_A(l, mid, lson, x, y);
    if(y > mid)  Sec_A(mid + 1, r, rson, x, y);
}

int main() {
    cin >> n >> Mod;
    Build_tree(1, n, 1);
    int m = n;
    while(m --) {
        char c;
        cin >> c;
        if(c == A) {
            LL num;
            cin >> num;
            tot ++;
            Poi_G(1, n, 1, tot, (Answer + num) % Mod);
        } else {
            int len;
            cin >> len;
            if(!len) {cout << 0; break;}
            Answer = - oo;
            Sec_A(1, n, 1, tot - len + 1, tot);
            cout << Answer << endl;
        } 
    }
    
    return 0;
}

 

[Cogs] 最大数maxnumber

标签:blank   poi   return   stream   log   bre   tchar   AC   getchar   

原文地址:https://www.cnblogs.com/shandongs1/p/8544860.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!