# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
295236 | Saboon | Highway Tolls (IOI18_highway) | C++17 | 378 ms | 8984 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 90000 + 10;
int n;
ll Cost = 0, Step;
vector<int> Q;
vector<int> g[maxn];
bool isOdd(ll Cost, ll Now, int sub){
if (sub <= 4){
ll T = abs(Now-Cost);
return (T/Step)&1;
}
if (sub == 5)
return (Now&1);
}
int find(vector<int> S, int sub){
assert((int)S.size() > 0);
int n = S.size();
int lo = -1, hi = n;
while (hi - lo > 1){
int mid = (lo+hi) >> 1;
for (int itV = 0; itV <= mid; itV++){
int v = S[itV];
for (auto idx : g[v])
Q[idx] ^= 1;
}
ll Now = ask(Q);
for (int itV = 0; itV <= mid; itV++){
int v = S[itV];
for (auto idx : g[v])
Q[idx] ^= 1;
}
ll Dif = (Now-Cost)/Step;
if (isOdd(Cost, Now, sub))
hi = mid;
else
lo = mid;
}
return S[hi];
}
void find_pair(int N, vector<int> U, vector<int> V, int A, int B){
int sub = 1;
if (U.size() == N-1) // Subtask 1,2,3,4
sub = 4;
else if ((A^B)&1)
sub = 5;
Step = B-A;
n = N;
int m = U.size();
Q.resize(m);
for (int i = 0; i < m; i++){
Q[i] = 1;
g[V[i]].push_back(i);
g[U[i]].push_back(i);
}
Cost = ask(Q);
vector<int> S, T;
for (int i = 16; i >= 0; i--){
for (int v = 0; v < n; v++)
if (v & (1 << i))
for (auto idx : g[v])
Q[idx] ^= 1;
ll Now = ask(Q);
for (int v = 0; v < n; v++)
if (v & (1 << i))
for (auto idx : g[v])
Q[idx] ^= 1;
if (isOdd(Cost, Now, sub)){
for (int v = 0; v < n; v++)
if (v & (1 << i))
S.push_back(v);
else
T.push_back(v);
break;
}
}
int s = find(S, sub), t = find(T, sub);
answer(s,t);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |