bzoj 1058: [ZJOI2007]报表统计
维护每一个原本的点和加入他的最后一个点,<set>妥妥的
1 /* 2 ID:WULALA 3 PROB:bzoj1058 4 LANG:C++ 5 */ 6 #include <cstdio> 7 #include <cstring> 8 #include <algorithm> 9 #include <cmath> 10 #include <iostream> 11 #include <ctime> 12 #include <set> 13 #define N 500008 14 #define M 15 #define mod 16 #define mid(l,r) ((l+r) >> 1) 17 #define INF 1e9 18 using namespace std; 19 20 int n,m,tot,l[N],r[N],mgp,msp; 21 multiset<int> bst,c; 22 set<int>::iterator it; 23 24 int main() 25 { 26 freopen("input.txt","r",stdin); 27 freopen("output.txt","w",stdout); 28 mgp = msp = INF; 29 bst.insert(-INF); 30 bst.insert(INF); 31 scanf("%d%d",&n,&m); 32 l[0] = l[n+1] = INF; 33 for (int i = 1;i <= n;i++) 34 { 35 int b; 36 scanf("%d",&b); 37 l[i] = r[i] = b; 38 c.insert(abs(l[i] - l[i-1])); 39 int x =* bst.lower_bound(b),y =* --bst.lower_bound(b); 40 msp = min(msp,min(abs(b - y),abs(b - x))); 41 bst.insert(b); 42 } 43 for (int i = 1;i <= m;i++) 44 { 45 char s[20]; 46 scanf("%s",s); 47 if (s[0] == 'I') 48 { 49 int a,b; 50 scanf("%d%d",&a,&b); 51 it = bst.lower_bound(abs(r[a] - l[a+1])); 52 printf("%d ",abs(r[a] - l[a+1])); 53 printf("%d\n\n",*it); 54 if (*it == abs(r[a] - l[a+1])) c.erase(it); 55 // c.erase(abs(r[a] - l[a+1])); 56 c.insert(abs(r[a] - b)); 57 c.insert(abs(l[a+1] - b)); 58 r[a] = b; 59 int x =* bst.lower_bound(b),y =* --bst.lower_bound(b); 60 msp = min(msp,min(abs(b - y),abs(b - x))); 61 bst.insert(b); 62 } 63 else if (s[4] == 'S') printf("%d\n",msp); 64 else 65 { 66 int r =* c.lower_bound(-1); 67 printf("%d\n",r); 68 } 69 } 70 return 0; 71 }