蒟蒻用的线段树+动态开点,WA+MLE+RE
感觉数组开的太大了,但再小又RE更多。
#include <bits/stdc++.h>
using namespace std;
const int N=50005;
long long n,rt=-1,op,kl;
struct node{
int a,b,lazy,cnt;
}Tree[80000005];
struct qwe{
long long x,y,c;
}a[N];
bool cmp(qwe asd,qwe zxc){
return asd.y<zxc.y;
}
void Add(int p,int l,int r,int x,int y){
Tree[p].a=l,Tree[p].b=r;
int mid=(l+r)>>1;
if(l==r){
return ;
}
if(x<=mid && Tree[p].a<=y){
if(Tree[(p<<1)].a==0){
Add((p<<1),l,mid,x,y);
}
}
if(x<=Tree[p].b && mid<y){
if(Tree[(p<<1)|1].a==0){
Add((p<<1)|1,mid+1,r,x,y);
}
}
}
void Insert(int p,int l,int r){
if(Tree[p].lazy==1){
return ;
}
if(l<=Tree[p].a && Tree[p].b<=r){
Tree[p].lazy=1;
Tree[p].cnt++;
kl=1;
return ;
}
if(l==r){
return ;
}
int mid=(Tree[p].a+Tree[p].b)>>1;
if(l<=mid && Tree[p].a<=r){
if(Tree[(p<<1)].a==0){
Tree[(p<<1)].a=Tree[p].a,Tree[(p<<1)].b=mid;
}
Insert((p<<1),l,r);
}
if(l<=Tree[p].b && mid<r){
if(Tree[(p<<1)|1].a==0){
Tree[(p<<1)|1].a=mid+1,Tree[(p<<1)|1].b=Tree[p].b;
}
Insert((p<<1)|1,l,r);
}
if(Tree[(p<<1)].lazy==1 && Tree[(p<<1)|1].lazy==1){
Tree[p].lazy=1;
}
if(kl==1){
Tree[p].cnt++;
}
}
int main(){
cin>>n;
for(int i=1; i<=n; i++){
scanf("%lld%lld%lld",&a[i].x,&a[i].y,&a[i].c);
rt=max(rt,-(a[i].x)*a[i].c);
}
sort(a+1,a+1+n,cmp);
for(int i=1; i<=n; i++){
kl=0;
op=-(a[i].x)*a[i].c;
Add(1,1,rt,op-a[i].c,op);
Insert(1,op-a[i].c,op);
}
cout<<Tree[1].cnt;
return 0;
}