harvey_wzy's blog

By harvey_wzy, history, 3 months ago, In English

and sand when I am 6

and toys when I am 7

and TV when I am 8

and video games when I am 9

and programming on Codeforces and Atcoder when I am 10 and 11 (now)

Full text and comments »

  • Vote: I like it
  • +86
  • Vote: I do not like it

By harvey_wzy, history, 16 months ago, In English

Problem: ABC188E

#include <bits/stdc++.h>
using namespace std;

int a[200005], f[200005];
vector<int> pre[200005];

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	for (int i = 0; i < m; i++) {
		int x, y;
		scanf("%d %d", &x, &y);
		x--, y--;
		pre[y].push_back(x);
	}
	memset(f, 0x3f, sizeof f);
	int ans = -0x3f3f3f3f;
	for (int i = 0; i < n; i++) {
		for (int j : pre[i]) {
			f[i] = min(f[i], f[j]);
			f[i] = min(f[i], a[j]);
		}
		ans = max(ans, a[i] - f[i]);
	}
	printf("%d", ans);
	return 0;
}

I had increase the "infinity" in array f, and I found that when f[i] = 0x3f3f3f3f + 0x3f3f2f2f, it passed , when f[i] = 0x3f3f3f3f + 0x2f2f2f2f, it WA on test #6. I had no idea about it. Could anyone give a test to hack it?

Full text and comments »

  • Vote: I like it
  • +2
  • Vote: I do not like it

By harvey_wzy, history, 17 months ago, In English

Today, I find some topics in this form......

This type of topics always say a lot of things of ******, and at last post a drawing of him/her.

So who started this type of topics???

Full text and comments »

  • Vote: I like it
  • -22
  • Vote: I do not like it

By harvey_wzy, history, 17 months ago, In English

So this is my code to ABC279F:

#include <bits/stdc++.h>
using namespace std;

int fa[600005];

void init() {
	memset(fa, -1, sizeof fa);
}

int find_root(int x) {
	if (fa[x] == -1) {
		return x;
	}
	return fa[x] = find_root(fa[x]);
}

void unite(int x, int y) {
	if (find_root(x) != find_root(y) && find_root(x) != -1) {
		fa[find_root(x)] = find_root(y);
	}
}

int now[300005], idx[300005], past[600005];

int main() {
	init();
	int n, q;
	scanf("%d %d", &n, &q);
	for (int i = 0; i < n; i++) {
		now[i] = i;
		past[i] = i;
		idx[i] = i;
	}
	int cntn = n - 1;
	int cnt = n - 1;
	while (q--) {
		int tp;
		scanf("%d", &tp);
		if (tp == 1) {
			int x, y;
			scanf("%d %d", &x, &y);
			x--, y--;
			unite(now[y], now[x]);
			now[y] = ++cntn;
			past[cntn] = y;
		} else if (tp == 2) {
			int x;
			scanf("%d", &x);
			x--;
			idx[++cnt] = now[x];
		} else {
			int x;
			scanf("%d", &x);
			x--;
			printf("%d\n", past[find_root(idx[x])] + 1);
		}
//		for (int i = 0; i < n; i++) {
//			cerr << now[i] << " ";
//		}
//		cerr << endl;
	}
	return 0;
}

It should be RE (Though the size of "idx" is 300005), but it judged as WA.

Why?

And it wasted me a lot of time :(

Full text and comments »

  • Vote: I like it
  • -4
  • Vote: I do not like it