QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#590223#7181. Graph CutsTomorrowTL 9ms4196kbC++173.2kb2024-09-25 22:38:502024-09-25 22:38:51

Judging History

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

  • [2024-09-25 22:38:51]
  • 评测
  • 测评结果:TL
  • 用时:9ms
  • 内存:4196kb
  • [2024-09-25 22:38:50]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define C const
#define U unsigned
#define SC static
#define CE constexpr
#define TL template
#define TN typename
#define OP operator
#define pb push_back
#define ft first
#define sd second
#define mi (l + (r - l) / 2)
#define TTT TL<TN T = I>
#define TTI TL<TN It>
#define BE(v) v.begin(), v.end()
#define VD void
#define BL bool
#define CH char
#define I int
#define LL long long
#define II __int128
#define D double
#define STR string
using PII = pair<I, I>;
TTT using V = vector<T>;

#define FORX(v) for(auto& x : v)
#define FOR(i, b, e)  for(auto i = b, _e = (decltype(i))e;i != _e; ++i)
#define FORR(i, b, e) for(auto i = b, _e = (decltype(i))e;i != _e; --i)
#define FORV(v, i) for (I i = 0, _n = v.size(), x = _n ? v[0] : 0;i < _n;x = v[++i])
#define FUNC(T, f, ...) function<T(__VA_ARGS__)> f = [&](__VA_ARGS__)->T

#define DR(T, ...) T __VA_ARGS__; R(__VA_ARGS__);
TTT VD R(T& x) { cin >> x; }
TTT T R() { DR(T, x); return x; }
TL<TN T, TN... A> VD R(T& x, A&... a) { R(x), R(a...); }
CE CH LF = '\n', SP = ' ';
TL<CH s = LF> VD W() { cout << s; }
TL<CH s = LF, TN T> VD W(C T& x) { cout << x << s; }
TL<CH s = LF, TN T, TN... A> VD W(C T& x, C A&... a) { W<SP>(x), W<s>(a...); }

TTT CE T inf() { return numeric_limits<T>::max() / 2; }
TTT VD setmin(T& a, C T& b) { if (b < a)a = b; }
TTT VD setmax(T& a, C T& b) { if (a < b)a = b; }

TL<> struct std::hash<PII>
{
	size_t OP()(C PII& p)C{return (size_t)p.ft << 32 | p.sd;}
};
VD test()
{
	hash<I>();
	DR(I, n, m);++n; I sqm = sqrt(m);
	V<I> dg(n), ish(n), vh;
	unordered_map<PII, I> eg;
	V<unordered_set<I>> s(n), d(n);
	unordered_set<PII> lde;

	FUNC(PII, make, I u, I v) { return u < v ? PII{ u, v } : PII{ v, u }; };
	FOR(i, 0, m)
	{
		DR(I, u, v);
		eg[make(u, v)] = i + 1;
		++dg[u], ++dg[v];
	}
	FOR(i, 1, n)if (dg[i] >= sqm)ish[i] = 1, vh.pb(i);
	FORX(eg)
	{
		I u = x.ft.ft, v = x.ft.sd;
		if (ish[u])s[u].insert(v);
		if (ish[v])s[v].insert(u);
		if (!ish[u] && !ish[v])s[u].insert(v), s[v].insert(u);
	}

	DR(I, q);
	while (q--)
	{
		DR(STR, op);
		if (op[0] != '?')
		{
			DR(I, p);
			if (!ish[p])
			{
				FORX(s[p])s[x].erase(p);
				FORX(d[p])d[x].erase(p);
				FORX(s[p])d[x].insert(p);
				FORX(d[p])s[x].insert(p);
				FORX(s[p])lde.insert(make(p, x));
				FORX(d[p])lde.erase(make(p, x));
			}
			swap(s[p], d[p]);
			FORX(vh)
			{
				if (x == p)continue;
				if (s[x].count(p))s[x].erase(p), d[x].insert(p);
				else if (d[x].count(p))d[x].erase(p), s[x].insert(p);
			}
		}
		else
		{
			I id = 0;
			if (lde.size())
			{
				auto it = lde.begin();
				id = eg[*it];
				I u = it->ft, v = it->sd;
				d[u].erase(v);
				d[v].erase(u);
				lde.erase(it);
			}
			else
			{
				FORX(vh)
				{
					if (d[x].empty())continue;
					I u = x, v = *d[x].begin();if (u > v)swap(u, v);
					if (ish[u])d[u].erase(v);
					if (ish[v])d[v].erase(u);
					id = eg[{u, v}];
					break;
				}
			}
			W(id);
		}
	}
}

I main()
{
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	if (fopen("test.in", "r"))
	{
		freopen("test.in", "r", stdin);
		freopen("test.out", "w", stdout);
	}
	I t = 1;
	// R(t);
	while (t--)test();
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3780kb

input:

4 5
1 2
1 3
1 4
2 3
2 4
10
+ 1
+ 2
?
?
?
?
?
- 2
?
?

output:

2
3
4
5
0
1
0

result:

ok q=10

Test #2:

score: 0
Accepted
time: 0ms
memory: 3592kb

input:

0 0
0

output:


result:

ok q=0

Test #3:

score: 0
Accepted
time: 1ms
memory: 3604kb

input:

0 0
1
?

output:

0

result:

ok q=1

Test #4:

score: 0
Accepted
time: 9ms
memory: 4196kb

input:

1000 2000
1 50
1 88
331 1
1 352
1 497
2 32
2 282
550 2
989 2
334 3
3 665
4 38
4 69
4 343
4 451
589 4
917 4
89 5
5 162
675 5
681 6
7 22
127 7
7 592
7 672
787 7
8 310
107 9
9 137
184 9
9 244
378 9
446 9
9 658
883 9
65 10
75 10
414 10
10 468
686 10
245 11
269 11
11 386
403 11
493 11
394 12
493 12
565 1...

output:

207
1958
1990
1285
1474
655
879
1917
1850
1287
847
1848
571
497
718
1741
376
1225
837
836
852
1183
1182
224
528
278
1421
615
1238
727
1144
895
754
743
1880
1529
1480
435
1560
972
1422
1561
254
1857
907
1702
1557
1556
853
1127
1593
1527
1228
1851
1783
1194
1695
667
1279
1267
1796
1075
1076
1993
1860
...

result:

ok q=100000

Test #5:

score: -100
Time Limit Exceeded

input:

447 99681
2 1
1 3
4 1
1 5
1 6
1 7
1 8
9 1
10 1
1 11
1 12
1 13
1 14
1 15
1 16
17 1
18 1
19 1
20 1
21 1
22 1
23 1
24 1
25 1
1 26
27 1
28 1
1 29
30 1
31 1
1 32
33 1
1 34
1 35
36 1
37 1
38 1
39 1
40 1
1 41
1 42
43 1
44 1
45 1
46 1
1 47
48 1
49 1
1 50
1 51
1 52
53 1
54 1
55 1
1 56
57 1
1 58
59 1
60 1
1 6...

output:


result: