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\n", 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\n", st1.top()); else printf("%d\n", *st2.begin()); } return 0; }