1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| #include<iostream> #include<cstdio> using namespace std; using ll=long long ; const int N=3e5+10; template<class T> inline void read(T &x) { x=0;bool f=0; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=1;ch=getchar();} while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar(); if(f)x=~x+1; } template<class T,class ...T1> inline void read(T &x,T1 &...x1) { read(x),read(x1...); } struct Point{ll x,y;}sta[N]; int n,m,top; ll sumk,sumb; inline ll f(const Point &now){return sumk*now.x+now.y+sumb;} int main() { read(n,m); sta[top=1]={0,0}; while(m--) { int op,k; read(op); if(op==1)read(k),sta[top=1]={0,0},n+=k,sumk=sumb=0; else if(op==2) { read(k); Point now={n,-sumk*n-sumb}; if(f(sta[top])) while(top>1&&(f(now)-f(sta[top]))*(sta[top-1].x-sta[top].x) >=(f(sta[top-1])-f(sta[top]))*(now.x-sta[top].x))top--; sta[++top]=now; n+=k; } else { int b; read(b,k); sumk+=k,sumb+=b; } while(top>1&&f(sta[top])>=f(sta[top-1]))top--; printf("%lld %lld\n",sta[top].x+1,f(sta[top])); } return 0; }
|