제출 #761911

#제출 시각아이디문제언어결과실행 시간메모리
761911Ahmed57말 (IOI15_horses)C++17
34 / 100
373 ms71964 KiB
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; //Fast long long fast(long long a,long long b){ if(b==0)return 1; if(b==1)return a%mod; long long ha = fast(a,b/2)%mod; if(b%2==0)return (ha*ha)%mod; else return (((ha*ha)%mod)*a)%mod; } long long seg[800001],lazy[800001]; double seg2[800001],lazy2[800001]; void prop(int p,int l,int r){ seg[p]*=lazy[p]; seg[p]%=mod; seg2[p]+=lazy2[p]; if(l!=r){ lazy[p*2]*=lazy[p]; lazy[p*2]%=mod; lazy2[p*2]+=lazy2[p]; lazy[p*2+1]*=lazy[p]; lazy[p*2+1]%=mod; lazy2[p*2+1]+=lazy2[p]; } lazy[p] = 1; lazy2[p] = 0; } void update(int p,int l,int r,int lq,int rq,long long val,double val2){ prop(p,l,r); if(l>=lq&&r<=rq){ lazy[p]*=val; lazy[p]%=mod; lazy2[p]+=val2; prop(p,l,r); return ; } if(l>rq||r<lq)return ; int md = (l+r)/2; update(p*2,l,md,lq,rq,val,val2); update(p*2+1,md+1,r,lq,rq,val,val2); if(seg2[p*2]>seg2[p*2+1]){ seg2[p]= seg2[p*2]; seg[p] = seg[p*2]; }else{ seg2[p]= seg2[p*2+1]; seg[p] = seg[p*2+1]; } } pair<long long,double> query(int p,int l,int r,int lq,int rq){ prop(p,l,r); if(l>=lq&&r<=rq)return {seg[p],seg2[p]}; if(l>rq||r<lq)return {0,-1}; int md = (l+r)/2; pair<long long,double> p1 = query(p*2,l,md,lq,rq); pair<long long,double> p2 = query(p*2+1,md+1,r,lq,rq); if(p1.second>p2.second)return p1; else return p2; } int n; vector<long long> x,y; long long init(int N,int X[],int Y[]){ n = N; for(int i = 0;i<=8e5;i++){ seg[i] = 1, lazy[i] = 1; seg2[i] = 0 , lazy2[i] = 0; } for(int i = 0;i<n;i++){ x.push_back(X[i]); y.push_back(Y[i]); update(1,1,n,i+1,n,X[i],log(X[i])); update(1,1,n,i+1,i+1,Y[i],log(Y[i])); } return query(1,1,n,1,n).first; }long long updateX(int pos,int val){ update(1,1,n,pos+1,n,fast(x[pos],mod-2),-log(x[pos])); x[pos] = val; update(1,1,n,pos+1,n,x[pos],log(x[pos])); return query(1,1,n,1,n).first; }long long updateY(int pos,int val){ update(1,1,n,pos+1,pos+1,fast(y[pos],mod-2),-log(y[pos])); y[pos] = val; update(1,1,n,pos+1,pos+1,y[pos],log(y[pos])); return query(1,1,n,1,n).first; }/* int main(){ int X[] = {2,1,3}; int Y[] = {3,4,1}; cout<<init(3,X,Y)<<endl; cout<<updateX(0,1)<<endl; }*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...