QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#142644#6404. Shuttle TourSchi2oidCompile Error//C++142.6kb2023-08-19 16:14:172023-08-19 16:14:19

Judging History

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

  • [2023-08-19 16:14:19]
  • 评测
  • [2023-08-19 16:14:17]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)
#define mid ((l+r)>>1)
#define cle node(1000000000,0,0)
#define ncle node(loc[l],loc[l],1)
const int N=200005;
int loc[N],fa[N],val[N],cid[N],top[N],len[55],tot=0,ccnt=1;
long long dep[N];
char s[N];
vector<int>c[55];
vector<int>ce[55];
struct edg{
	int v,w;
};
vector<edg>e[N];
struct node{
	int mn,mx,cnt;
	node(int MN=1000000000,int MX=0,int CNT=0){
		mn=MN,mx=MX,cnt=CNT;
	}
}t[4*N][55],ret[55];
void mg(node &x,node y){
	x.mn=min(x.mn,y.mn);
	x.mx=max(x.mx,y.mx);
	x.cnt+=y.cnt;
}
void push_up(int p){
	for(int i=1;i<=ccnt;i++){
		t[p][i]=t[ls(p)][i];
		mg(t[p][i],t[rs(p)][i]);
	}
}
void bd(int p,int l,int r){
	if(l==r){
		t[p][cid[l]]=(s[l]=='0')?cle:ncle;
		return;
	}
	bd(ls(p),l,mid);
	bd(rs(p),mid+1,r);
	push_up(p);
}
void md(int p,int l,int r,int x){
	if(l==r){ 
		t[p][cid[x]]=(t[p][cid[x]].cnt)?cle:ncle;
		return;
	}
	if(x<=mid) md(ls(p),l,mid,x);
	else md(rs(p),mid+1,r,x);
	push_up(p);
}
void qr(int p,int l,int r,int ql,int qr){
	if(l>=ql&&r<=qr){
		for(int i=1;i<=ccnt;i++) mg(ret[i],t[p][i]);
		return;
	}
	if(ql<=mid) qr(ls(p),l,mid,ql,qr);
	if(qr>mid) qr(rs(p),mid+1,r,ql,qr);
}
void dfs(int x,int f,int w,int tp){
	fa[x]=f,val[x]=w;
	cid[x]=cid[tp];
	loc[x]=++len[cid[tp]];
	c[cid[tp]].push_back(x);
	dep[x]=dep[f]+w;
	int ok=0;
	for(int i=0;i<e[x].size();i++){
		int v=e[x][i].v,w=e[x][i].w;
		if(v==f) continue;
		if(!ok) ok=1,dfs(v,x,w,tp);
		else{
			cid[v]=++ccnt;
			top[ccnt]=v;
			dfs(v,x,w,v);
		}
	}
}
long long cdfs(int x){
	int l=ret[x].mn,r=ret[x].mx;
	long long ans=0;
	for(int i=0;i<ce[x].size();i++){
		int v=ce[x][i];
		ans+=cdfs(v);
		int p=loc[c[v][0]];
		if(ret[v].cnt){
			l=min(l,p);
			r=max(r,p);
		}
		ret[x].cnt+=ret[v].cnt;
	}
	if(ret[x].cnt!=tot) l=0;
	return ans+dep[c[x][r]]-dep[c[x][l]];
}
int main(){
	int n,q,u,v,w;
	cin>>n>>q;
	for(int i=1;i<=50;i++) c[i].push_back(0);
	scanf("%s",s+1);
	for(int i=1;i<n;i++){
		scanf("%d%d%d",&u,&v,&w);
		e[u].push_back((edg){v,w});
		e[v].push_back((edg){u,w});
	}
	cid[1]=top[1]=1;
	dfs(1,0,0,1);
	for(int i=1;i<=ccnt;i++) c[i][0]=fa[top[i]];
	for(int i=2;i<=ccnt;i++) ce[cid[fa[top[i]]]].push_back(i);
	bd(1,1,n);
	for(int i=1;i<=q;i++){
		scanf("%d",&w);
		if(w==1){
			scanf("%d",&u);
			md(1,1,n,u);
		}
		else{
			scanf("%d%d",&u,&v);
			for(int j=1;j<=ccnt;j++) ret[j]=cle;
			qr(1,1,n,u,v);
			tot=0;
			for(int j=1;j<=ccnt;j++) tot+=ret[j].cnt;
			if(!tot) puts("-1");
			else printf("%lld\n",2ll*cdfs(1));
		}
	}
	return 0;
}

Details

answer.code: In function ‘void qr(int, int, int, int, int)’:
answer.code:58:23: error: ‘qr’ cannot be used as a function
   58 |         if(ql<=mid) qr(ls(p),l,mid,ql,qr);
      |                     ~~^~~~~~~~~~~~~~~~~~~
answer.code:59:22: error: ‘qr’ cannot be used as a function
   59 |         if(qr>mid) qr(rs(p),mid+1,r,ql,qr);
      |                    ~~^~~~~~~~~~~~~~~~~~~~~
answer.code: In function ‘int main()’:
answer.code:99:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   99 |         scanf("%s",s+1);
      |         ~~~~~^~~~~~~~~~
answer.code:101:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  101 |                 scanf("%d%d%d",&u,&v,&w);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~
answer.code:111:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  111 |                 scanf("%d",&w);
      |                 ~~~~~^~~~~~~~~
answer.code:113:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  113 |                         scanf("%d",&u);
      |                         ~~~~~^~~~~~~~~
answer.code:117:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  117 |                         scanf("%d%d",&u,&v);
      |                         ~~~~~^~~~~~~~~~~~~~