QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#646460#7470. WBLTpiggy1230 677ms13840kbC++207.2kb2024-10-16 23:22:162024-10-16 23:22:17

Judging History

你现在查看的是最新测评结果

  • [2024-10-16 23:22:17]
  • 评测
  • 测评结果:0
  • 用时:677ms
  • 内存:13840kb
  • [2024-10-16 23:22:16]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
using namespace std;

struct node {
	int l,r,b,id;
} p[100001],P2[100001];
int tot=0;
vector<node> P3[66];
int a[100001],cnt[100001],ANS[100001],S;
const ll w=64,w2=6,w3=63,lim=100000;
unsigned ll pre[66],suf[66];
struct Bitset {
	vector<unsigned ll> vs;
	ll n;
	inline void init(ll len) {
		vs.resize((len>>w2)+1);
		n=len;
	}
	inline void operator&=(Bitset B) {
		if (B.n<n)n^=B.n^=n^=B.n,swap(B.vs,vs);
		for (ll i=0; i<=(n>>w2); i++) {
			vs[i]&=B.vs[i];
		}
	}
	inline void set0(ll x) {
		vs[x>>w2]&=~(1ull<<(x&w3));
	}
	inline void set1(ll x) {
		vs[x>>w2]|=(1ull<<(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++)if (vs[i])return 1;
		return 0;
	}
	inline void all() {
		for (ll i=0; i<(n>>w2); i++) {
			vs[i]=~0;
		}
		vs[n>>w2]=pre[n&w3];
	}
	inline ll mex() {
		ll ans=0;
		for (ll i=0; i<=(n>>w2); i++) {
			if (!(~vs[i])){
				ans+=w;
			}else{
				ans+=__builtin_ctzll(~vs[i]);
				break;
			}
		}
		return ans;
	}
} bs,bs2[66];
ll T=0;

inline void add(ll pos) {
	cnt[a[pos]]++;
	if (cnt[a[pos]]==1) {
		bs.set1(a[pos]);
	}
}

inline void del(ll pos) {
	cnt[a[pos]]--;
	if (cnt[a[pos]]==0) {
		bs.set0(a[pos]);
	}
}

inline void add1(ll pos) {
	cnt[a[pos]]++;
	if (cnt[a[pos]]==1) {
		bs2[a[pos]%T].set1(a[pos]/T);
	}
}

inline void del1(ll pos) {
	cnt[a[pos]]--;
	if (cnt[a[pos]]==0) {
		bs2[a[pos]%T].set0(a[pos]/T);
	}
}

namespace ly
{
    namespace IO
    {
        #ifndef LOCAL
            #define SIZE (1<<25)
            char in[SIZE],out[SIZE],*p1=in,*p2=in,*p3=out;
            #define getchar() (p1==p2&&(p2=(p1=in)+fread(in,1,SIZE,stdin),p1==p2)?EOF:*p1++)
            #define flush() (fwrite(p3=out,1,SIZE,stdout))
            #define putchar(ch) (p3==out+SIZE&&flush(),*p3++=(ch))
            class Flush{public:~Flush(){flush();}}_;
        #endif
        template<typename type>
        inline void read(type &x)
        {
            x=0;char ch=getchar();
            while(!isdigit(ch)) ch=getchar();
            while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
        }
        template<typename type>
        inline void write(type x)
        {
            static short Stack[50],top(0);
            do Stack[++top]=x%10,x/=10;while(x);
            while(top) putchar(Stack[top--]|48);
            putchar(' ');
        }
        #ifndef LOCAL
            #undef SIZE
            #undef getchar
            #undef putchar
            #undef flush
        #endif
    }
}using namespace ly::IO;

int main() {
	ll n;
	read(n);
	for (ll i=1; i<=n; i++) {
		read(a[i]);
	}
	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;
	read(q);
	for (ll i=1; i<=q; i++) {
//		p[i].l=read(),p[i].r=read(),p[i].b=read();
		read(p[i].l);read(p[i].r);read(p[i].b);
		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) {
			if (a.l/S==b.l/S){
				if ((a.l/S)&1)return a.r>b.r;
				else return a.r<b.r;
			}else{
				return a.l<b.l;
			}
		});
		ll L=1,R=0;
		bs.init(lim);
		for (ll i=1; i<=tot; i++) {
			int l=P2[i].l,r=P2[i].r,b=P2[i].b;
			while (L>l)add(--L);
			while (R<r)add(++R);
			while (L<l)del(L++);
			while (R>r)del(R--);
			Bitset ans;
			ans.init(b-1);
			ans.all();
			ll rel=0;
			for (ll j=1;; ++j) {
				ans&=bs.sub((j-1)*b,min(lim,j*b-1));
				if (!ans.any()) {
					rel=j-1;
					break;
				}
			}
			ANS[P2[i].id]=rel;
		}
	}

	for (ll i=1; i<=w; ++i) {
		if (P3[i].empty())continue;
		S=n/sqrt(P3[i].size())+1;
		T=i;
		for (ll j=0; j<=lim; j++)cnt[j]=0;
		sort(P3[i].begin(),P3[i].end(),[&](node a,node b) {
			if (a.l/S==b.l/S){
				if ((a.l/S)&1)return a.r>b.r;
				else return a.r<b.r;
			}else{
				return a.l<b.l;
			}
		});
		for (ll j=0; j<i; j++) {
			bs2[j].init(lim/i);
			for (unsigned ll &k:bs2[j].vs) {
				k=0;
			}
		}
		ll L=1,R=0;
		for (ll j=0; j<P3[i].size(); ++j) {
			ll l=P3[i][j].l,r=P3[i][j].r;
			while (L>l)add1(--L);
			while (R<r)add1(++R);
			while (L<l)del1(L++);
			while (R>r)del1(R--);
			for (ll k=0; k<i; ++k) {
				ANS[P3[i][j].id]=max(ANS[P3[i][j].id],(int)bs2[k].mex());
			}
		}
	}
	for (ll i=1; i<=q; i++)write(ANS[i]);
	return 0;
}

