QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#371539#244. Turn Off The LightQOJ114514ancestor0 455ms14100kbC++141.9kb2024-03-30 13:50:042024-03-30 13:50:17

Judging History

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

  • [2024-03-30 13:50:17]
  • 评测
  • 测评结果:0
  • 用时:455ms
  • 内存:14100kb
  • [2024-03-30 13:50:04]
  • 提交

answer

//tomorin
#include<bits/stdc++.h>
#define int long long
#define N 1000005
#define MOD 1000000007
#define P(x) px[x]
#define Q(x) (px[x]^((x)&1))
#define S(x) (px[(x)-1]^px[n])
#define len (rr-ll+1)
#define cntP (sp[rr]-sp[ll-1])
#define cntQ (sq[rr]-sq[ll-1])
#define cc(ll,rr,P,c1,v) if(ll<=rr){if(P(x-v)^nw)c1+=(len-cnt##P)*2;else c1+=cnt##P*2;nw=P(v?ll:rr)^P(x-v)^nw,x=v?(ll+1):rr;}
using namespace std;
int T,n,L,R;string s;
bool a[N],px[N];
signed sp[N],sq[N];
int calc(int st){
	int l=L,r=R,c1,c2,x,nw,ll,rr;
	if(st==1&&r==1||st==n&&l==n)return 3;
	if(st<l)l=st+1;
	if(st>r)r=st-1;
	x=st,c1=0;
	x=max(st,r),nw=a[x]^(x>st),c1=max(r-st,0ll)+x-l-1+nw*2;
	// i in [max(l,st),x-2],?cnt:P(i)^P(x-1)^nw
	ll=max(l,st),rr=x-2;cc(ll,rr,P,c1,1)
	// while(x>max(l+1,st+1))--x,nw=nw^a[x],c1+=nw*2;
	// cout<<nw<<' '<<x<<'\n';
	// i in [l,x-2],?cnt:Q(i)^Q(x-1)^nw
	ll=l,rr=x-2;cc(ll,rr,Q,c1,1)
	while(x>l+1)--x,nw=nw^a[x]^1,c1+=nw*2;//max(l,st)+1->l+1
	c1+=(nw^a[l]^(l>st));
	x=min(st,l),nw=a[x]^(x<st),c2=max(st-l,0ll)+r-1-x+nw*2;
	// i in [x+1,min(r,st)-1],?cnt:P(x)^P(i)^nw
	ll=x+1,rr=min(r,st)-1;cc(ll,rr,P,c2,0)
	// if(ll<=rr){if(P(x)^nw)c2+=(len-cntP)*2;else c2+=cntP*2;nw=P(rr)^P(x)^nw,x=rr;}
	// while(x<min(r-1,st-1))++x,nw=nw^a[x],c2+=nw*2;
	// i in [x+1,r-1],?cnt:Q(x)^Q(i)^nw
	ll=x+1,rr=r-1;cc(ll,rr,Q,c2,0)
	// while(x<r-1)++x,nw=nw^a[x]^1,c2+=nw*2;
	c2+=(nw^a[r]^(r<st));
	return max(c1,c2);
}
void solve(){
	cin>>n>>s;int ans=L=R=0;
	for(int i=1;i<=n;i++){
		a[i]=(s[i-1]=='1');
		if(a[i]&&!L)L=i;
		if(a[i])R=i;
	}
	for(int i=1;i<=n;i++)
		px[i]=px[i-1]^a[i],
		sp[i]=sp[i-1]+P(i),
		sq[i]=sq[i-1]+Q(i);
	if(L)for(int i=1;i<=n;i++)
		ans=(ans+calc(i)*i)%MOD,clog<<calc(i)<<' ';
	cout<<ans<<'\n';
}
signed main(){
	// freopen("light.in","r",stdin);
	// freopen("light.out","w",stdout);
	cin.tie(0)->sync_with_stdio(0);
	cin>>T;
	while(T--)solve();
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 455ms
memory: 14100kb

input:

146645
2
00
2
10
2
01
2
11
3
000
3
100
3
010
3
110
3
001
3
101
3
011
3
111
4
0000
4
1000
4
0100
4
1100
4
0010
4
1010
4
0110
4
1110
4
0001
4
1001
4
0101
4
1101
4
0011
4
1011
4
0111
4
1111
5
00000
5
10000
5
01000
5
11000
5
00100
5
10100
5
01100
5
11100
5
00010
5
10010
5
01010
5
11010
5
00110
5
10110
5...

output:

0
5
7
6
0
14
6
12
14
24
12
26
0
34
18
36
12
40
20
54
26
60
40
74
24
66
46
80
0
69
43
86
27
80
50
99
23
90
60
129
34
111
81
120
45
120
90
159
64
141
111
150
46
135
105
168
75
150
120
153
0
123
85
170
57
152
110
165
41
150
108
207
70
177
135
192
41
168
126
249
88
219
177
210
58
201
159
240
117
210
168...

result:

wrong answer 7th lines differ - expected: '10', found: '6'