QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#865247 | #9905. 哈夫曼树 | KFC | Compile Error | / | / | C++98 | 2.1kb | 2025-01-21 16:17:16 | 2025-01-21 16:17:22 |
Judging History
answer
// Hydro submission #678f580a3e10c2b5101fb1a7@1737447434666
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <bitset>
#include <map>
#include <cassert>
#include <queue>
#include <random>
#include <ctime>
#include <set>
#define int long long
using namespace std;
void read(int &x){
x=0;
int f=1;
char c=getchar();
while(!('0'<=c && c<='9')){
if(c=='-'){
f=-1;
}
c=getchar();
}
while('0'<=c && c<='9'){
x=(x<<3)+(x<<1)+(c^48);
c=getchar();
}
x*=f;
}
multiset<pair<int,int> > st;
int sum=0;
void add(pair<int,int> p){
if(p.first>p.second){
swap(p.first,p.second);
}
//printf("[+(%lld %lld)]\n",p.first,p.second);
auto it=st.insert(p);
auto pl=*prev(it),pr=*next(it);
if(pl.second>pr.first){
sum--;
}
if(pl.second>p.first){
sum++;
}
if(p.second>pr.first){
sum++;
}
}
void del(pair<int,int> p){
if(p.first>p.second){
swap(p.first,p.second);
}
//printf("[-(%lld %lld)]\n",p.first,p.second);
auto it=st.find(p);
auto pl=*prev(it),pr=*next(it);
if(pl.second>pr.first){
sum++;
}
if(pl.second>p.first){
sum--;
}
if(p.second>pr.first){
sum--;
}
st.erase(it);
}
int n,q,a[200010],tr[200010][2],dpt[200010],fa[200010];
signed main(){
read(n);
read(q);
for(int i=1;i<=n;i++){
read(a[i]);
}
st.insert(make_pair(-1e18,-1e18));
st.insert(make_pair(1e18,1e18));
for(int i=n+1;i<2*n;i++){
read(tr[i][0]);
read(tr[i][1]);
a[i]=a[tr[i][0]]+a[tr[i][1]];
add(make_pair(a[tr[i][0]],a[tr[i][1]]));
fa[tr[i][0]]=fa[tr[i][1]]=i;
dpt[i]=max(dpt[tr[i][0]],dpt[tr[i][1]])+1;
}
if(dpt[2*n-1]>80){
for(int i=1;i<=q;i++){
printf("NO\n");
}
return 0;
}
printf(sum?"NO\n":"YES\n");
int u;
while(--q){
read(u);
for(int i=fa[u];i;i=fa[i]){
del(make_pair(a[tr[i][0]],a[tr[i][1]]));
}
read(a[u]);
for(int i=fa[u];i;i=fa[i]){
a[i]=a[tr[i][0]]+a[tr[i][1]];
add(make_pair(a[tr[i][0]],a[tr[i][1]]));
}
printf(sum?"NO\n":"YES\n");
}
return 0;
}
/*
5 2
1 2 -2 3 4
1
2 3
1
1 2
*/
Details
In file included from /usr/include/c++/14/random:37, from answer.code:10: /usr/include/c++/14/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options. 32 | #error This file requires compiler and library support \ | ^~~~~ answer.code: In function ‘void add(std::pair<long long int, long long int>)’: answer.code:39:14: error: ‘it’ does not name a type; did you mean ‘int’? 39 | auto it=st.insert(p); | ^~ | int answer.code:40:14: error: ‘pl’ does not name a type 40 | auto pl=*prev(it),pr=*next(it); | ^~ answer.code:41:12: error: ‘pl’ was not declared in this scope; did you mean ‘p’? 41 | if(pl.second>pr.first){ | ^~ | p answer.code:41:22: error: ‘pr’ was not declared in this scope; did you mean ‘p’? 41 | if(pl.second>pr.first){ | ^~ | p answer.code:44:12: error: ‘pl’ was not declared in this scope; did you mean ‘p’? 44 | if(pl.second>p.first){ | ^~ | p answer.code:47:21: error: ‘pr’ was not declared in this scope; did you mean ‘p’? 47 | if(p.second>pr.first){ | ^~ | p answer.code: In function ‘void del(std::pair<long long int, long long int>)’: answer.code:56:14: error: ‘it’ does not name a type; did you mean ‘int’? 56 | auto it=st.find(p); | ^~ | int answer.code:57:14: error: ‘pl’ does not name a type 57 | auto pl=*prev(it),pr=*next(it); | ^~ answer.code:58:12: error: ‘pl’ was not declared in this scope; did you mean ‘p’? 58 | if(pl.second>pr.first){ | ^~ | p answer.code:58:22: error: ‘pr’ was not declared in this scope; did you mean ‘p’? 58 | if(pl.second>pr.first){ | ^~ | p answer.code:61:12: error: ‘pl’ was not declared in this scope; did you mean ‘p’? 61 | if(pl.second>p.first){ | ^~ | p answer.code:64:21: error: ‘pr’ was not declared in this scope; did you mean ‘p’? 64 | if(p.second>pr.first){ | ^~ | p answer.code:67:18: error: ‘it’ was not declared in this scope; did you mean ‘st’? 67 | st.erase(it); | ^~ | st