QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#762279#7767. 数据结构hxhhxhCompile Error//C++204.3kb2024-11-19 14:24:572024-11-19 14:24:59

Judging History

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

  • [2024-11-19 14:24:59]
  • 评测
  • [2024-11-19 14:24:57]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define vpi basic_string<pii>
#define fi first
#define se second
using namespace std;
const int N=2e5+5;
struct SEG{
	struct st{
		int l,r;
		ll c,s,z;
	}a[N<<2];
	void bt(int x,int l,int r){
		a[x].l=l;
		a[x].r=r;
		a[x].c=a[x].s=a[x].z=0;
		if(l<r){
			bt(x<<1,l,(l+r>>1));
			bt(x<<1|1,(l+r>>1)+1,r);
		}
	}
	void ps(int x,ll v){
		a[x].s+=(a[x].r-a[x].l+1)*v;
		a[x].c+=v;
		a[x].z+=v;
	}
	void xf(int x){
		ps(x<<1,a[x].z);
		ps(x<<1|1,a[x].z);
		a[x].z=0;
	}
	void pu(int x){
		a[x].c=max(a[x<<1].c,a[x<<1|1].c);
		a[x].s=a[x<<1].s+a[x<<1|1].s;
	} 
	void add(int x,int l,int r,ll v){
		if(a[x].l==l&&a[x].r==r) return ps(x,v);
		if(a[x].z) xf(x);
		int mid=a[x].l+a[x].r>>1;
		if(r<=mid) add(x<<1,l,r,v);
		else if(l>mid) add(x<<1|1,l,r,v);
		else add(x<<1,l,mid,v),add(x<<1|1,mid+1,r,v);
		pu(x); 
	}
	ll qs(int x,int l,int r){
		if(a[x].l==l&&a[x].r==r) return a[x].s;
		if(a[x].z) xf(x);
		int mid=a[x].l+a[x].r>>1;
		if(r<=mid) return qs(x<<1,l,r);
		if(l>mid) return qs(x<<1|1,l,r);
		return qs(x<<1,l,mid)+qs(x<<1|1,mid+1,r);
	}
	ll qv(int x,int l,int r){
		if(a[x].l==l&&a[x].r==r) return a[x].c;
		if(a[x].z) xf(x);
		int mid=a[x].l+a[x].r>>1;
		if(r<=mid) return qv(x<<1,l,r);
		if(l>mid) return qv(x<<1|1,l,r);
		return max(qv(x<<1,l,mid),qv(x<<1|1,mid+1,r));
	}
}T;
int n,Q,K,fa[N],dfn[N],hs[N],siz[N],dcnt,dep[N],top[N];
vector<int>e[N],g[N];
vpi tk[N][4],lk[N][4],tr[N];
void dfs1(int x,int f){
	siz[x]=1;
	dep[x]=dep[f]+1;
	fa[x]=f;
	for(int i:e[x]){
		if(i==f) continue;
		dfs1(i,x);
		siz[x]+=siz[i];
		g[x].push_back(i);
	}
	for(int i:g[x]) if(siz[i]>siz[hs[x]]) hs[x]=i;
}
void lb(int x){
	if(!dfn[x]) dfn[x]=++dcnt;
}
void dfs2(int x,int ff){
	top[x]=ff;
	if(ff==x){
		vector<int>u;
		for(int t=x;t;t=hs[t]) u.push_back(t),lb(t);
		for(int i=1;i<=3;i++){
			vector<int>v;
			for(int j:u) for(int l:g[j]) if(top[j]!=x) v.push_back(l),lb(l);
			u=v;
		}
	}
	if(hs[x]) dfs2(hs[x],ff);
	for(int i:g[x]) if(i!=hs[x]) dfs2(i,i);
}
void zp(vpi&x){
	sort(x.begin(),x.end());
	vpi y;
	for(pii i:x){
		if(y.empty()||i.fi>y.back().se+1) y.push_back(i);
		else y.back().se=max(y.back().se,i.se);
	}
	x=y;
}
void add(vpi&x,const vpi&y){
	if(y.empty()) return;
	if(x.empty()) x=y;
	else{
		for(pii i:y) x.push_back(i);
		zp(x);
	}
}
void dfs3(int x){
	tr[x]=tk[x][0]={{dfn[x],dfn[x]}};
	for(int i:g[x]){
		dfs3(i);
		for(int j=0;j<K;j++) add(tk[x][j+1],tk[i][j]);
		add(tr[x],tr[i]);
	}
	for(int i=0;i<K;i++) add(tk[x][i+1],tk[x][i]);
}
void dfs4(int x){
	for(int i=0;i<=K;i++) lk[x][i]=tk[x][i];
	if(x>1) for(int i=0;i<K;i++) add(tk[x][i+1],tk[fa[x]][i]);
	if(top[x]!=x) for(int i=0;i<=K;i++) add(lk[x][i],lk[fa[x]][i]);
	for(int i:g[x]) dfs4(i);
}
int lca(int x,int y){
	while(top[x]!=top[y]){
		if(dep[top[x]]<dep[top[y]]) swap(x,y);
		x=fa[top[x]];
	}
	return dep[x]<dep[y]?x:y;
}
vpi del(vpi a,vpi b){
	vpi res;
	int l=0,r=-1,m=b.size();
	for(pii i:a){
		while(l<m&&b[l].se<i.fi) l++;
		while(r<m-1&&b[r+1].fi<=i.se) r++;
		if(l>r){
			res.push_back(i);
			continue;
		}
		if(i.fi<b[l].fi) res.push_back({i.fi,b[l].fi-1});
		for(int j=l+1;j<=r;j++) res.push_back({b[j-1].se+1,b[j].fi-1});
		if(i.se>b[r].se) res.push_back({b[r].se+1,i.se});
	}
	zp(res);
	return res;
}
vpi qw(int x,int k){
	if(!x) return {};
	vpi res=lk[x][k];
	add(res,qw(fa[top[x]],k));
	return res;
}
vpi ql(int x,int y,int k){
	int u=lca(x,y);
	vpi res=tk[u][k];
	vpi wx=qw(u,k);
	add(res,del(qw(x,k),wx));
	add(res,del(qw(y,k),wx));
	return res;
}
int main(){
//	freopen("T2/zyf8.in","r",stdin);
//	freopen("T2/zyf8.out","w",stdout);
	cin>>n>>Q;K=3;
	for(int i=1,j,k;i<n;i++){
		scanf("%d %d",&j,&k);
		e[j].push_back(k);
		e[k].push_back(j);
	}
	dfs1(1,0);
	dfs2(1,1);
	dfs3(1);
	dfs4(1);
	T.bt(1,1,n);
	for(int op,x,y,k,u;Q--;){
		vpi cw;
		scanf("%d",&op);
		if(op&1) scanf("%d %d %d",&x,&y,&k),cw=ql(x,y,k);
		else scanf("%d",&x),cw=tr[x];
		ll res=0;
		if(op<3){
			scanf("%d",&u);
			for(pii i:cw) T.add(1,i.fi,i.se,u);
		}
		else if(op>4){
			res=-1e15;
			for(pii i:cw) res=max(res,T.qv(1,i.fi,i.se));
		}
		else for(pii i:cw) res+=T.qs(1,i.fi,i.se);
		if(op>2) printf("%lld\n",res);
	}
	return 0;
}