/*
2
49999 99999
1
1 2 49999
                                                                
 ■■■■■     ■■      ■■■     ■■■   ■    ■     ■     ■■■■    ■■■■  
 ■   ■■    ■■     ■  ■■   ■  ■■  ■    ■    ■■     ■  ■■  ■■  ■  
 ■    ■    ■■    ■    ■  ■    ■   ■  ■    ■■■    ■■  ■■  ■   ■■ 
 ■    ■    ■■    ■    ■  ■    ■   ■  ■     ■■    ■   ■■      ■■ 
 ■    ■    ■■    ■       ■         ■■      ■■        ■■      ■  
 ■   ■■    ■■    ■  ■■■  ■  ■■■    ■■      ■■       ■■     ■■■  
 ■■■■■     ■■    ■    ■  ■    ■    ■■      ■■      ■■        ■■ 
 ■         ■■    ■    ■  ■    ■    ■■      ■■     ■■          ■ 
 ■         ■■    ■    ■  ■    ■    ■■      ■■     ■      ■   ■■ 
 ■         ■■    ■■  ■■  ■■  ■■    ■■      ■■    ■       ■■  ■■ 
 ■         ■■      ■■■■    ■■■■    ■■      ■■    ■■■■■■   ■■■■  
*/

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 9844kb

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:

wrong answer Output contains longer sequence [length = 1001], but answer contains 1000 elements

Subtask #2:

score: 0
Wrong Answer

Test #2:

score: 0
Wrong Answer
time: 92ms
memory: 13840kb

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:

wrong answer Output contains longer sequence [length = 100001], but answer contains 100000 elements

Subtask #3:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 677ms
memory: 13752kb

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 7 9 5 3123 34 5 3 2 7 8 45 34 350 11 515 3 0 40 1 11 2 5 2 3 267 6 2 3 11 333 13 0 5 11 424 676 17 7 103 5 11 4 10 3 4 1 23 2 7 4 63 7 1 0 93 10 7 9 5674 16 1 16 9 141 2 1 2 18 1 6 4 1 0 714 8 18 14 3 1 4 13 5 4 1 278 6 19 130 9 7 763 3 26 5 2 1427 4 3348 389 41 11 1564 362 10 5 8 1 2271 15 18 3 3...

result:

wrong answer Output contains longer sequence [length = 99969], but answer contains 99968 elements