QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#836398 | #9920. Money Game 2 | ucup-team191# | WA | 3ms | 28428kb | C++23 | 2.8kb | 2024-12-28 19:41:59 | 2024-12-28 19:41:59 |
Judging History
This is the latest submission verdict.
- [2024-12-31 22:17:02]
- hack成功,自动添加数据
- (/hack/1322)
- [2024-12-31 21:57:13]
- hack成功,自动添加数据
- (/hack/1321)
- [2024-12-28 19:41:59]
- Submitted
answer
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;
using vl=vector<ll>;
#define pb push_back
#define all(a) begin(a),end(a)
const int N=1000010,MOD=1e9+7,M=1<<20;
const char en='\n';
const ll LLINF=1ll<<60,INF=MOD*2;
array<ll,3> merR(const array<ll,3>&a,const array<ll,3>&b)
{
ll sz=a[2]+b[2];
if (b[0]>=a[1])
{
if (a[2]>=31) return {a[0]+1,INF,sz};
ll na=a[0]+1+((b[0]-a[1])>>a[2]);
ll p2=1<<a[2];
ll os=p2-1-((b[0]-a[1])&(p2-1));
if (os==0) return {na,b[1],sz};
if (b[2]>=31) return {na,INF,sz};
return {na,min(INF,(os<<b[2])+b[1]),sz};
}
ll os=a[1]-b[0]-1;
if (os==0) return {a[0],b[1],sz};
if (b[2]>=31) return {a[0],INF,sz};
return {a[0],min(INF,(os<<b[2])+b[1]),sz};
}
array<ll,3> merL(const array<ll,3>&a,const array<ll,3>&b)
{
return merR(b,a);
}
int t,n,h[N];
array<ll,3> segL[M*2+10],segR[M*2+10]; //segR: left is most valuable(so going from i rightwards), segL: right is most valuable(so going from i leftwards)
void updL(int i,array<ll,3> x)
{
segL[i+=M]=x;
for (i/=2;i;i/=2) segL[i]=merL(segL[i*2],segL[i*2+1]);
}
void updR(int i,array<ll,3> x)
{
segR[i+=M]=x;
for (i/=2;i;i/=2) segR[i]=merR(segR[i*2],segR[i*2+1]);
}
pair<array<ll,3>,int> incL(int i,array<ll,3> x)
{
i+=M;
while (i>1)
{
if (i&1)
{
auto c1=merL(segL[i^1],x);
if (c1[0]!=x[0])
{
i^=1;
while (i<M)
{
c1=merL(segL[i*2+1],x);
if (c1[0]!=x[0]) i=i*2+1;
else x=c1,i=i*2;
}
return {merL(segL[i],x),i-M};
}
x=c1;
}
i/=2;
}
return {x,-1};
}
pair<array<ll,3>,int> incR(int i,array<ll,3> x)
{
i+=M;
while (i>1)
{
if (i%2==0)
{
auto c1=merR(x,segR[i^1]);
if (c1[0]!=x[0])
{
i^=1;
while (i<M)
{
c1=merR(x,segR[i*2]);
if (c1[0]!=x[0]) i=i*2;
else x=c1,i=i*2+1;
}
return {merR(x,segR[i]),i-M};
}
x=c1;
}
i/=2;
}
return {x,M};
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>t;
while (t--)
{
cin>>n;
for (int i=0;i<n;++i)
{
cin>>h[i];
h[i+n]=h[i];
}
for (int i=0;i<2*n;++i)
{
updL(i,array<ll,3>({h[i],2,1}));
updR(i,array<ll,3>({h[i],2,1}));
}
for (int i=0;i<n;++i)
{
vector<pair<ll,int>> sr,sl;
array<ll,3> cu={0,2,1};
int cui=i;
while (1)
{
auto no=incR(cui,cu);
if (no.y>=i+n) break;
sr.pb({no.x[0],no.y-i});
cu=no.x;
cui=no.y;
}
cu={0,2,1};
cui=i+n;
while (1)
{
auto no=incL(cui,cu);
if (no.y<=i) break;
sl.pb({no.x[0],i+n-no.y});
cu=no.x;
cui=no.y;
}
ll ma=0;
for (auto x: sl) for (auto y: sr) if (x.y+y.y<n) ma=max(ma,x.x+y.x);
cout<<h[i]+ma<<' ';
}
cout<<en;
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 28164kb
input:
3 5 2 1 4 3 5 5 2 1 3 1 2 1 1000000000
output:
6 5 7 8 8 4 4 5 4 4 1000000000
result:
ok 11 numbers
Test #2:
score: 0
Accepted
time: 0ms
memory: 28428kb
input:
1 10 8 15 18 15 13 4 14 4 17 5
output:
30 37 41 39 34 27 29 26 31 27
result:
ok 10 numbers
Test #3:
score: -100
Wrong Answer
time: 3ms
memory: 24296kb
input:
1000 4 8 9 7 9 1 9 1 10 2 3 9 3 4 3 2 4 0 4 3 1 4 10 8 4 6 1 9 1 4 4 10 10 1 6 1 9 1 0 2 4 6 4 8 1 6 7 2 5 10 4 9 2 1 4 3 5 5 9 3 9 8 9 4 4 8 5 6 2 10 1 1 7 3 9 2 4 4 2 4 1 2 3 5 2 1 1 4 3 2 0 9 4 7 3 10 1 3 4 1 2 2 6 4 1 2 3 3 1 5 3 5 8 4 2 9 3 4 5 9 10 3 4 6 5 4 0 1 6 4 3 1 10 1 4 1 9 5 7 4 8 1 6 ...
output:
18 18 17 18 9 10 3 9 6 6 5 3 4 3 3 18 16 13 15 9 4 18 17 11 14 9 0 4 6 13 9 11 14 5 10 12 7 6 9 11 11 13 17 16 17 12 14 13 12 10 1 7 12 8 9 5 6 4 4 5 2 4 4 2 5 9 11 11 13 10 4 4 2 6 4 2 3 4 5 11 12 10 9 3 13 17 16 12 9 10 7 6 6 3 7 10 7 9 13 12 11 14 10 12 16 1...
result:
wrong answer 7th numbers differ - expected: '7', found: '3'