QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#460181#5531. ICCfryan100 ✓77ms4156kbC++202.9kb2024-07-01 04:48:292024-07-01 04:48:29

Judging History

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

  • [2024-07-01 04:48:29]
  • 评测
  • 测评结果:100
  • 用时:77ms
  • 内存:4156kb
  • [2024-07-01 04:48:29]
  • 提交

answer

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include "icc.h"
using namespace std;
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()

struct dsu {
	int n;
	vector<int> r;
	dsu() {}
	dsu(int n) : n(n) {
		r.resize(n);
		fill(r.begin(),r.end(),-1);
	}
	int trace(int v) {
		return (r[v] < 0 ? v : r[v] = trace(r[v]));
	}
	int size(int v) {
		return -r[trace(v)];
	}
	int same_set(int u, int v) {
		return (trace(u) == trace(v));
	}
	int unite(int u, int v) {
		if ((u = trace(u)) == (v = trace(v))) {
			return u;
		}
		if (-r[u] < -r[v]) swap(u,v);
		r[u] += r[v];
		r[v] = u;
		return u;
	}
};

vector<int> gen(int cyc, int len) {
	vector<int> res; res.resize(len);
	for (int b = 0; b < len; b += cyc) {
		for (int i = b; i < min(len, b+cyc); i++) {
			res[i] = (b/cyc)%2;
		}
	}
	return res;
}

const int mxn = 1e2;
int aux1[mxn], aux2[mxn];

/*
int query(int la, int lb, int a[], int b[]) {
	cout << "querying:\n";
	for (int i = 0; i < la; i++) cout << a[i] << " ";
	cout << "\n";
	for (int i = 0; i < lb; i++) cout << b[i] << " ";
	cout << "\n? - ";
	int ans; cin >> ans;
	return ans;
}
*/

int send_query(vector<int> &a, vector<int> &b) {
	for (int i = 0; i < sz(a); i++) {
		aux1[i] = a[i]+1;
	}
	for (int i = 0; i < sz(b); i++) {
		aux2[i] = b[i]+1;
	}
	return query(sz(a), sz(b), aux1, aux2);
}

array<int,2> get_edge(vector<int> &a, vector<int> &b) {
	if (sz(a) == 1 && sz(b) == 1) {
		return {a[0], b[0]};
	}
	if (sz(a) < sz(b)) swap(a,b);
	vector<int> a1, a2;
	for (int i = 0; i < sz(a); i++) {
		if (i%2 == 0) a1.push_back(a[i]);
		else a2.push_back(a[i]);
	}
	if (send_query(a1, b)) {
		return get_edge(a1,b);
	}
	return get_edge(a2,b);
}

void send_answer(int a, int b) {
//	cout << "road: " << a << " " << b << "\n";
	setRoad(a+1,b+1);
}

void run(int n) {
	dsu ds(n);
	for (int i = 1; i < n; i++) {
		vector<int> cn;
		for (int j = 0; j < n; j++) {
			if (ds.trace(j) == j) {
				cn.push_back(j);
			}
		}
		for (int c = 1; c < 1e9; c *= 2) {
			vector<int> mask = gen(c, sz(cn));
	//		for (auto i : mask) cout << i << " ";
	//		cout << "\n";
			vector<int> a,b;
			for (int i = 0; i < n; i++) {
				int rep = lower_bound(all(cn), ds.trace(i)) - cn.begin();
				if (mask[rep]) {a.push_back(i);}
				else {b.push_back(i);}
			}
			if (send_query(a,b)) {
				array<int,2> e = get_edge(a,b);
				send_answer(e[0], e[1]);
				ds.unite(e[0], e[1]);
				break;
			}
		}
		
	}
}

/*
signed main() {
	run(5);
	return 0;
}
*/

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 7
Accepted

Test #1:

score: 7
Accepted
time: 4ms
memory: 3996kb

input:

1
1500 3
15

0
2

0.0
2.5

0
3.5

0

1 1

output:

3
Ok! 96 queries used.

result:

ok 

Test #2:

score: 7
Accepted
time: 4ms
memory: 4016kb

input:

1
1500 4
15

0
0

0.0
3.5

0
2.5

5

1 1

output:

4
Ok! 97 queries used.

result:

ok 

Subtask #2:

score: 11
Accepted

Test #3:

score: 11
Accepted
time: 19ms
memory: 4036kb

input:

1
2500 4
50

0
0

0.0
3.5

0
2.5

5

1 1

output:

4
Ok! 528 queries used.

result:

ok 

Test #4:

score: 11
Accepted
time: 23ms
memory: 4048kb

input:

1
2500 4
50

0
1.3

