# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1078523 | someone | Broken Device (JOI17_broken_device) | C++14 | 2087 ms | 3772 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 "Annalib.h"
#include <bits/stdc++.h>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
using i64 = long long;
using namespace std;
const i64 MOD1 = 1e9 + 7, MOD2 = 1e9 + 9;
void Anna(int N, long long X, int K, int P[]) {
vector<bool> broken(N);
for(int i = 0; i < K; i++)
broken[P[i]] = 1;
mt19937 rng(42);
X ^= rng();
vector<array<int, 2>> crt[2];
for(int i = 0; i < N/2; i++) {
int val = rng() % MOD1;
if(!broken[i]) crt[0].push_back({val, i});
}
for(int i = N/2; i < N; i++) {
int val = rng() % MOD2;
if(!broken[i]) crt[1].push_back({val, i});
}
vector<int> ans(N);
for(int i = 0; i < 2; i++) {
crt[i].resize(34);
vector<array<int, 3>> pos;
pos.reserve(1 << 18);
int mod = (i == 0 ? MOD1 : MOD2);
for(int mask = 0; mask < (1 << 17); mask++) {
int sum1 = 0, sum2 = (mod - X % mod) % mod;
for(int j = 0; j < 17; j++) if(mask & (1 << j)) {
sum1 = (sum1 + crt[i][j][0]) % mod;
sum2 = (sum2 + mod - crt[i][j+17][0]) % mod;
}
pos.push_back({sum1, 0, mask});
pos.push_back({sum2, 17, mask});
}
sort(all(pos));
for(int j = 1; j < sz(pos); j++)
if(pos[j][1] == pos[j-1][1]) {
for(int k = 0; k < 17; k++)
if(pos[j][2] & (1 << k))
ans[crt[i][pos[j][1] + k][1]] = 1;
for(int k = 0; k < 17; k++)
if(pos[j-1][2] & (1 << k))
ans[crt[i][pos[j-1][1] + k][1]] = 1;
break;
}
}
for(int i = 0; i < N; i++)
Set(i, ans[i]);
}
#include "Brunolib.h"
#include <bits/stdc++.h>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
using i64 = long long;
using namespace std;
const i64 MOD1 = 1e9 + 7, MOD2 = 1e9 + 9;
using ll = __int128;
ll euclid(ll a, ll b, ll &x, ll &y) {
if (!b) return x = 1, y = 0, a;
ll d = euclid(b, a % b, y, x);
return y -= a/b * x, d;
}
ll crt(ll a, ll m, ll b, ll n) {
if (n > m) swap(a, b), swap(m, n);
ll x, y, g = euclid(m, n, x, y);
assert((a - b) % g == 0); // else no solution
x = (b - a) % n * x % n / g * m + a;
return x < 0 ? x + m*n/g : x;
}
long long Bruno( int N, int A[] ){
mt19937 rng(42);
i64 xored = rng(), a = 0, b = 0;
for(int i = 0; i < N/2; i++) {
i64 val = rng();
if(A[i]) a ^= val;
}
for(int i = N/2; i < N; i++) {
i64 val = rng();
if(A[i]) b ^= val;
}
return ((i64)crt(a, MOD1, b, MOD2)) ^ xored;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |