QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#286703#7967. 二进制noodlesWA 1415ms166372kbC++172.8kb2023-12-18 13:42:482023-12-18 13:42:49

Judging History

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

  • [2023-12-18 13:42:49]
  • 评测
  • 测评结果:WA
  • 用时:1415ms
  • 内存:166372kb
  • [2023-12-18 13:42:48]
  • 提交

answer

#include <cstdio>
#include <cctype>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
template<typename T> void cmin(T &a,const T &b){if(b<a)a=b;}
template<typename T> void cmax(T &a,const T &b){if(a<b)a=b;}

void Read(int &x){
	char c;
	while(!isdigit(c=getchar()));
	x=(c&15);
	while(isdigit(c=getchar()))
		x=x*10+(c&15);
}

void Print(int x,char c){
	int i;
	for(i=1;i*10LL<=x;i*=10);
	for(;i;i/=10)
		putchar(x/i%10|48);
	putchar(c);
}

const int N=1000005;

struct PQ{
	priority_queue<int,vector<int>,greater<int>> q1,q2;
	void add(int x){
		q1.push(x);
	}
	void del(int x){
		q2.push(x);
	}
	int get(){
		while(!q2.empty() && q1.top()==q2.top()){
			q1.pop();
			q2.pop();
		}
		return q1.top();
	}
	void clear(){
		while(!q1.empty())
			q1.pop();
		while(!q2.empty())
			q2.pop();
	}
	int size(){
		return q1.size()-q2.size();
	}
}q[N];

int n,s[N],f[N],pre[N],nxt[N],to[N];

int c[N];
void add(int p){
	for(int i=p;i<=n;i+=i&-i)
		++c[i];
}
int qry(int p){
	int s=0;
	for(int i=p;i;i&=i-1)
		s+=c[i];
	return s;
}
int pos(int p){return p-qry(p-1);}

