1 solutions
-
0
Guest MOD
-
0
#include<algorithm> #include<iostream> #include<cstring> #include<cstdlib> #include<cstdio> #include<queue> #include<cmath> #define il inline using namespace std; const int N=1e5+50; #define int long long struct node { int flag=0; int a,b; }s[N*4]; long long query(int id,int l,int r,int x) { if(s[id].flag==1&&x<=r&&x>=l) return s[id].a*x+s[id].b; int mid=l+r>>1; if(x<=mid) return query(id*2,l,mid,x); else return query(id*2+1,mid+1,r,x); } void pushup(int id) { if(s[id*2].flag==1&&s[id*2+1].flag==1&&s[id*2].a==s[id*2+1].a&&s[id*2].b==s[id*2+1].b) { s[id].flag=1; s[id].a=s[id*2].a; s[id].b=s[id*2].b; s[id*2].flag=0; s[id*2+1].flag=0; } } void add(int id,int l,int r,int a,int b) { int mid=l+r>>1; if(s[id].flag==1) { if((a*l+b)>=(s[id].a*l+s[id].b)&&(a*r+b)>=(s[id].a*r+s[id].b)) { s[id].a=a,s[id].b=b; return; } else if((a*l+b)<=(s[id].a*l+s[id].b)&&(a*r+b)<=(s[id].a*r+s[id].b)) return; else { s[id*2].flag=s[id*2+1].flag=1; s[id*2].a=s[id*2+1].a=s[id].a; s[id*2].b=s[id*2+1].b=s[id].b; s[id].flag=0; add(id*2,l,mid,a,b); add(id*2+1,mid+1,r,a,b); pushup(id); } } else { add(id*2,l,mid,a,b); add(id*2+1,mid+1,r,a,b); pushup(id); } } signed main() { int a,b; cin>>a>>b; //[1,10^5] s[1].flag=1,s[1].a=a,s[1].b=b; int m;cin>>m; while(m--) { int opt; cin>>opt; if(opt==1) { cin>>a>>b; add(1,1,1e5,a,b); } else { int x;cin>>x; cout<<query(1,1,1e5,x)<<"\n"; } } } /* 1 1 10 2 5 1 4 2 2 1000 1 -30 2 2 2343 2 10000 1 -35 250 2 1515 1 789 2 2 1010 */ /* struct nn { int x,n; }a[30010],b[30010],c[30010]; //x为数字值 n为数字在原数组中的下标 int n; long long aa[30010],ans; il void s1(int l,int r) //第一次归并算出aa { if(l==r) return; int mid=(l+r)>>1; s1(l,mid);s1(mid+1,r); int i1=l,i2=mid+1,ii=l; while(i1<=mid&&i2<=r) { if(a[i1].x>=a[i2].x) { c[ii++]=a[i1++]; } else { aa[a[i2].n]+=mid-i1+1; c[ii++]=a[i2++]; } } while(i1<=mid) c[ii++]=a[i1++]; while(i2<=r) c[ii++]=a[i2++]; for(register int i=l;i<=r;i++) a[i]=c[i]; } il int s2(int l,int r) { if(l==r) return aa[b[l].n]; int mid=(l+r)>>1; long long s=0,ss=0; //s为这段区间左半部分的aa和,ss为这段区间的aa和 s=ss=s2(l,mid); ss+=s2(mid+1,r); int i1=l,i2=mid+1,ii=l; while(i1<=mid&&i2<=r) { if(b[i1].x>=b[i2].x) { s-=aa[b[i1].n]; c[ii++]=b[i1++]; } else { ans+=s; c[ii++]=b[i2++]; } } while(i1<=mid) c[ii++]=b[i1++]; while(i2<=r) c[ii++]=b[i2++]; for(register int i=l;i<=r;i++) b[i]=c[i]; return ss; //返回区间的aa和 } int main() { scanf("%d\n",&n); for(register int i=1;i<=n;i++) { scanf("%d",&a[i].x); a[i].n=i; b[i]=a[i]; } s1(1,n); s2(1,n); printf("%lld\n",ans); return 0; } */
- 1
Information
- ID
- 760
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 8
- Tags
- # Submissions
- 23
- Accepted
- 4
- Uploaded By