QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#343585#8055. Balanceucup-team191#WA 95ms20224kbC++233.0kb2024-03-02 19:46:232024-03-02 19:46:23

Judging History

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

  • [2024-03-02 19:46:23]
  • 评测
  • 测评结果:WA
  • 用时:95ms
  • 内存:20224kb
  • [2024-03-02 19:46:23]
  • 提交

answer

#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <vector>
#include <algorithm>

#define X first
#define Y second
#define PB push_back

using namespace std;

typedef pair < int, int > pii;

const int N = 1e5 + 500;

vector < pii > v[N];
vector < int > t[N];
int n, m, dep[N], up[N], L[N], R[N], tme, brid[N], siz[N], par[N], a[N];
vector < int > dobar[N], saz;
set < int > mogu[N];
map < int, int > rek[N];

void span(int x, int lst) {
	up[x] = dep[x]; L[x] = tme++;
	siz[x] = 1;
	for(auto &[y, ind] : v[x]) {
		if(ind == lst) continue;
		if(dep[y] != -1) {
			up[x] = min(up[x], dep[y]);
		} else {
			dep[y] = dep[x] + 1;
			t[x].PB(y); par[y] = x;
			span(y, ind);
			siz[x] += siz[y];
		}
	}
	R[x] = tme - 1;
}

int odredi(int x) {
	int naj = up[x];
	for(int y : t[x]) {
		naj = min(naj, odredi(y));
	}
	if(naj >= dep[x]) {
		brid[x] = 1;
	}
	return naj;
}

int cnt[N], sol[N];

int sijece(int l, int r, set < int > &S) {
	if(l > r) {
		int L = sijece(0, r, S);
		if(L != -1) return L;
		return sijece(l, n - 1, S);
	}
	if(S.lower_bound(l) != S.upper_bound(r)) {
		return *S.lower_bound(l);
	}
	return -1;
}

int fin[2 * N];

void solve() {
	scanf("%d%d", &n, &m);
	saz.clear(); tme = 0;
	for(int i = 0;i <= n;i++) {
		v[i].clear(), t[i].clear(), dep[i] = -1, up[i] = N;
		dobar[i].clear(); brid[i] = 0; mogu[i].clear(); rek[i].clear();
		cnt[i] = 0;
	}
	for(int i = 0;i <= 2 * n;i++) fin[i] = 0;
	for(int i = 0;i < m;i++) {
		int x, y; scanf("%d%d", &x, &y);
		v[x].PB({y, i});
		v[y].PB({x, i});
	}
	dep[1] = 0;
	span(1, -1);
	odredi(1);
	dobar[n].PB(0);
	for(int i = 2;i <= n;i++) {
		if(brid[i]) {
			dobar[siz[i]].PB(L[i]);
			dobar[n - siz[i]].PB((R[par[i]] + 1) % n);
		}
	}
	for(int i = 0;i < n;i++) {
		scanf("%d", a + i); saz.PB(a[i]);
	}
	sort(saz.begin(), saz.end());
	saz.erase(unique(saz.begin(), saz.end()), saz.end());
	for(int i = 0;i < n;i++) {
		cnt[lower_bound(saz.begin(), saz.end(), a[i]) - saz.begin()]++;
	}
	int k = (int)saz.size();
	for(int i = 1;i < k;i++) cnt[i] += cnt[i - 1];
	for(int x : dobar[cnt[0]]) mogu[0].insert(x);
	if(k == 1) {
		printf("Yes\n");
		for(int i = 1;i <= n;i++)
			printf("%d ", saz[0]);
		printf("\n");
		return;
	}
	for(int i = 1;i + 1 < k;i++) {
		for(int x : dobar[cnt[i]]) {
			int ret = sijece(x, (x + (cnt[i] - cnt[i - 1]) % n), mogu[i - 1]);
			if(ret != -1) {
				rek[i][x] = ret; mogu[i].insert(x);
			}
		}
	}
	if(mogu[k - 2].empty()) {
		printf("No\n");
		return;
	}
	int sad = *mogu[k - 2].begin();
	for(int i = k - 2;i >= 0;i--) {
		fin[sad]++;
		fin[sad + cnt[i]]--;
		sad = rek[i][sad];
	}
	for(int i = 1;i < 2 * n;i++) fin[i] += fin[i - 1];
	for(int i = 1;i <= n;i++) {
		sol[i] = saz[k - fin[L[i]] - fin[L[i] + n] - 1];
	}
	printf("Yes\n");
	for(int i = 1;i <= n;i++)
		printf("%d ", sol[i]);
	printf("\n");
}

int main() {
	int T; scanf("%d", &T);
	for(;T--;) solve();
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 5ms
memory: 20224kb

input:

5
5 4
1 2
2 3
3 4
4 5
1 2 3 4 5
5 4
1 2
1 3
1 4
1 5
1 2 3 4 5
5 4
1 2
1 3
1 4
1 5
1 2 2 2 3
5 6
1 2
1 2
2 3
3 4
4 5
3 5
1 2 1 2 1
2 2
1 2
1 2
1 2

output:

Yes
1 2 3 4 5 
No
Yes
2 1 2 2 3 
Yes
2 2 1 1 1 
No

result:

ok ok (5 test cases)

Test #2:

score: -100
Wrong Answer
time: 95ms
memory: 20216kb

input:

100000
4 3
4 2
1 3
2 1
2 1 3 2
5 7
2 5
5 3
2 3
5 1
4 3
2 4
4 3
1 3 1 1 2
3 2
2 1
2 3
1 1 1
4 7
3 4
1 4
2 3
4 3
4 2
3 1
4 3
2 3 3 2
4 6
2 4
3 1
1 2
1 2
2 3
4 2
1 1 3 3
4 7
3 2
4 2
1 2
3 4
3 2
2 4
3 4
2 1 1 1
5 5
3 2
1 5
4 5
4 3
2 1
1 2 2 3 2
3 5
2 3
1 3
3 1
3 1
2 1
3 2 3
2 3
2 1
2 1
1 2
1 1
2 3
2 1
1...

output:

Yes
2 2 1 3 
No
Yes
1 1 1 
No
No
Yes
2 1 1 1 
No
No
Yes
1 1 
Yes
1 1 
Yes
1 1 
Yes
1 1 1 1 
No
Yes
1 1 1 1 1 
Yes
1 1 3 1 1 
Yes
1 1 1 
Yes
1 2 
Yes
1 1 1 1 1 
Yes
1 2 
No
Yes
1 1 
Yes
1 1 1 
Yes
1 1 
Yes
1 1 1 1 
Yes
1 1 
Yes
2 2 2 2 2 
Yes
1 1 1 1 1 
Yes
1 1 
Yes
1 2 1 1 
No
Yes
1 1 
No
Yes
1 1 
N...

result:

wrong answer max - min = 2, but sum of difference = 6 (test case 15)