Details

In file included from /usr/include/c++/13/bits/basic_string.h:47,
                 from /usr/include/c++/13/string:54,
                 from /usr/include/c++/13/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:52,
                 from answer.code:1:
/usr/include/c++/13/string_view: In instantiation of ‘class std::basic_string_view<std::pair<int, int>, std::char_traits<std::pair<int, int> > >’:
answer.code:102:4:   required from here
/usr/include/c++/13/string_view:109:21: error: static assertion failed
  109 |       static_assert(is_trivial_v<_CharT> && is_standard_layout_v<_CharT>);
      |                     ^~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/string_view:109:21: note: ‘std::is_trivial_v<std::pair<int, int> >’ evaluates to false
answer.code: In function ‘int main()’:
answer.code:170:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  170 |                 scanf("%d %d",&j,&k);
      |                 ~~~~~^~~~~~~~~~~~~~~
answer.code:181:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  181 |                 scanf("%d",&op);
      |                 ~~~~~^~~~~~~~~~
answer.code:182:31: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  182 |                 if(op&1) scanf("%d %d %d",&x,&y,&k),cw=ql(x,y,k);
      |                          ~~~~~^~~~~~~~~~~~~~~~~~~~~
answer.code:183:27: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  183 |                 else scanf("%d",&x),cw=tr[x];
      |                      ~~~~~^~~~~~~~~
answer.code:186:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  186 |                         scanf("%d",&u);
      |                         ~~~~~^~~~~~~~~