# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
754609 |
2023-06-08T06:57:06 Z |
GrindMachine |
ICC (CEOI16_icc) |
C++17 |
|
170 ms |
624 KB |
// Om Namah Shivaya
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define sz(a) a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x, y) ((x + y - 1) / (y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rep1(i, n) for(int i = 1; i <= n; ++i)
#define rev(i, s, e) for(int i = s; i >= e; --i)
#define trav(i, a) for(auto &i : a)
template<typename T>
void amin(T &a, T b) {
a = min(a, b);
}
template<typename T>
void amax(T &a, T b) {
a = max(a, b);
}
#ifdef LOCAL
#include "debug.h"
#else
#define debug(x) 42
#endif
/*
*/
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;
#include "icc.h"
struct DSU {
vector<int> par, rankk, siz;
DSU() {
}
DSU(int n) {
init(n);
}
void init(int n) {
par = vector<int>(n + 1);
rankk = vector<int>(n + 1);
siz = vector<int>(n + 1);
rep(i, n + 1) create(i);
}
void create(int u) {
par[u] = u;
rankk[u] = 0;
siz[u] = 1;
}
int find(int u) {
if (u == par[u]) return u;
else return par[u] = find(par[u]);
}
bool same(int u, int v) {
return find(u) == find(v);
}
void merge(int u, int v) {
u = find(u), v = find(v);
if (u == v) return;
if (rankk[u] == rankk[v]) rankk[u]++;
if (rankk[u] < rankk[v]) swap(u, v);
par[v] = u;
siz[u] += siz[v];
}
};
int my_query(vector<int> a, vector<int> b){
int s1 = sz(a), s2 = sz(b);
int a2[s1], b2[s2];
rep(i,s1) a2[i] = a[i];
rep(i,s2) b2[i] = b[i];
return query(s1,s2,a2,b2);
}
void run(int n){
DSU dsu(n);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<int> dist(1,2);
rep1(iter,n-1){
vector<int> roots;
vector<int> guys[n+5];
rep1(i,n){
int p = dsu.find(i);
guys[p].pb(i);
if(p == i){
roots.pb(i);
}
}
while(true){
vector<int> v1, v2;
trav(r,roots){
int t = dist(rng);
if(t == 1){
trav(u,guys[r]){
v1.pb(u);
}
}
else{
trav(u,guys[r]){
v2.pb(u);
}
}
}
int res = my_query(v1,v2);
if(!res) conts;
// fix right, b.s left
int l = 0, r = sz(v1) - 1;
int u = -1;
while(l <= r){
int mid = (l+r) >> 1;
vector<int> v1_new, v2_new;
rep(i,mid+1) v1_new.pb(v1[i]);
v2_new = v2;
int ok = my_query(v1_new, v2_new);
if(ok){
u = v1[mid];
r = mid - 1;
}
else{
l = mid + 1;
}
}
// fix left, b.s right
l = 0, r = sz(v2) - 1;
int v = -1;
while(l <= r){
int mid = (l+r) >> 1;
vector<int> v1_new, v2_new;
v1_new = v1;
rep(i,mid+1) v2_new.pb(v2[i]);
int ok = my_query(v1_new, v2_new);
if(ok){
v = v2[mid];
r = mid - 1;
}
else{
l = mid + 1;
}
}
assert(u != -1);
assert(v != -1);
setRoad(u,v);
dsu.merge(u,v);
break;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
468 KB |
Ok! 116 queries used. |
2 |
Correct |
5 ms |
500 KB |
Ok! 112 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
500 KB |
Ok! 562 queries used. |
2 |
Correct |
46 ms |
496 KB |
Ok! 857 queries used. |
3 |
Correct |
42 ms |
504 KB |
Ok! 809 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
116 ms |
624 KB |
Ok! 1555 queries used. |
2 |
Correct |
170 ms |
504 KB |
Ok! 2185 queries used. |
3 |
Correct |
119 ms |
468 KB |
Ok! 1697 queries used. |
4 |
Correct |
133 ms |
508 KB |
Ok! 1748 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
126 ms |
508 KB |
Ok! 1720 queries used. |
2 |
Correct |
124 ms |
496 KB |
Ok! 1746 queries used. |
3 |
Correct |
136 ms |
504 KB |
Ok! 1888 queries used. |
4 |
Correct |
121 ms |
504 KB |
Ok! 1645 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
143 ms |
492 KB |
Too many queries! 1917 out of 1775 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
143 ms |
500 KB |
Too many queries! 1898 out of 1625 |
2 |
Halted |
0 ms |
0 KB |
- |