QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#803402#9862. Antivirusucup-team3510#Compile Error//C++983.9kb2024-12-07 17:05:502024-12-07 17:05:57

Judging History

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

  • [2024-12-07 17:05:57]
  • 评测
  • [2024-12-07 17:05:50]
  • 提交

answer

#include<iostream>
#include<vector>
#include<cstring>
using namespace std;

struct E {
	int v, x;
} e[600010];
int h[3][100010];
int dfc, tot, n, m;
int fa[100010], fth[100010], pos[100010], mn[100010], idm[100010], sdm[100010], dfn[100010];

void add(int x, int u, int v) {
	e[++tot] = {v, h[x][u]};
	h[x][u] = tot;
}

void dfs(int u) {
	dfn[u] = ++dfc;
	pos[dfc] = u;
	for (int i = h[0][u]; i; i = e[i].x) {
		int v = e[i].v;
		if (!dfn[v]) {
			dfs(v);
			fth[v] = u;
		}
	}
}

int find(int x) {
	if (fa[x] == x) {
		return x;
	}
	int tmp = fa[x];
	fa[x] = find(fa[x]);
	if (dfn[sdm[mn[tmp]]] < dfn[sdm[mn[x]]]) {
		mn[x] = mn[tmp];
	}
	return fa[x];
}

void tar(int st) {
	dfs(st);
	for (int i = 1; i <= n; ++i) {
		fa[i] = sdm[i] = mn[i] = i;
	}
	for (int i = dfc; i >= 2; --i) {
		int u = pos[i], res = 1e9;
		for (int j = h[1][u]; j; j = e[j].x) {
			int v = e[j].v;
			if (!dfn[v]) {
				continue;
			}
			find(v);
			if (dfn[v] < dfn[u]) {
				res = std::min(res, dfn[v]);
			} else {
				res = std::min(res, dfn[sdm[mn[v]]]);
			}
		}
		sdm[u] = pos[res];
		fa[u] = fth[u];
		add(2, sdm[u], u);
		u = fth[u];
		for (int j = h[2][u]; j; j = e[j].x) {
			int v = e[j].v;
			find(v);
			if (sdm[mn[v]] == u) {
				idm[v] = u;
			} else {
				idm[v] = mn[v];
			}
		}
		h[2][u] = 0;
	}
	for (int i = 2; i <= dfc; ++i) {
		int u = pos[i];
		if (idm[u] != sdm[u]) {
			idm[u] = idm[idm[u]];
		}
	}
}

int T,q,c[100010];
struct tree
{
	int minc;
	long long f,add,minn;
};
tree a[400000];
inline void add(int p,long long v)
{
	a[p].add+=v;
	a[p].minn+=v;
	a[p].f+=v;
}
inline void Min(int p,long long v)
{
	a[p].minn=min(a[p].minn,v);
	a[p].f=min(a[p].f,v+a[p].minc);
}
inline void pushdown(int p)
{
	if(a[p].add)
	{
		add(p<<1,a[p].add);
		add((p<<1)|1,a[p].add);
		a[p].add=0;
	}
	if(a[p].minn<1e18)
	{
		Min(p<<1,a[p].minn);
		Min((p<<1)|1,a[p].minn);
		a[p].minn=1e18;
	}
}
inline void update(int p)
{
	a[p].f=min(a[p<<1].f,a[(p<<1)|1].f);
}
void add(int l,int r,int ll,int rr,int v,int p)
{
	if(r<ll||l>rr)
	{
		return;
	}
	if(ll<=l&&r<=rr)
	{
		add(p,v);
		return;
	}
	int mid=l+r>>1;
	pushdown(p);
	add(l,mid,ll,rr,v,p<<1);
	add(mid+1,r,ll,rr,v,(p<<1)+1);
	update(p);
}
vector<int> E[100010];
int size[100010],d[100010],son[100010];
void dfs1(int now)
{
	size[now]=1,son[now]=0;
	for(int i=0,maxx=0;i<E[now].size();i++)
	{
		int t=E[now][i];
		d[t]=d[now]+1,fa[t]=now;
		dfs1(t),size[now]+=size[t];
		if(size[t]>maxx)
		{
			maxx=size[t];
			son[now]=t;
		}
	}
}
int top[100010],num,id[100010],ID[100010];
void dfs2(int now,int front)
{
	top[now]=front;
	ID[id[now]=++num]=now;
	if(son[now])
	{
		dfs2(son[now],front);
	}
	for(int i=0;i<E[now].size();i++)
	{
		int t=E[now][i];
		if(t==son[now])
		{
			continue;
		}
		dfs2(t,t);
	}
}
void build(int l,int r,int p)
{
	a[p].add=0,a[p].minn=1e18;
	if(l==r)
	{
		a[p].f=a[p].minc=c[ID[l]];
		return;
	}
	int mid=l+r>>1;
	build(l,mid,p<<1),build(mid+1,r,(p<<1)|1);
	a[p].f=a[p].minc=min(a[p<<1].minc,a[(p<<1)|1].minc);
}
inline void init()
{
	dfc=tot=num=0;
	memset(dfn,0,n+5<<2);
	for(int i=0;i<3;i++)
	{
		memset(h[i],0,n+5<<2);
	}
	for(int i=1;i<=n;i++)
	{
		E[i].clear();
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>T;
	while(T--)
	{
		cin>>n>>m>>q;
		init();
		for(int i=1,x,y;i<=m;i++)
		{
			cin>>x>>y;
			add(0,y,x);
			add(1,x,y);
		}
		for(int i=1;i<=n;i++)
		{
			cin>>c[i];
		}
		tar(1);
		for(int i=2;i<=n;i++)
		{
			E[idm[i]].emplace_back(i);
		}
		fa[1]=num=0;
		dfs1(1),dfs2(1,1);
		build(0,n,1);
		long long sum=0;
		for(int i=1,x,y;i<=q;i++)
		{
			cin>>x>>y;
			sum+=y;
			while(x)
			{
				add(0,n,id[top[x]],id[x],-y,1);
				x=fa[top[x]];
			}
			cout<<sum+a[1].f<<" ";
			Min(1,a[1].f);
		}
		cout<<endl;
	}
	return 0;
}

Details

answer.code: In function ‘void add(int, int, int)’:
answer.code:14:31: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions]
   14 |         e[++tot] = {v, h[x][u]};
      |                               ^
answer.code:14:31: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions]
answer.code: In function ‘int main()’:
answer.code:221:35: error: ‘class std::vector<int>’ has no member named ‘emplace_back’
  221 |                         E[idm[i]].emplace_back(i);
      |                                   ^~~~~~~~~~~~