QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#646111 | #7470. WBLT | piggy123 | 60 | 337ms | 16344kb | C++20 | 6.2kb | 2024-10-16 21:18:04 | 2024-10-16 21:18:08 |
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;
ll n;
inline void init(ll len) {
vs.resize((len>>w2)+5);
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[](ll x) {
return vs[x>>w2]>>(x&w3)&1;
}
inline void set(ll x,ll v) {
vs[x>>w2]-=(vs[x>>w2]>>(x&w3)&1)<<(x&w3);
vs[x>>w2]+=v<<(x&w3);
}
inline ll subcut(ll l,ll 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(ll l,ll r) {
Bitset C;
C.init(max(0ll,r-l+1));
if (r-l+1<=0)return C;
ll pl=l;
for (ll i=0; i<=((r-l+1)>>w2); i++) {
C.vs[i]=subcut(pl,min(r,pl+w-1));
pl+=w;
}
return C;
}
inline bool any() {
for (ll 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 (ll i=0; i<(n>>w2); i++) {
vs[i]=pre[w-1];
}
vs[n>>w2]=pre[n&w3];
}
inline ll mex() {
ll ans=0;
for (ll i=0; i<=(n>>w2); i++) {
ll z=w;
if ((~vs[i])!=0)
z=__builtin_ctzll(~vs[i]);
ans+=z;
if (z!=w)break;
}
return min(n+1,ans);
}
} bs,bs2[66];
ll T=0;
inline void add(ll pos) {
cnt[a[pos]]++;
if (cnt[a[pos]]==1) {
bs.set(a[pos],1);
}
}
inline void del(ll pos) {
cnt[a[pos]]--;
if (cnt[a[pos]]==0) {
bs.set(a[pos],0);
}
}
inline void add1(ll pos) {
cnt[a[pos]]++;
if (cnt[a[pos]]==1) {
bs2[a[pos]%T].set(a[pos]/T,1);
}
}
inline void del1(ll 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);
ll n;
n=read();
for (ll i=1; i<=n; i++) {
a[i]=read();
}
for (ll i=0; i<w; i++) {
if (i==0) {
pre[i]=(1ull<<i);
} else {
pre[i]=pre[i-1]+(1ull<<i);
}
}
for (ll i=w-1; i>=0; i--) {
suf[i]=suf[i+1]+(1ull<<i);
}
ll q;
q=read();
S=sqrt(max(1ll,n));
for (ll 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<=30) {
P3[p[i].b].push_back(p[i]);
} else {
P2[++tot]=p[i];
}
}
sort(P2+1,P2+1+tot,[&](node a,node b) {
return (a.l/S==b.l/S?a.r<b.r:a.l<b.l);
});
ll L=1,R=0;
bs.init(lim);
for (ll 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();
ll rel=lim/P2[i].b+1;
for (ll 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 (ll i=1; i<=w; i++) {
T=i;
for (ll j=0; j<i; j++) {
bs2[j].init(lim/i);
}
for (ll j=0;j<=lim;j++)cnt[j]=0,bs2[j%i].set(j/i,0);
sort(P3[i].begin(),P3[i].end(),[&](node a,node b) {
return (a.l/S==b.l/S?a.r<b.r:a.l<b.l);
});
ll L=1,R=0;
for (ll 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 (ll k=0; k<P3[i][j].b; k++) {
ANS[P3[i][j].id]=max(ANS[P3[i][j].id],bs2[k].mex());
}
}
}
for (ll 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: 30
Accepted
Test #1:
score: 30
Accepted
time: 17ms
memory: 8288kb
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:
3 3 2 4 4 0 3 2 2 2 2 2 1 4 2 2 3 3 2 2 5 3 1 2 2 2 2 1 3 3 2 3 1 3 5 2 0 4 2 1 5 2 2 2 2 2 2 2 2 2 2 6 1 3 2 1 2 2 1 0 0 2 2 2 3 2 1 3 2 2 2 3 2 4 0 2 2 2 3 3 2 2 0 2 3 2 2 2 4 1 2 2 4 3 2 2 5 3 2 2 1 1 2 2 2 6 3 2 1 2 3 1 1 0 3 3 2 2 2 1 2 2 2 3 3 3 2 4 3 2 1 5 2 4 2 1 1 2 2 3 2 2 2 3 3 2 2 1 2 2 ...
result:
ok 1000 numbers
Subtask #2:
score: 30
Accepted
Test #2:
score: 30
Accepted
time: 173ms
memory: 12916kb
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 11 2 7 2 4 2 2 3 9 5 2 2 4 2 2 4 2 2 2 2 7 8 2 2 9 2 3 4 4 2 3 2 2 3 2 2 1 2 2 2 13 167 11 2 3 0 2 2 2 2 2 2 3 3 4 7 2 3 2 4 2 5 2 23 2 3 2 0 2 2 2 4 2 4 2 2 4 2 2 5 2 91 5 2 2 2 3 3 2 2 3 2 0 2 3 2 2 2 3 2 5 2 2 5 2 77 21 2 7 3 2 3 2 2 2 2 13 2 4 4 2 2 9 2 2 2 3 13 3 5 2 4 ...
result:
ok 100000 numbers
Test #3:
score: 30
Accepted
time: 337ms
memory: 14420kb
input:
100000 6 8 75 85 89 8 88 56 1 64 37 6 28 16 87 74 57 51 5 72 39 85 100 54 1 97 77 40 97 95 65 56 37 13 44 23 68 49 85 79 27 57 75 81 1 26 61 45 97 31 85 61 51 37 30 53 1 51 11 57 49 22 40 67 49 85 53 89 1 97 88 57 79 6 61 61 36 75 71 53 81 91 91 1 91 1 29 67 47 81 81 37 71 14 17 26 65 59 36 7 97 77 ...
output:
5 2 4 2 4 4 4 0 6 2 2 7 8 2 3 2 4 8 2 2 2 8 2 2 2 0 4 1 3 2 2 4 10 2 3 0 2 13 2 2 3 2 2 2 5 2 3 2 0 3 6 2 0 2 3 2 3 34 2 2 7 2 2 8 2 2 10 2 0 0 2 2 2 3 2 2 2 3 2 5 2 2 2 2 2 2 5 10 34 2 2 3 3 2 3 2 2 2 2 20 4 13 4 4 2 50 5 3 2 2 10 2 3 2 3 4 2 12 3 7 12 5 2 5 3 4 2 2 3 2 2 2 2 2 2 2 4 2 2 2 2 2 0 13...
result:
ok 100000 numbers
Test #4:
score: 30
Accepted
time: 235ms
memory: 16344kb
input:
100000 6 7 6 6 1 1 9 1 7 6 3 4 6 6 5 1 8 6 6 3 2 7 1 3 6 3 9 2 1 7 6 10 7 5 7 7 3 1 1 6 1 3 3 2 5 1 9 2 1 10 3 7 1 1 7 3 4 6 5 5 10 8 7 3 9 5 4 9 5 1 2 1 10 1 7 1 9 2 9 5 1 1 9 9 1 10 7 1 6 5 3 9 3 6 10 7 6 9 7 3 9 1 1 7 6 9 5 3 4 1 9 7 9 3 8 10 1 6 7 9 4 1 5 1 1 5 1 1 6 5 7 3 9 7 7 5 6 3 4 7 6 5 5 ...
output:
2 4 2 2 2 0 0 2 0 5 2 0 2 2 2 0 3 2 0 2 2 0 2 1 3 2 4 0 0 1 2 4 2 2 0 2 0 0 2 0 2 0 4 2 2 2 2 0 2 2 3 2 2 5 4 3 0 2 2 2 3 3 2 1 2 0 1 2 2 2 4 2 2 2 0 2 4 0 2 2 3 4 2 0 3 2 2 4 2 2 0 0 4 4 1 2 2 2 3 2 2 2 0 2 2 5 0 2 4 1 2 2 2 2 2 2 0 2 2 2 2 0 4 2 2 5 0 2 4 2 2 5 2 0 2 4 2 0 4 2 2 2 2 2 0 2 5 2 4 2 ...
result:
ok 100000 numbers
Subtask #3:
score: 0
Time Limit Exceeded
Test #5:
score: 0
Time Limit Exceeded
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...