QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#646228 | #7470. WBLT | piggy123 | 0 | 621ms | 13896kb | C++20 | 6.4kb | 2024-10-16 21:46:53 | 2024-10-16 21:46:53 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
using namespace std;
struct node {
ll l,r,b,id;
} p[100005],P2[100005];
ll tot=0;
vector<node> P3[100005];
ll a[100005],cnt[100005],ANS[100005],S;
const ll w=64,w2=6,w3=63,lim=100000;
unsigned ll pre[88],suf[88];
struct Bitset {
vector<unsigned ll> vs;
int n;
inline void init(int len) {
vs.resize((len>>w2)+4);
n=len;
}
friend Bitset operator&(Bitset A,Bitset B) {
Bitset C;
C.init(max(A.n,B.n));
for (ll i=0; i<=(min(A.n,B.n)>>w2); i++) {
C.vs[i]=A.vs[i]&B.vs[i];
}
return C;
}
inline ll operator[](int x) {
return vs[x>>w2]>>(x&w3)&1;
}
inline void set(int x,int v) {
vs[x>>w2]-=(vs[x>>w2]>>(x&w3)&1)<<(x&w3);
vs[x>>w2]+=v<<(x&w3);
}
inline unsigned ll subcut(int l,int r) {
if ((l>>w2)==(r>>w2)) {
return ((pre[r&w3]-(!(l&w3)?0:pre[(l&w3)-1]))&vs[l>>w2])>>(l&w3);
} else {
return ((suf[l&w3]&vs[l>>w2])>>(l&w3))|((pre[r&w3]&vs[r>>w2])<<(w-(l&w3)));
}
}
inline Bitset sub(int l,int r) {
Bitset C;
C.init(max(0,r-l+1));
if (r-l+1<=0)return C;
int pl=l;
for (int i=0; i<=((r-l+1)>>w2); i++) {
C.vs[i]=subcut(pl,min(r,pl+(int)w-1));
pl+=w;
}
return C;
}
inline bool any() {
for (int i=0; i<=(n>>w2); i+=4)if (vs[i]|vs[i+1]|vs[i+2]|vs[i+3])return 1;
return 0;
}
inline void all() {
for (int i=0; i<(n>>w2); i++) {
vs[i]=pre[w-1];
}
vs[n>>w2]=pre[n&w3];
}
inline ll mex() {
ll ans=0;
for (int i=0; i<=(n>>w2); i++) {
if ((~vs[i])==0){
ans+=w;
}else{
ans+=__builtin_ctzll(~vs[i]);
break;
}
}
return ans;
}
} bs,bs2[66];
ll T=0;
inline void add(int pos) {
cnt[a[pos]]++;
if (cnt[a[pos]]==1) {
bs.set(a[pos],1);
}
}
inline void del(int pos) {
cnt[a[pos]]--;
if (cnt[a[pos]]==0) {
bs.set(a[pos],0);
}
}
inline void add1(int pos) {
cnt[a[pos]]++;
if (cnt[a[pos]]==1) {
bs2[a[pos]%T].set(a[pos]/T,1);
}
}
inline void del1(int pos) {
cnt[a[pos]]--;
if (cnt[a[pos]]==0) {
bs2[a[pos]%T].set(a[pos]/T,0);
}
}
inline ll read() {
ll x=0;
char c=getchar();
while(!isdigit(c))c=getchar();
while (isdigit(c))x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x;
}
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
int n;
n=read();
for (int i=1; i<=n; i++) {
a[i]=read();
}
for (int i=0; i<w; i++) {
if (i==0) {
pre[i]=(1ull<<i);
} else {
pre[i]=pre[i-1]+(1ull<<i);
}
}
for (int i=w-1; i>=0; i--) {
suf[i]=suf[i+1]+(1ull<<i);
}
int q;
q=read();
for (int i=1; i<=q; i++) {
p[i].l=read(),p[i].r=read(),p[i].b=read();
p[i].id=i;
if (p[i].b<=w) {
P3[p[i].b].push_back(p[i]);
} else {
P2[++tot]=p[i];
}
}
if (tot) {
S=n/sqrt(tot)+1;
sort(P2+1,P2+1+tot,[&](node a,node b) {
return (a.l/S==b.l/S?(a.l/S%2?a.r>b.r:a.r<b.r):a.l<b.l);
});
int L=1,R=0;
bs.init(lim);
for (int i=1; i<=tot; i++) {
// cout<<p[i].l<<" "<<p[i].r<<"------------\n";
while (L>P2[i].l)add(--L);
while (R<P2[i].r)add(++R);
while (L<P2[i].l)del(L++);
while (R>P2[i].r)del(R--);
Bitset ans;
ans.init(P2[i].b-1);
ans.all();
int rel=lim/P2[i].b+1;
for (int j=1; j<=lim/P2[i].b+1; j++) {
Bitset A=bs.sub((j-1)*P2[i].b,min(lim,j*P2[i].b-1));
ans=ans&A;
if (!ans.any()) {
rel=j-1;
break;
}
}
ANS[P2[i].id]=rel;
}
}
for (int i=1; i<=w; i++) {
if (P3[i].empty())continue;
S=n/sqrt(P3[i].size())+1;
T=i;
for (int j=0; j<=lim; j++)cnt[j]=0;
sort(P3[i].begin(),P3[i].end(),[&](node a,node b) {
return (a.l/S==b.l/S?(a.l/S%2?a.r>b.r:a.r<b.r):a.l<b.l);
});
for (int j=0; j<i; j++) {
bs2[j].init(lim/i);
for (unsigned ll &k:bs2[j].vs) {
k=0;
}
}
int L=1,R=0;
for (int j=0; j<P3[i].size(); j++) {
while (L>P3[i][j].l)add1(--L);
while (R<P3[i][j].r)add1(++R);
while (L<P3[i][j].l)del1(L++);
while (R>P3[i][j].r)del1(R--);
for (int k=0; k<i; k++) {
ANS[P3[i][j].id]=max(ANS[P3[i][j].id],bs2[k].mex());
}
}
}
for (int i=1; i<=q; i++)cout<<ANS[i]<<"\n";
return 0;
}
/*
2
49999 99999
1
1 2 49999
■■■■■ ■■ ■■■ ■■■ ■ ■ ■ ■■■■ ■■■■
■ ■■ ■■ ■ ■■ ■ ■■ ■ ■ ■■ ■ ■■ ■■ ■
■ ■ ■■ ■ ■ ■ ■ ■ ■ ■■■ ■■ ■■ ■ ■■
■ ■ ■■ ■ ■ ■ ■ ■ ■ ■■ ■ ■■ ■■
■ ■ ■■ ■ ■ ■■ ■■ ■■ ■
■ ■■ ■■ ■ ■■■ ■ ■■■ ■■ ■■ ■■ ■■■
■■■■■ ■■ ■ ■ ■ ■ ■■ ■■ ■■ ■■
■ ■■ ■ ■ ■ ■ ■■ ■■ ■■ ■
■ ■■ ■ ■ ■ ■ ■■ ■■ ■ ■ ■■
■ ■■ ■■ ■■ ■■ ■■ ■■ ■■ ■ ■■ ■■
■ ■■ ■■■■ ■■■■ ■■ ■■ ■■■■■■ ■■■■
*/
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 6568kb
input:
1000 233 991 831 426 140 881 289 287 957 886 561 109 305 469 961 577 683 593 277 601 181 255 100 997 161 619 632 413 987 811 357 635 99 809 888 511 945 881 261 434 851 311 21 641 508 701 661 158 696 560 577 501 951 786 909 238 546 573 617 236 270 705 786 353 651 296 353 720 261 429 855 176 977 57 50...
output:
6 3 2 4 4 0 4 2 2 2 2 2 4 4 2 3 4 4 2 3 5 3 3 2 2 8 2 2 4 3 2 3 5 4 5 3 0 6 2 2 4 2 2 3 4 2 2 2 2 3 2 5 2 3 2 3 2 4 4 0 0 2 2 2 3 2 3 4 2 5 2 6 2 7 0 2 2 2 3 4 2 2 0 2 3 3 3 2 4 2 2 2 6 3 2 4 5 3 3 2 2 2 2 2 2 5 4 3 4 2 3 3 4 2 4 3 2 2 2 5 3 2 2 3 3 3 2 4 7 2 2 5 2 4 2 3 2 5 2 3 2 3 2 3 4 2 2 2 2 4 ...
result:
wrong answer 1st numbers differ - expected: '3', found: '6'
Subtask #2:
score: 0
Wrong Answer
Test #2:
score: 0
Wrong Answer
time: 119ms
memory: 13896kb
input:
100000 241 721 861 909 540 928 171 159 637 60 145 227 110 975 766 220 311 761 191 980 887 793 773 957 625 61 994 606 465 625 598 667 181 197 15 826 136 499 199 331 621 327 945 726 197 997 681 641 465 805 211 531 333 505 483 345 612 241 376 700 5 338 661 777 241 412 118 585 121 1 398 658 855 598 300 ...
output:
2 6 17 3 2 2 2 2 2 3 2 2 7 2 3 2 4 2 2 3 4 5 2 2 4 2 2 4 2 2 2 3 5 6 2 2 5 2 3 4 3 2 3 3 2 3 2 2 2 2 2 2 3 3 3 2 3 3 2 2 2 2 2 2 3 4 4 6 2 3 2 4 2 5 2 23 2 3 2 1 2 2 2 4 2 4 2 2 4 2 2 4 2 7 4 2 2 2 3 3 2 2 3 2 1 2 3 2 2 2 3 2 5 2 2 5 2 5 21 2 7 3 2 3 2 2 2 2 5 2 4 4 2 2 3 2 2 2 3 4 3 4 2 4 3 2 2 5 2...
result:
wrong answer 13th numbers differ - expected: '11', found: '7'
Subtask #3:
score: 0
Wrong Answer
Test #5:
score: 0
Wrong Answer
time: 621ms
memory: 13624kb
input:
99917 24947 3268 49683 43610 87927 86331 16017 19557 72137 16689 28231 87819 9481 2403 18661 8145 86091 90410 54635 10896 53999 43367 95987 23733 17359 94625 81763 44331 63663 6075 20784 94229 61578 3890 95047 32681 39491 33139 51629 34573 859 31797 22897 7647 52199 17817 6311 46787 20619 81037 5374...
output:
3 2 4 7 10 4 9 6 4 4 7 12 6 10 4 10 4 0 7 3 5 4 4 3 4 4 5 3 4 4 9 8 1 4 3 4 7 8 6 5 4 12 3 5 9 5 3 6 4 6 3 8 5 3 5 16 5 5 3 8 3 3 8 4 17 4 1 8 6 2 2 5 3 1 8 9 8 10 4 6 3 7 4 5 6 10 7 11 8 8 10 19 4 9 4 3 5 6 5 4 6 12 6 5 4 4 10 2 11 9 7 3 4 8 12 7 5 0 5 8 7 9 1 5 3 6 5 6 9 4 7 3 9 3 6 7 5 3 6 4 7 5 ...
result:
wrong answer 2nd numbers differ - expected: '7', found: '2'