bzoj 1208 set,或treap或splay(待补)
tags:写set直接过了,但这题好像还是treap和splay的模板题,不会,留坑待补。
// set #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a;i<=b;i++) #define per(i,b,a) for (int i=b;i>=a;i--) #define mes(a,b) memset(a,b,sizeof(a)) #define INF 0x3f3f3f3f typedef long long ll; const int N = 2000005, mod=1000000; int n; ll a, b, ans; set<ll >A, B; int main() { A.insert(-INF); A.insert(INF); B.insert(-INF); B.insert(INF); scanf("%d", &n); rep(i,1,n) { scanf("%lld %lld", &a, &b); if(a==0) { if(B.size()==2) A.insert(b); else { int x=*(B.upper_bound(b)), y=*(--B.upper_bound(b)); if(abs(x-b)>=abs(y-b)) B.erase(y), ans=(ans+abs(y-b))%mod; else B.erase(x), ans=(ans+abs(x-b))%mod; } } else { if(A.size()==2) B.insert(b); else { int x=*(A.upper_bound(b)), y=*(--A.upper_bound(b)); if(abs(x-b)>=abs(y-b)) A.erase(y), ans=(ans+abs(y-b))%mod; else A.erase(x), ans=(ans+abs(x-b))%mod; } } } printf("%lld\n", (ans+mod)%mod); return 0; }