QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#680762#7736. Red Black TreeYoralenCompile Error//C++141.5kb2024-10-26 22:35:132024-10-26 22:35:16

Judging History

你现在查看的是最新测评结果

  • [2024-10-26 22:35:16]
  • 评测
  • [2024-10-26 22:35:13]
  • 提交

answer

#include<iostream>
#include<algorithm>
#include<set>
using namespace std;
const int N=100005;
struct edge{int to,next;}w[N<<1];
int n,h[N],cnt,T,a[N],ar[N];
char s[N];
void Add(int x,int y){
    w[++cnt].to=y,w[cnt].next=h[x],h[x]=cnt;
}
int hd[N],ng[N],ans[N],sv[N];
struct Dlt{
	vector<int>ng,ps;
	int no=0,sg=0;
	void Init(){
		ng.clear();ps.clear();
		no=sg=0;
	}
	int val(int k){
		if(k<=ng.size())return ng[k-1];
		else if(k<=ng.size()+no)return 0;
		else return ps[ps.size()-(k-ng.size()-no)];
	}
	void Ins(int v){
		if(v<0)ng.push_back(v),sg+=v;
		if(v==0)no++;
		if(v>0)ps.push_back(v);
	}
	int size(){
		return ng.size()+no+ps.size();
	}
};
Dlt DFS(int u){
    int i,j,ln;hd[u]=a[u];
    Dlt S,F;S.Init();
    for(i=h[u];i;i=w[i].next){
        int e=w[i].to;
        F=DFS(e);hd[u]+=hd[e];
        if(!S.size())S=F,ln=F.size();
        else{
        	ln=min(ln,F.size());
        	for(j=1;j<=ln;j++)ar[j]=S.val(j)+F.val(j);
        	S.Init();int pl=1,pr=ln;
        	while(ar[pl]<0&&pl<=ln)S.Ins(ar[pl]),pl++;
        	while(ar[pr]>0&&pr>=1)S.Ins(ar[pr]),pr--;
        	S.no=pr-pl+1;
        }
    }
    if(a[u]==0)S.Ins(1);else S.Ins(-1);
    ans[u]=hd[u]+S.sg;return S;
}
int main(){
    int i,x;
    scanf("%d",&T);
    while(T--){
        scanf("%d",&n);scanf("%s",s+1);cnt=0;
        for(i=1;i<=n;i++)a[i]=s[i]-'0',h[i]=ng[i]=ans[i]=hd[i]=0;
        for(i=2;i<=n;i++)scanf("%d",&x),Add(x,i);DFS(1);
        for(i=1;i<=n;i++)printf("%d ",ans[i]);putchar('\n');
    }
    return 0;
}

詳細信息

answer.code:14:9: error: ‘vector’ does not name a type
   14 |         vector<int>ng,ps;
      |         ^~~~~~
answer.code: In member function ‘void Dlt::Init()’:
answer.code:17:20: error: request for member ‘clear’ in ‘ng’, which is of non-class type ‘int [100005]’
   17 |                 ng.clear();ps.clear();
      |                    ^~~~~
answer.code:17:28: error: ‘ps’ was not declared in this scope; did you mean ‘s’?
   17 |                 ng.clear();ps.clear();
      |                            ^~
      |                            s
answer.code: In member function ‘int Dlt::val(int)’:
answer.code:21:26: error: request for member ‘size’ in ‘ng’, which is of non-class type ‘int [100005]’
   21 |                 if(k<=ng.size())return ng[k-1];
      |                          ^~~~
answer.code:22:31: error: request for member ‘size’ in ‘ng’, which is of non-class type ‘int [100005]’
   22 |                 else if(k<=ng.size()+no)return 0;
      |                               ^~~~
answer.code:23:29: error: ‘ps’ was not declared in this scope; did you mean ‘s’?
   23 |                 else return ps[ps.size()-(k-ng.size()-no)];
      |                             ^~
      |                             s
answer.code:23:48: error: request for member ‘size’ in ‘ng’, which is of non-class type ‘int [100005]’
   23 |                 else return ps[ps.size()-(k-ng.size()-no)];
      |                                                ^~~~
answer.code: In member function ‘void Dlt::Ins(int)’:
answer.code:26:27: error: request for member ‘push_back’ in ‘ng’, which is of non-class type ‘int [100005]’
   26 |                 if(v<0)ng.push_back(v),sg+=v;
      |                           ^~~~~~~~~
answer.code:28:24: error: ‘ps’ was not declared in this scope; did you mean ‘s’?
   28 |                 if(v>0)ps.push_back(v);
      |                        ^~
      |                        s
answer.code: In member function ‘int Dlt::size()’:
answer.code:31:27: error: request for member ‘size’ in ‘ng’, which is of non-class type ‘int [100005]’
   31 |                 return ng.size()+no+ps.size();
      |                           ^~~~
answer.code:31:37: error: ‘ps’ was not declared in this scope; did you mean ‘s’?
   31 |                 return ng.size()+no+ps.size();
      |                                     ^~
      |                                     s
answer.code: In function ‘int main()’:
answer.code:55:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   55 |     scanf("%d",&T);
      |     ~~~~~^~~~~~~~~
answer.code:57:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   57 |         scanf("%d",&n);scanf("%s",s+1);cnt=0;
      |         ~~~~~^~~~~~~~~
answer.code:57:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   57 |         scanf("%d",&n);scanf("%s",s+1);cnt=0;
      |                        ~~~~~^~~~~~~~~~
answer.code:59:31: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   59 |         for(i=2;i<=n;i++)scanf("%d",&x),Add(x,i);DFS(1);
      |                          ~~~~~^~~~~~~~~