QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#696854 | #9532. 长野原龙势流星群 | tosivan | 0 | 471ms | 192236kb | C++14 | 2.1kb | 2024-11-01 03:12:43 | 2024-11-01 03:12:44 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll __int128
#define ld long double
const ll INF=1e18;
long long rval[200005];
ll val[200005];
struct Line{
ll m,c,pt;
bool operator<(const Line& l)const{
if(pt!=l.pt)return pt<l.pt;
if(m!=l.m)return m<l.m;
return c<l.c;
}
};
struct Info{
multiset<Line>ms;
void add(ll m, ll c, ll pt){
if(ms.size()==0){ms.insert({m,c,pt});return;}
Line lol=*ms.rbegin();
if(lol.pt<pt){ms.insert({m,c,pt});return;}
lol=*ms.lower_bound({-INF,-INF,pt});
if(pt!=lol.pt){ms.insert({m,c,pt});return;}
lol.m+=m; lol.c+=c;
ms.insert(lol);
}
ll balance(){
ll m=0,c=0;
while(ms.size()){
Line lol=*ms.rbegin();
m+=lol.m,c+=lol.c;
ms.erase(ms.find(lol));
ll x;
if(ms.size()==0){
x=(-c)/m;
ms.insert({m,c,x}); return x;
}
else{
Line finale=*ms.rbegin();
ll x=finale.pt+1;
if(m*x+c>=0){
x=(-c)/m;
ms.insert({m,c,x}); return x;
}
}
}
Line lol=*ms.rbegin(); return lol.pt;
}
ll size(){
return ms.size();
}
};
vector<ll>adj[200005];
Info ms[200005];
ll ans[200005];
void merge(ll a, ll b){
if(ms[a].size()<ms[b].size())swap(ms[a],ms[b]);
for(auto& k: ms[b].ms){
ms[a].add(k.m,k.c,k.pt);
}
}
void dfs(ll s){
for(auto& u: adj[s]){
dfs(u);
merge(s,u);
}
ms[s].add(-1,val[s],INF);
ans[s]=ms[s].balance();
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
long long n;
cin>>n;
for(int i=2;i<=n;i++){
long long k;
cin>>k;
adj[k].push_back(i);
}
for(int i=1;i<=n;i++)cin>>rval[i];
for(int i=1;i<=n;i++){
val[i]=rval[i]; val[i]*=(10000000000LL);
}
dfs(1);
for(int i=1;i<=n;i++){
vector<long long>wtf;
while(ans[i]!=0){
wtf.push_back(ans[i]%10);
ans[i]/=10;
}
reverse(wtf.begin(),wtf.end());
for(int j=0;j<wtf.size()-10;j++){
cout<<wtf[j];
}
cout<<".";
for(int j=wtf.size()-10;j<wtf.size();j++){
cout<<wtf[j];
}
cout<<'\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 22804kb
input:
2000 1 2 2 4 5 2 3 6 4 2 7 2 8 14 8 12 1 14 4 14 8 18 9 2 7 22 20 22 14 29 28 16 6 21 23 6 21 14 13 9 1 4 18 13 2 39 21 33 18 20 38 27 27 1 49 5 51 3 31 24 10 42 2 44 13 9 35 66 27 60 67 59 29 40 53 2 33 43 26 43 62 16 78 45 14 10 73 69 41 35 25 26 2 70 54 1 54 48 5 36 44 28 90 29 51 51 93 82 95 45 ...
output:
999803501.0000000000 999803501.0000000000 998945886.0000000000 999803501.0000000000 994043154.0000000000 994043154.0000000000 993984068.0000000000 998945886.0000000000 994043154.0000000000 997339394.0000000000 894702725.0000000000 992874487.0000000000 998089712.0000000000 997022909.0000000000 935685...
result:
wrong answer 1st numbers differ - expected: '883838885.9230770', found: '999803501.0000000', error = '0.1312056'
Subtask #2:
score: 0
Wrong Answer
Test #32:
score: 0
Wrong Answer
time: 471ms
memory: 192236kb
input:
200000 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 52 52...
output:
999977778.0000000000 999973738.0000000000 999977778.0000000000 999973738.0000000000 999967309.0000000000 999973237.0000000000 999977778.0000000000 999973738.0000000000 999922586.0000000000 999967309.0000000000 999924983.0000000000 999956176.0000000000 999973237.0000000000 999977778.0000000000 999844...
result:
wrong answer 1st numbers differ - expected: '792545632.4154930', found: '999977778.0000000', error = '0.2617290'
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #2:
0%