QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#371528 | #244. Turn Off The Light | QOJ114514ancestor | 0 | 175ms | 14016kb | C++14 | 1.8kb | 2024-03-30 13:44:08 | 2024-03-30 13:44:08 |
Judging History
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));
// clog<<c1<<' '<<c2<<'\n';
return min(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;
cout<<ans<<'\n';
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
cin>>T;
while(T--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 175ms
memory: 14016kb
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 3 6 6 0 12 2 12 12 24 12 26 0 32 14 36 6 40 20 38 23 60 40 58 24 62 42 60 0 67 39 66 21 80 50 83 15 90 60 93 34 87 57 80 41 120 90 123 64 117 87 110 42 123 93 120 67 118 88 129 0 121 81 126 51 128 86 125 33 150 108 147 70 153 111 152 31 168 126 165 88 171 129 170 54 165 123 168 85 154 112 159 68 2...
result:
wrong answer 2nd lines differ - expected: '5', found: '3'