Feel the sweep line +set is better than the line segment tree to play some
#include <cstdio> #include <iostream> #include <algorithm> #include <set> #define N 40010 using n
Amespace std;
typedef long Long LL;
multiset<ll,greater<ll> > S;
int n,cnt;
ll Ans;
struct stp{int x; ll k; int g;
friend bool operator < (STP A,STP b) {return a.x<b.x;
}}a[n*3];
Inline char NC () {static Char buf[100000],*p1=buf,*p2=buf; Return p1==p2&& (p2= (p1=buf) +fread (Buf,1,100000,stdin), P1==P2)?
eof:*p1++;
} inline void rea (int &x) {char c=nc (); x=0; int f=1; For (;c> ' 9 ' | |
c< ' 0 '; C=nc ()) f=c== '-'?-f:f; for (; c>= ' 0 ' &&c<= ' 9 '; x=x*10+c-' 0 ', C=NC ());
X*=f;
} inline void Rea (ll &x) {char c=nc (); x=0; int f=1; For (;c> ' 9 ' | |
c< ' 0 '; C=nc ()) f=c== '-'?-f:f; for (; c>= ' 0 ' &&c<= ' 9 '; x=x*10+c-' 0 ', C=NC ());
X*=f;
int main () {REA (n);
for (int i=1;i<=n;i++) {int l,r; ll K; REA (L); Rea (R);
Rea (k);
if (l>=r) continue; A[++cnt]= (STP) {l,k,1};
A[++cnt]= (STP) {r,k,0}; } s.insert (0); Sort (a+1,a+1+cnt);
int last=a[1].x;
for (int i=1;i<=cnt;i++) {ans+=1ll* (a[i].x-last) * (*s.begin ()); last=a[i].x;
if (A[I].G) S.insert (A[I].K);
Else S.erase (S.find (A[I].K));
printf ("%lld\n", ans+ (*s.begin ()));
return 0;
}