QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#291828 | #7417. Honorable Mention | ucup-team1004 | WA | 627ms | 69108kb | C++14 | 3.3kb | 2023-12-27 09:15:47 | 2023-12-27 09:15:47 |
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=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 &f=t[rt][i][j],&s=::s[rt][i][j];
f=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]-node(0,k),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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 4ms
memory: 30096kb
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: 0ms
memory: 30096kb
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: 627ms
memory: 69108kb
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 44514576 6687899 77972079 99605207 107722534 15473551 17383263 62015893 10704209 41214189 24468833 9407252 9022604 39352001 72311416 5179293 42027602 52700848 38135939 37046253 9842000 16327339 16812761 107985169 28306780 46711081 868029 102813303 27960781 50366782 16380197 2791670 21112728...
result:
wrong answer 2nd numbers differ - expected: '44514177', found: '44514576'