zoukankan      html  css  js  c++  java
  • [JSOI2008]最大数maxnumber

    Description

    BZOJ1012

    Solution

    线段树模板题

    (话说vim的ggyG竟然不复制最后一个字符,送来了我bzoj的第一个ce...看来文末换行符还是要打的)

    Code

    #include <cstdio>
    #include <algorithm>
    
    typedef long long LL;
    const int N = 800000 + 10;
    
    LL a[N];
    
    void add(int o, int l, int r, int q, LL v) {
    	if (l == r) {
    		a[o] = v;
    		return;
    	}
    	int mid = (l+r) >> 1;
    	if (q <= mid) add(o<<1, l, mid, q, v);
    	else add(o<<1|1, mid+1, r, q, v);
    	a[o] = std::max(a[o<<1], a[o<<1|1]);	
    }
    
    LL query(int o, int l, int r, int ql, int qr) {
    	if (ql <= l && qr >= r) {
    		return a[o];
    	}
    	int mid = (l+r) >> 1;
    	LL ans = 0;
    	if (ql <= mid) ans = std::max(ans, query(o<<1, l, mid, ql, qr));
    	if (qr > mid) ans = std::max(ans, query(o<<1|1, mid+1, r, ql, qr));
    	return ans;	
    }
    
    int main() {
    	LL m, d;
    	scanf("%lld%lld", &m, &d);
    	LL ans = 0, x, n = 0;
    	char op[3];	
    	for (int i = 1; i <= m; ++i) {
    		scanf("%s%lld", op, &x);
    		if (op[0] == 'A') add(1, 1, m, ++n, (x+ans)%d);
    		else {
    			ans = query(1, 1, m, n-x+1, n);
    			printf("%lld
    ", ans);
    		}
    	}	
    	return 0;
    }
    

    Note

    据说这个题还可以用ST表来解决。

  • 相关阅读:
    织梦开发——相关阅读likeart应用
    织梦标签教程
    织梦专题调用代码
    HIT 2543 Stone IV
    POJ 3680 Intervals
    HIT 2739 The Chinese Postman Problem
    POJ 1273 Drainage Ditches
    POJ 2455 Secret Milking Machine
    SPOJ 371 Boxes
    HIT 2715 Matrix3
  • 原文地址:https://www.cnblogs.com/wyxwyx/p/bzoj1012.html
Copyright © 2011-2022 走看看