0.0
0.7

0
3.5

15

2 1

output:

4
Ok! 643 queries used.

result:

ok 

Test #5:

score: 11
Accepted
time: 23ms
memory: 4108kb

input:

1
2500 3
50

0.05
2.3

0.1
0.7

0
1.5

1.7

2 1

output:

3
Ok! 627 queries used.

result:

ok 

Subtask #3:

score: 22
Accepted

Test #6:

score: 22
Accepted
time: 66ms
memory: 4028kb

input:

1
2250 6
100

0.05
2.3

0.1
0.7

0
1.5

1.7

1.1 1

output:

6
Ok! 1398 queries used.

result:

ok 

Test #7:

score: 22
Accepted
time: 70ms
memory: 4064kb

input:

1
2250 6
100

0.05
1.5

0.1
1.3

0.01
1.7

0

100 1

output:

6
Ok! 1597 queries used.

result:

ok 

Test #8:

score: 22
Accepted
time: 72ms
memory: 4096kb

input:

1
2250 5
100

0.00
2.00

0.00
1.70

0.10
1.30

5

1.15 1

output:

5
Ok! 1492 queries used.

result:

ok 

Test #9:

score: 22
Accepted
time: 71ms
memory: 3940kb

input:

1
2250 5
100

0.00
1.00

0.00
2.30

0.00
0.70

0

1.1 1

output:

5
Ok! 1524 queries used.

result:

ok 

Subtask #4:

score: 21
Accepted

Test #10:

score: 21
Accepted
time: 71ms
memory: 4044kb

input:

1
2000 5
100

0.01
1.00

0.10
1.70

0.00
1.50

5.0

1.20 1

output:

5
Ok! 1488 queries used.

result:

ok 

Test #11:

score: 21
Accepted
time: 69ms
memory: 4008kb

input:

1
2000 5
100

0.00
0.70

0.00
2.10

0.00
1.20

0.0

1.5 1

output:

5
Ok! 1514 queries used.

result:

ok 

Test #12:

score: 21
Accepted
time: 69ms
memory: 3992kb

input:

1
2000 6
100

0.01
0.70

0.00
2.70

0.00
1.90

3.5

1.1 1

output:

6
Ok! 1492 queries used.

result:

ok 

Test #13:

score: 21
Accepted
time: 71ms
memory: 4052kb

input:

1
2000 5
100

0.01
1.00

0.10
1.70

0.01
2.30

5.0

1.20 1

output:

5
Ok! 1466 queries used.

result:

ok 

Subtask #5:

score: 29
Accepted

Test #14:

score: 29
Accepted
time: 70ms
memory: 4152kb

input:

1
1775 4
100

0.00
0.00

0.00
2.70

0.10
7.55

0.0

1.15 1

output:

4
Ok! 1497 queries used.

result:

ok 

Test #15:

score: 29
Accepted
time: 70ms
memory: 4004kb

input:

1
1775 5
100

0.00
1.50

0.00
1.10

0.00
1.75

0.0

1.5 1

output:

5
Ok! 1554 queries used.

result:

ok 

Test #16:

score: 29
Accepted
time: 69ms
memory: 4012kb

input:

1
1775 5
100

0.01
1.50

0.00
1.10

0.01
1.75

0.0

1.3 1

output:

5
Ok! 1532 queries used.

result:

ok 

Test #17:

score: 29
Accepted
time: 68ms
memory: 4048kb

input:

1
1775 5
100

0.00
0.30

0.00
2.10

0.00
1.75

0.0

1.5 1

output:

5
Ok! 1519 queries used.

result:

ok 

Test #18:

score: 29
Accepted
time: 77ms
memory: 4156kb

input:

1
1775 5
100

0.01
0.70

0.00
2.70

0.00
1.90

3.5

1.5 1

output:

5
Ok! 1632 queries used.

result:

ok 

Test #19:

score: 29
Accepted
time: 69ms
memory: 4116kb

input:

1
1775 5
100

0.01
1.50

0.00
1.10

0.01
1.75

1.0

1.10 1

output:

5
Ok! 1457 queries used.

result:

ok 

Subtask #6:

score: 10
Accepted

Test #20:

score: 10
Accepted
time: 67ms
memory: 3972kb

input:

1
1625 5
100

0.00
0.00

0.00
3.00

0.00
1.00

0.0

3 1

output:

5
Ok! 1498 queries used.

result:

ok 

Test #21:

score: 10
Accepted
time: 68ms
memory: 4068kb

input:

1
1625 5
100

0.00
0.90

0.00
2.70

0.10
1.55

0.0

1.55 1

output:

5
Ok! 1514 queries used.

result:

ok