QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#385465 | #7765. Xor Master | valeriu# | 0 | 402ms | 91896kb | C++20 | 6.0kb | 2024-04-10 19:34:51 | 2024-07-04 03:35:27 |
Judging History
answer
#pragma GCC optimize("O3,fast-math")
//#pragma GCC target("avx,avx2,sse3,sse4")
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
//#define int ll
#define sz(x) ((int)(x).size())
using pii = pair<int,int>;
using tii = tuple<int,int,int>;
const int bmax = 64;
namespace Basis {
ull pivot[bmax];
ull contrmsk[bmax];
ull control = 0;
ull flippers = 0;
int upd = -1;
bool add(ull x) {
upd = -1;
for(int i = bmax - 1; i >= 0; i--) {
if(pivot[i] == 0 && ((1ull << i) & x)) {
pivot[i] = x;
upd = i;
break;
}
else if(pivot[i] != 0 && ((1ull << i) & x))
x ^= pivot[i];
}
if(x == 0) return 0;
for(int i = 0; i < bmax; i++) {
if(pivot[i] == 0) continue;
for(int j = i + 1; j < bmax; j++) {
if(pivot[j] & (1ull << i))
pivot[j] ^= pivot[i];
}
}
control = 0;
flippers = 0;
for(int contra = 0; contra < bmax; contra++) {
contrmsk[contra] = 0;
if(pivot[contra] != 0) {
control |= (1ull << contra);
continue;
}
for(int i = contra + 1; i < bmax; i++)
if(pivot[i] & (1ull << contra)) contrmsk[contra] |= (1ull << i);
if(__builtin_popcountll(contrmsk[contra]) % 2 == 1)
flippers |= (1ull << contra);
}
return 1;
}
ull get_val(ull a) {
ull R = 0;
for(int i = 0; i < bmax; i++) {
if(pivot[i] != 0) continue;
R |= ((ull)((__builtin_popcountll(a & contrmsk[i]) & 1)
^ ((a & (1ull << i))? 1 : 0))) << i;
}
return R;
}
}
pii operator +(const pii& x, const pii& y) {
return pii{x.first + y.first, x.second + y.second};
}
pii flip(const pii& x) { return pii{x.second, x.first}; }
const int nmax = 5e5 + 5;
int biti[nmax];
struct Node {
vector<pii> cnt;
ull txor;
int len;
Node() {
cnt.assign(1, pii{~0ull, 0ull});
txor = 0;
len = 1;
}
Node(ull a) {
cnt.assign(1, pii{0ull, 0ull});
txor = a;
len = 0;
}
void pull(Node L, Node R) {
len = L.len + R.len;
cnt.clear();
pii carry = {0, 0};
auto std = [&](int i) -> ull { if(i >= sz(R.cnt)) return 0; return (R.cnt[i].first & (~L.txor)) | (R.cnt[i].second & (L.txor)); };
auto inv = [&](int i) -> ull { if(i >= sz(R.cnt)) return 0; return (R.cnt[i].first & (L.txor)) | (R.cnt[i].second & (~L.txor)); };
for(int i = 0; i < max(sz(L.cnt), sz(R.cnt)) || carry.first || carry.second; i++) {
ull A, B;
if(i >= sz(L.cnt)) A = B = 0;
else tie(A, B) = L.cnt[i];
pii new_carry((A & carry.first) | (std(i) & carry.first) | (std(i) & A), (B & carry.second) | (inv(i) & carry.second) | (inv(i) & B));
cnt.emplace_back((A ^ carry.first ^ std(i)), (B ^ carry.second ^ inv(i)));
carry = new_carry;
}
txor = L.txor ^ R.txor;
}
};
const int N = (1 << 19) + 5; // limit for array size
template<typename Node>
struct AINT {
int n; // array size
Node t[2 * N];
void init(int n_) {
int p = 1;
while(p < n_) p *= 2;
n = p;
}
void build() { // build the tree
for (int i = n - 1; i > 0; --i) t[i].pull(t[i<<1], t[i<<1|1]);
}
void modify(int p, Node value) { // set value at position p
p--;
for (t[p += n] = value; p > 1; p >>= 1) t[p>>1].pull(t[min(p, p^1)], t[max(p, p^1)]);
}
Node query(int l, int r) { // sum on interval [l, r)
--l;
Node resL(0), resR(0);
for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
if (l&1) resL.pull(resL, t[l++]);
if (r&1) resR.pull(t[--r], resR);
}
resL.pull(resL, resR);
return resL;
}
};
signed main() {
cin.tie(0) -> sync_with_stdio(0);
int n, q;
cin >> n >> q;
biti[1] = 1;
for(int i = 2; i < nmax; i++) biti[i] = biti[i >> 1] + 1;
AINT<Node> aint;
aint.init(n);
vector<ull> v(n + 1), real(n + 1);
for(auto &x : v | views::drop(1)) cin >> x;
real = v;
auto update = [&](int p, ull x) {
v[p] ^= Basis::get_val(x);
real[p] ^= x;
Node H;
H.pull(Node(v[p]), Node());
aint.modify(p, H);
};
auto reformat = [&]() {
if(Basis::upd == -1) {
for(int i = 1; i <= n; i++) {
aint.t[i + aint.n - 1].pull(Node(v[i]), Node());;
}
aint.build();
return;
}
ull A = Basis::pivot[Basis::upd];
ull msb = A, T = msb;
while(msb > 0) T = msb, msb &= (msb - 1);
msb = T;
const Node pula_lui_becali(A);
for(int i = 1; i <= n; i++) {
if(v[i] & msb) {
v[i] ^= A;
aint.t[i + aint.n - 1].pull(pula_lui_becali, aint.t[i + aint.n - 1]);
}
}
aint.build();
return;
};
auto query = [&](int l, int r) -> ull {
ull rez = 0;
Node elem(Basis::flippers);
elem.pull(elem, aint.query(l, r));
ull p = 1;
for(auto x : elem.cnt) rez += x.second * p, p <<= 1;
return rez;
};
reformat();
for(int i = 0; i < q; i++) {
int T;
cin >> T;
if(T == 1) {
int p;
ull x;
cin >> p >> x;
update(p, x);
}
else if(T == 2) {
ull x;
cin >> x;
if(Basis::add(x)) {
reformat();
}
}
else {
int l, r;
cin >> l >> r;
cout << query(l, r) + Basis::control * (ull)(r - l + 1) << '\n';
}
}
}
/**
Anul asta nu se da centroid
-- Rugaciunile mele
*/
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 30ms
memory: 79360kb
input:
2000 2000 1860495733 462603674 3739839441 759356520 47330263 550811730 2301200895 989240351 2499503801 2624225494 2123076812 1180966826 238739434 488666688 784742950 2583466952 4111371941 2335988605 2583741355 933716686 1644403538 1970423306 304500250 905101643 1814942168 1136358764 88729799 1577263...
output:
29488012073 18446743991360242365 18446744022781727305 34460823299 7864313619 18446744050585917606 20991540472 38159171583 22047837290 18446744069885242712 30207992329 38867149035 18446744072769973309 6373015840 106541221316 18446743937382158510 18446743984358110276 71444810085 18446744039771626473 1...
result:
wrong answer 1st lines differ - expected: '867006634793', found: '29488012073'
Subtask #2:
score: 0
Wrong Answer
Test #5:
score: 0
Wrong Answer
time: 402ms
memory: 91896kb
input:
500000 100000 12261386944926786495 7846697792998647383 16622924885320463714 170129022271213944 12625257523700625864 7684671687986103560 11532026873918423068 1131776055566669037 8263146651412710501 17872572061246021001 5017109039248728310 11088626167542318645 13810119722795416818 10928315716094262229...
output:
18446743908496470136 235743516692 216129662365 18446743815865446852 18446743929796586493 18446743851740850292 18446743401395578327 18446743921324300565 18446743920737436596 18446743955735602576 18446743586727494159 18446743219508550721 64548599901 118650555923 18446744040453370824 221749579336 62908...
result:
wrong answer 1st lines differ - expected: '12337138966997790840', found: '18446743908496470136'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Wrong Answer
Test #15:
score: 0
Wrong Answer
time: 352ms
memory: 81960kb
input:
100000 100000 860905160 3192911636 290327446 2020707113 959258245 454185039 421895589 1070265496 2218913641 1684685660 1206723673 2606734467 4247254571 3341954386 3805299640 1702270353 2472053741 2816060613 1307901348 2702949728 879391505 884661815 330738731 1575749344 1239158446 2099693858 67466644...
output:
41573787219175 25364917827893 32412318577715 12585005100121 6600461082533 17797595422475 7320866271155 8118678421086 2829930978325 53493879457672 52183923020322 75475316316644 3080768402626 36693104020698 25244683763858 48751336773132 12521025095609 63266706143341 50256413653692 30057886969473 26857...
result:
wrong answer 1st lines differ - expected: '208755389215975', found: '41573787219175'
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
0%
Subtask #7:
score: 0
Skipped
Dependency #1:
0%