QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#507863 | #8335. Fast Hash Transform | ucup-team2307 | TL | 616ms | 3636kb | C++20 | 3.2kb | 2024-08-06 21:49:41 | 2024-08-06 21:49:42 |
Judging History
answer
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
using namespace std;
using ll = long long;
using ull=unsigned long long;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using pii = pair<int, int>;
using vi = vector<int>;
#define fi first
#define se second
#define pb push_back
const int L=64;
using row=bitset<L+1>;
using matr=array<row,L+1>;
constexpr matr UNIT()
{
matr res={};
for(int i=0;i<=L;i++)
res[i][i]=true;
return res;
}
matr mul(const matr& l,const matr& r)
{
matr R;
for(int i=0;i<=L;i++)
for(int j=0;j<=L;j++)
R[i][j] = r[j][i];
matr res={};
for(int i=0;i<=L;i++)
for(int j=0;j<=L;j++)
{
res[i][j] = (l[i]&R[j]).count()&1;
}
return res;
}
void print(matr m)
{
for(int i=0;i<=L;i++,cout<<"\n")
for(int j=0;j<=L;j++)
cout<<m[i][j];
cout<<"\n";
}
matr read()
{
matr res={};
res[L][L]=true;
// cout<<"read start"<<endl;
int m;
cin>>m;
while(m--)
{
int s,o;
ull a;
cin>>s>>o>>a;
for(int i=0;i<L;i++)
{
int j=(i+s)%L;
if(o==0)
{
if((a>>j)&1)
res[L][j].flip();
else
res[i][j].flip();
}
else
{
if((a>>j)&1)
res[i][j].flip();
}
}
}
ull b;
cin>>b;
for(int i=0;i<L;i++)
if((b>>i)&1)
res[L][i].flip();
// cout<<"read end"<<endl;
// print(res);
return res;
}
static matr unit = UNIT();
struct Tree {
typedef matr T;
T f(const T& a, const T& b) { return mul(a,b); } // (any associative fn)
vector<T> s; int n;
Tree(int n = 0, T def = unit) : s(2*n, def), n(n) {}
void update(int pos, const T& val) {
for (s[pos += n] = val; pos /= 2;)
s[pos] = f(s[pos * 2], s[pos * 2 + 1]);
}
T query(int b, int e) { // query [b, e)
T ra = unit, rb = unit;
for (b += n, e += n; b < e; b /= 2, e /= 2) {
if (b % 2) ra = f(ra, s[b++]);
if (e % 2) rb = f(s[--e], rb);
}
return f(ra, rb);
}
};
signed main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
int n,q,c;
cin>>n>>q>>c;
Tree tree(n);
for(int i=0;i<n;i++)
tree.update(i,read());
while(q--)
{
int op;
cin>>op;
if(op==0)
{
int l,r;
ull x;
cin>>l>>r>>x;
matr m=tree.query(l-1,r);
// print(m);
ull res=0;
for(int i=0;i<L;i++)
for(int j=0;j<L;j++)
if(m[i][j]&&((x>>i)&1))
res^=1ULL<<j;
for(int j=0;j<L;j++)
if(m[L][j])
res^=1ULL<<j;
cout<<res<<"\n";
}
else
{
int l;
cin>>l;
tree.update(l-1,read());
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3532kb
input:
3 5 1 1 4 0 0 51966 1 60 0 0 0 1 0 0 16 15 0 1 1 771 0 2 2 32368 0 3 3 0 1 2 2 0 0 15 61 1 4095 46681 0 1 3 2023
output:
64206 2023 31 1112
result:
ok 4 tokens
Test #2:
score: 0
Accepted
time: 3ms
memory: 3636kb
input:
9 9 3 32 9 0 17785061119123981789 33 0 10890571864137198682 42 0 9437574736788763477 34 0 5239651887868507470 55 0 14741743279679654187 27 1 1444116632918569317 38 1 5740886562180922636 1 1 8113356142324084796 3 0 10955266306442425904 60 0 16421026339459788005 53 0 1595107134632608917 48 1 923204972...
output:
9487331362121050549 3906661590723083106 15757672015979182109 4975471776251039345 11503109206538591140 3763610618439604410
result:
ok 6 tokens
Test #3:
score: 0
Accepted
time: 616ms
memory: 3488kb
input:
1 20000 400 32 13 0 1721926083061553294 52 1 8951352260297008058 6 0 3180917732545757991 63 1 14978562500072226750 50 1 7331113732303115313 59 0 688182721924779475 12 0 16291922173168822489 61 0 16018198440613086698 8 0 12494084957448674305 7 0 2834422858291562646 42 1 10354539547309738529 28 0 2541...
output:
11827781865759498816 7454610526276185721 9581050724293785387 2177163806257271094 14004004964877510141 18073834598135159471 16966489063087641088 12289032565388413023 17823140805867698239 18104549908461644670 15570008264282957124 12400954982104000299 9842549278742638708 16535034933613060362 1561642006...
result:
ok 19600 tokens
Test #4:
score: -100
Time Limit Exceeded
input:
500 20000 400 32 3 0 9869926173615303101 39 1 11114680792832491178 54 1 3380955246053990760 31 0 16868042247314276464 26 0 5814925615581342395 30 1 1114053898154397400 46 1 9215698002668459992 38 1 12938485987410997250 58 0 8030873196223549640 0 0 16055471402053138912 47 1 16568729207788187629 63 0 ...
output:
9119093329811149961 16901643057538871933 17161855998497876349 3964234071281411558 13588188063229334268 15557968976322375381 4612345875926431452 9507168112801039022 9504318642653891468 217407202160767706 12982350345598971306 17957502630817476223 6353877977318728572 15552768639781831485 16778108770682...