QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#291835 | #7417. Honorable Mention | ucup-team1004 | WA | 613ms | 69056kb | C++14 | 3.3kb | 2023-12-27 09:21:10 | 2023-12-27 09:21:10 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define all(a) begin(a),end(a)
#ifdef DEBUG
template<class T>
ostream& operator << (ostream &out,vector<T> a){
out<<'[';
for(T x:a)out<<x<<',';
return out<<']';
}
template<class T>
vector<T> ary(T *a,int l,int r){
return vector<T>{a+l,a+1+r};
}
template<class T>
void debug(T x){
cerr<<x<<endl;
}
template<class T,class...S>
void debug(T x,S...y){
cerr<<x<<' ',debug(y...);
}
#else
#define debug(...) void()
#endif
const int N=3.5e4+10,M=2,V=N;
const ll INF=1e18,Inf=1e12;
int n,m,a[N];
vector<ll>t[N<<2][M][M],s[N<<2][M][M];
void chkmax(vector<ll>&A,vector<ll>&P,vector<ll>&Q){
int len=P.size()+Q.size()-1;
vector<ll>B(len);
merge(P.begin()+1,P.end(),Q.begin()+1,Q.end(),B.begin()+1,greater<ll>());
B[0]=P[0]+Q[0];
for(int i=1;i<len;i++)B[i]+=B[i-1];
if(A.size()<len)A.resize(len,-Inf);
for(int i=0;i<len;i++)A[i]=max(A[i],B[i]);
}
void calc(int rt){
for(int i=0;i<M;i++){
for(int j=0;j<M;j++){
auto &s=::s[rt][i][j],&f=t[rt][i][j]=s;
for(int i=f.size()-1;i;i--)f[i]-=f[i-1];
}
}
}
void build(int l=1,int r=n,int rt=1){
if(l==r){
s[rt][0][0]={0};
s[rt][0][1]={-Inf,a[l]};
s[rt][1][0]={0};
s[rt][1][1]={a[l],a[l]};
return calc(rt);
}
int mid=(l+r)>>1;
build(l,mid,rt<<1);
build(mid+1,r,rt<<1|1);
for(int i=0;i<M;i++){
for(int j=0;j<M;j++){
for(int k=0;k<M;k++){
chkmax(s[rt][i][j],t[rt<<1][i][k],t[rt<<1|1][k][j]);
}
}
}
calc(rt);
for(int i=0;i<M;i++){
for(int j=0;j<M;j++){
debug(ary(a,l,r),i,j,s[rt][i][j]);
}
}
}
using node=complex<ll>;
bool cmp(const node &a,const node &b){
return real(a)^real(b)?real(a)<real(b):imag(a)<imag(b);
}
using matrix=array<array<node,M>,M>;
matrix operator * (const matrix &a,const matrix &b){
static matrix c;
for(int i=0;i<M;i++){
fill(c[i].begin(),c[i].end(),node(-INF,0));
}
for(int k=0;k<M;k++){
for(int i=0;i<M;i++){
for(int j=0;j<M;j++){
c[i][j]=max(c[i][j],a[i][k]+b[k][j],cmp);
}
}
}
return c;
}
#ifdef DEBUG
ostream& operator << (ostream &out,node a){
return out<<'('<<real(a)<<','<<imag(a)<<')';
}
ostream& operator << (ostream &out,matrix a){
return out<<"[["<<a[0][0]<<','<<a[0][1]<<"],["<<a[1][0]<<','<<a[1][1]<<"]]";
}
#endif
matrix query(int L,int R,ll k,int l=1,int r=n,int rt=1){
if(L<=l&&r<=R){
static matrix res;
for(int i=0;i<M;i++){
for(int j=0;j<M;j++){
auto &f=t[rt][i][j];
int l=0,r=f.size(),mid;
for(;l+1<r;){
mid=(l+r)>>1;
if(f[mid]>=k)l=mid;
else r=mid;
}
// debug(i,j,k,l);
res[i][j]=node(s[rt][i][j][l]-l*k,l);
}
}
// debug(l,r,k,res);
return res;
}
int mid=(l+r)>>1;
if(R<=mid)return query(L,R,k,l,mid,rt<<1);
if(mid<L)return query(L,R,k,mid+1,r,rt<<1|1);
return query(L,R,k,l,mid,rt<<1)*query(L,R,k,mid+1,r,rt<<1|1);
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
build();
for(int x,y,k;m--;){
scanf("%d%d%d",&x,&y,&k);
int l=-V,r=V,mid;
for(;l+1<r;){
mid=(l+r)>>1;
auto res=query(x,y,mid)[0];
if(max(res[0],res[1],cmp).imag()>=k)l=mid;
else r=mid;
}
auto res=query(x,y,l)[0];
// debug(l,res);
printf("%lld\n",real(max(res[0],res[1],cmp))+k*l);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 30088kb
input:
5 5 -1 2 -3 4 -5 1 5 1 1 5 2 1 5 3 1 5 4 1 5 5
output:
4 6 5 2 -3
result:
ok 5 number(s): "4 6 5 2 -3"
Test #2:
score: 0
Accepted
time: 3ms
memory: 30024kb
input:
5 1 7 7 7 7 7 1 5 1
output:
35
result:
ok 1 number(s): "35"
Test #3:
score: -100
Wrong Answer
time: 613ms
memory: 69056kb
input:
25000 25000 -11889 -16468 18402 -13238 14125 12120 -3295 -12106 20152 7478 8575 9968 -13946 -13408 23715 -14670 -21837 12589 7029 20609 2868 12728 -6942 982 5884 -7561 -2058 -7892 7806 16344 14645 13904 7355 9860 15446 -539 24072 21969 19028 -24939 -21911 -11836 21045 -4727 -3882 2138 18513 -4796 -1...
output:
10341941 44514177 6687268 77971944 99605102 107722534 15473041 17383093 62015893 10703102 41214044 24468833 9407209 9022260 39351814 72311292 5178065 42027491 52700848 38135774 37045964 9842000 16327339 16812496 107985169 28306484 46710957 864270 102812861 27960495 50366764 16379719 2791377 21112728...
result:
wrong answer 12th numbers differ - expected: '22949449', found: '24468833'