int main(){
	Read(n);
	pre[0]=0;
	nxt[0]=1;
	for(int i=1;i<=n;++i){
		char c;
		while(!isdigit(c=getchar()));
		s[i]=(c&15);
		if(s[i]==0)
			f[i]=-1;
		pre[i]=i-1;
		nxt[i]=i+1;
		to[i]=i;
	}
	pre[n+1]=n;
	nxt[n+1]=n+1;
	for(int x=1;x<=n;++x){
		if(!(x&(x-1))){
			for(int i=1;i<=n;++i)
				q[i].clear();
			for(int i=1;i<=n;++i){
				if(x!=1)
					to[i]=nxt[to[i]];
				if(f[i]==-1 || to[i]>n)
					f[i]=-1;
				else
					f[i]=((f[i]<<1)|s[to[i]]);
				if(f[i]!=-1 && f[i]<=n)
					q[f[i]].add(i);
			}
		}
		if(q[x].size()==0){
			putchar('-');
			putchar('1');
			putchar(' ');
			putchar('0');
			putchar('\n');
		}else{
			int v=q[x].get();
			Print(pos(v),' ');
			Print(q[x].size(),'\n');
			static int p[20],pc;
			pc=0;
			for(int i=v;;i=nxt[i]){
				p[pc++]=i;
				add(i);
				if(i==to[v])
					break;
			}
			for(int i=0;i<pc;++i){
				if(f[p[i]]!=-1 && f[p[i]]<=n)
					q[f[p[i]]].del(p[i]);
				f[p[i]]=-1;
			}
			for(int i=pre[p[0]];i>=1 && to[i]>=p[0];i=pre[i]){
				int owo=0,qwq=0;
				for(int j=0;j<pc;++j){
					to[i]=nxt[to[i]];
					if(f[i]!=-1 && to[i]>p[pc-1]){
						++owo;
						qwq=(qwq<<1)|s[to[i]];
					}
				}
				if(f[i]!=-1 && f[i]<=n)
					q[f[i]].del(i);
				if(f[i]!=-1)
					f[i]=(((f[i]>>owo)<<owo)|qwq);
				if(f[i]!=-1 && f[i]<=n)
					q[f[i]].add(i);
			}
			nxt[pre[p[0]]]=nxt[p[pc-1]];
			pre[nxt[p[pc-1]]]=pre[p[0]];
		}
		// if(x==4){
		// 	for(int i=nxt[0];i<=n;i=nxt[i])
		// 		printf("%d",s[i]);
		// 	putchar(10);
		// 	for(int i=nxt[0];i<=n;i=nxt[i])
		// 		printf("%d%c",f[i],i<n?32:10);
		// }
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 9ms
memory: 73432kb

input:

20
01001101101101110010

output:

2 11
5 5
4 5
11 1
4 2
7 1
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0

result:

ok 20 lines

Test #2:

score: 0
Accepted
time: 1415ms
memory: 161564kb

input:

1000000
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

1 1000000
-1 0
1 999998
-1 0
-1 0
-1 0
1 999995
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
1 999991
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
1 999986
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0...

result:

ok 1000000 lines

Test #3:

score: 0
Accepted
time: 1110ms
memory: 166372kb

input:

1000000
1111111101011101110011011111111111111110110011110111011100111001011011011110101110111111111111111111111111011111101111110110111111111110111010111111100110011101101110011111111101111110111111111110111111111111011011110110111101101101110101100111111111001010111111111111010111011111111011110111...

output:

1 800681
7 159535
1 641144
13 31730
5 127804
5 127761
1 513379
542 6405
25 25324
54 25337
5 102464
30 25561
17 102196
17 102484
1 410890
2647 1324
618 5080
20 5103
99 20219
304 4894
89 20442
21 20308
15 82150
810 5135
82 20422
158 20309
20 81880
83 20567
39 81909
40 82119
1 328769
4222 267
2829 1056...

result:

ok 1000000 lines

Test #4:

score: 0
Accepted
time: 1120ms
memory: 166340kb

input:

1000000
1101111101110111111111011101011111110111101001111110111111110100111111001011111011110011111011100111111111111111010001111110011010101111111111011100110111010101111111111111111110110111001101111111100111111011110111111111111111101111111110101010011111101110111111111111111111111101111110111111...

output:

1 800315
1 159901
1 640412
38 31850
3 128050
3 128165
1 512243
97 6369
45 25480
12 25565
8 102482
40 25580
13 102583
13 102460
1 409776
295 1288
274 5080
345 4929
39 20549
187 5053
73 20509
118 20499
14 81980
447 5084
39 20492
84 20487
17 82091
52 20447
16 82006
16 82071
1 327699
441 231
571 1056
28...

result:

ok 1000000 lines

Test #5:

score: 0
Accepted
time: 1117ms
memory: 165516kb

input:

1000000
1011101110000111111111111010111100111001110111111101111110010111011011101111111111111111011111111011111111111111110110111111111110111111001011111101110111111011111111111111111011110011111011111100011111110110111111110110111100111101111111111011111111111011110111101111101011111111111111111111...

output:

1 799990
4 159695
2 640293
4 32324
17 127370
2 127967
3 512321
177 6381
15 25942
244 25350
10 102018
11 25885
12 102077
15 102178
3 410139
2620 1289
753 5091
16 5090
134 20850
959 5103
279 20246
18 20591
20 81421
770 5138
79 20743
292 20352
31 81720
147 20754
34 81414
45 81806
3 328330
6959 252
3565...

result:

ok 1000000 lines

Test #6:

score: -100
Wrong Answer
time: 1113ms
memory: 165748kb

input:

1000000
1001011111111110110111110111100110111110111111111111111111111101110111010010110101111101101101111010100111110111111101111111111101001111101100100101111111111110010011111111100111111110110111101111111111101111111111111111111101111111111111010100001111110111100111011110101111111111111101111101...

output:

1 799378
3 160096
3 639280
24 32304
10 127791
9 127869
3 511407
225 6534
55 25770
57 25712
10 102073
48 25844
11 102022
12 102244
3 409159
808 1350
451 5183
95 5244
56 20525
78 5110
52 20603
41 20369
29 81699
941 5203
83 20637
66 20630
27 81387
70 20753
30 81486
30 81965
3 327185
7290 264
1512 1085
...

result:

wrong answer 524248th lines differ - expected: '-1 0', found: '466758 1'