QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#355318 | #8112. Pastry shop | jiangly (Lingyu Jiang)# | WA | 1ms | 9824kb | C++20 | 1.5kb | 2024-03-16 15:50:38 | 2024-03-16 15:50:38 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define PI pair<ll,int>
#define fi first
#define se second
#define mp make_pair
const int N=200005;
int n,m,L[N],R[N],d[N],q[N],sz[N];
ll ans,xs,t[N],an[N],su[N];
ll sum(ll x){
return x*(x+1)/2;
}
void ins(int x,int de){
ans+=de*(t[x]*sz[x]-su[x]);
xs+=de*sum(sz[x]-1);
}
bool cmp(int x,int y){
return d[x]<d[y];
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cin >> n >> m;
For(i,1,n)cin>>t[i];
priority_queue<PI,vector<PI>,greater<PI> > heap;
For(i,1,n){
heap.push(mp(t[i]-t[i-1],i));
}
For(i,0,n){L[i]=R[i]=i; sz[i]=1; su[i]=t[i];}
For(i,1,m)cin>>d[q[i]=i];
sort(q+1,q+m+1,cmp);
ans=0,xs=0;
For(i,1,m){
int x=q[i];
while(!heap.empty()&&heap.top().fi<=d[x]){
int p=heap.top().se;
heap.pop();
if(R[p]!=-1){
ins(p,-1); ins(L[p-1],-1);
R[L[p-1]]=R[p];
L[R[p]]=L[p-1];
sz[L[p-1]]+=sz[p];
su[L[p-1]]+=su[p];
L[p]=R[p]=-1;
p=L[p-1];
ins(p,1);
ll tmp=(t[R[p]+1]-t[p])/sz[p]+1;
if(R[p]<n)heap.push(mp(tmp,R[p]+1));
}
}
an[x]=ans+xs*d[x];
}
For(i,1,m)cout<<an[i]<<"\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 9792kb
input:
4 3 3 10 11 23 4 2 5
output:
4 1 6
result:
ok 3 number(s): "4 1 6"
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 9824kb
input:
100 100 1 3 5 5 6 10 10 12 13 14 14 14 14 15 16 17 18 19 19 19 20 22 24 26 26 29 29 30 30 30 31 31 32 32 33 36 37 38 40 40 42 43 43 46 47 47 48 49 55 56 59 60 61 61 63 64 64 65 65 66 67 68 72 74 76 76 77 79 80 80 81 81 81 81 82 82 82 84 84 84 85 87 87 88 89 89 89 90 90 91 91 91 92 93 94 95 99 100 10...
output:
421601 242077 38293 67405 421601 115925 280893 212965 348821 300301 465269 120777 111073 377933 96517 57701 455565 343969 198409 222669 72257 9181 421601 38293 387637 232373 329413 411897 28589 111073 460417 334265 57701 43145 470121 290597 115925 179001 246929 23737 421601 470121 431305 57701 47997...
result:
wrong answer 1st numbers differ - expected: '439025', found: '421601'