• bzoj1058 [ZJOI2007]报表统计


    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1058

    【题解】

    这个insert操作好py啊是不是用set就能搞搞啊。

    什么?你跟我讲T了?

    读入优化?还是T?

    卡了卡常,发现一个东西用priority_queue就够了。。

    然后12s过了。

    # include <set>
    # include <queue>
    # include <stdio.h>
    # include <string.h>
    # include <iostream>
    # include <algorithm>
    // # include <bits/stdc++.h>
    
    using namespace std;
    
    typedef long long ll;
    typedef long double ld;
    typedef unsigned long long ull;
    const int M = 5e5 + 10;
    const int mod = 1e9+7;
    
    # define RG register
    # define ST static
    
    int n, q, a[M];
    int beg[M], end[M]; 
    
    multiset<int> num;
    multiset<int> st2;
    priority_queue<int, vector<int>, greater<int> > st1;
    
    inline int read() {
        int x = 0, f = 1; 
        char ch = getchar();
        while(!isdigit(ch)) {
            if(ch == '-') f = -1;
            ch = getchar();
        }
        while(isdigit(ch)) {
            x = (x<<3)+(x<<1)+ch-'0';
            ch = getchar();
        }
        return x*f;
    }
    
    inline void del(int x) {
        st2.erase(st2.find(x));
    }
    
    multiset<int>::iterator it;
    
    inline void push(int x) {
        int ins = 1e9;
        it = num.lower_bound(x);
        if(it != num.end()) {
            int y = *it;
            ins = min(ins, y-x);
        }
        if(it != num.begin()) {
            int y = *--it;
            ins = min(ins, x-y);
        }
        st1.push(ins);
        num.insert(x);
    }
    int main() {
        cin >> n >> q;
        for (int i=1, t; i<=n; ++i) {
    //        printf("i = %d
    ", i);
            t = read();
            beg[i] = end[i] = t;
            push(t);
            if(i >= 2) st2.insert(abs(t - beg[i-1]));
        }
        char st[23];
        int ps, d;
        while(q--) {
            scanf("%s", st);
            if(st[0] == 'I') {
                ps = read(), d = read();
                push(d);
                if(ps != n) {
                    del(abs(end[ps] - beg[ps+1]));
                    st2.insert(abs(d - end[ps]));
                    st2.insert(abs(d - beg[ps+1]));
                } else st2.insert(abs(d - end[ps]));
                end[ps] = d;
            } else if(st[4] == 'S') printf("%d
    ", st1.top());
            else printf("%d
    ", *st2.begin());
        }
        return 0;
    }
    View Code
  • 相关阅读:
    在Windows 10 环境下安装 Hadoop3.1.2
    jQuery选择器分类
    Hibernate 注解的用法以及说明
    EF中Repository模式应用场景
    C# Lambda表达式
    arpd编译错误
    【转】matplotlib画图时的中文设置
    Xt800、DEFY自带号码归属地更新包,更新至2013.4【数据总数278360条】
    80个Python经典资料(教程+源码+工具)汇总
    POJ 1026:Cipher
  • 原文地址:https://www.cnblogs.com/galaxies/p/bzoj1058.html
Copyright © 2020-2023  润新知