QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#590249#7181. Graph CutsTomorrowTL 19ms4476kbC++173.2kb2024-09-25 22:55:042024-09-25 22:55:04

Judging History

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

  • [2024-09-25 22:55:04]
  • 评测
  • 测评结果:TL
  • 用时:19ms
  • 内存:4476kb
  • [2024-09-25 22:55:04]
  • 提交

answer

#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
#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::tr1::hash<PII> { size_t OP()(C PII& p)C{ return (((size_t)p.ft) << 32) | p.sd; } };
VD test()
{
	DR(I, n, m);++n; I sqm = sqrt(m);
	V<I> dg(n), ish(n), vh;
	cc_hash_table<PII, I> eg;
	V<cc_hash_table<I, null_type>> s(n), d(n);
	cc_hash_table<PII, null_type> 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), d[x].insert(p), lde.insert(make(p, x));
				FORX(d[p])d[x].erase(p), s[x].insert(p), lde.erase(make(p, x));
			}
			swap(s[p], d[p]);
			FORX(vh)
			{
				if (x == p)continue;
				if (s[x].find(p) != s[x].end())s[x].erase(p), d[x].insert(p);
				else if (d[x].find(p) != d[x].end())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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3844kb

input:

0 0
0

output:


result:

ok q=0

Test #3:

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

input:

0 0
1
?

output:

0

result:

ok q=1

Test #4:

score: 0
Accepted
time: 19ms
memory: 4476kb

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:

70
12
1
163
156
149
18
290
98
383
199
103
200
413
487
132
29
250
543
344
19
411
529
460
110
496
405
415
104
331
145
353
588
548
453
682
647
618
318
677
589
716
549
63
439
82
270
157
623
262
247
248
603
704
686
720
613
571
426
263
303
210
186
572
811
705
735
651
284
506
880
378
658
659
118
42
291
122...

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: