题意:删除与当前区间有交点的区间,并插入此区间
思路:注意到当前维护的区间不能有交点,区间具有很好的排序性质,可以二分查找。
注意问题:读入字符时应采用scanf( ' %s') 的方式,用getchar读走回车可能会出现问题。
// luogu-judger-enable-o2
#include <bits/stdc++.h>
using namespace std;
typedef int LL;
typedef pair<LL,LL> pii;
set<pii> se;
vector<pii> ve;
int main()
{
LL m,x,y;
scanf("%d",&m);
char str[5];
char ch;
for( LL i =1;i <= m;i++ ){
scanf("%s",str);
ch = str[0];
if( ch == 'B' ){
printf("%d\n",se.size());
continue;
}
scanf("%d%d",&x,&y);
auto p1 = se.upper_bound( pii(x,0) );
if( p1 != se.begin() ) p1--;
ve.clear();
LL ans= 0;
for( ;p1->first <= y && p1 != se.end() ;p1++ ){
if( p1->second >= x ){
ve.push_back( *p1 );
ans++;
}
}
for( LL i = 0;i < ve.size();i++ ){
//if( se.find( ve[i] ) != se.end() )
se.erase( ve[i] );
}
se.insert( pii( x,y ) );
printf("%d\n",ans);
}
return 0;
}