QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#21821 | #2831. Game Theory | LFCode# | WA | 62ms | 14032kb | C++14 | 2.4kb | 2022-03-08 16:17:12 | 2022-05-08 04:07:04 |
Judging History
answer
#include<bits/stdc++.h>
#include<cstdio>
#include<cctype>
#define ll long long
#define PI pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define ui unsigned int
#define pb push_back
#define llu long long unsigned
using namespace std;
const int MB=1<<20;
struct FastIO{
char ib[MB+100],*p,*q;
char ob[MB+100],*r,stk[128];
int tp;
FastIO(){p=q=ib,r=ob,tp=0;}
~FastIO(){fwrite(ob,1,r-ob,stdout);}
char read_char(){if(p==q){p=ib,q=ib+fread(ib,1,MB,stdin);if(p==q)return 0;}return *p++;}
template<typename T>
void read_int(T& x){char c=read_char(),l=0;for(x=0;!isdigit(c);c=read_char())l=c;for(;isdigit(c);c=read_char())x=x*10-'0'+c;if(l=='-')x=-x;}
void write_char(char c){if(r-ob==MB)r=ob,fwrite(ob,1,MB,stdout);*r++=c;}
template<typename T>
void write_int(T x){if(x<0)write_char('-'),x=-x;do stk[++tp]=x%10+'0';while(x/=10);while(tp)write_char(stk[tp--]);}
}IO;
//IO.read_int(a);c=IO.read_char();IO.write_int(a);//IO.write_char(c);
const int N=200010;
int T,n,q,a[N];
char ch[N];
ll ans1[N<<2],ans2[N<<2],ans3[N<<2],ans4[N<<2],tag[N<<2];
int ls(int x){
return x<<1;
}
int rs(int x){
return x<<1|1;
}
void push_up(int p){
ans1[p]=min(ans1[ls(p)],ans1[rs(p)]);
ans4[p]=min(ans4[ls(p)],ans4[rs(p)]);
ans2[p]=ans2[ls(p)]+ans2[rs(p)];
ans3[p]=ans3[ls(p)]+ans3[rs(p)];
}
void f(int p,int l,int r){
ans2[p]=(r-l+1)-ans2[p];
ans3[p]=(l+r)*1ll*(r-l+1)-ans3[p];
swap(ans1[p],ans4[p]);
tag[p]^=1;
}
void push_down(int p,int l,int r){
if(tag[p]==0)return ;
int mid=(l+r)>>1;
f(ls(p),l,mid);
f(rs(p),mid+1,r);
tag[p]=0;
}
/*
l + l+1 +l+2 +... r
*/
void build(int p,int l,int r){
tag[p]=0;
if(l==r){
ans1[p]=n+1;
ans4[p]=n+1;
ans2[p]=(ch[l]=='1');
ans3[p]=ans2[p]*l*2;
if(ch[l]=='1')ans1[p]=l;
else ans4[p]=l;
return ;
}
int mid=(l+r)>>1;
build(ls(p),l,mid);
build(rs(p),mid+1,r);
push_up(p);
}
void update(int nl,int nr,int l,int r,int p){
if(nl<=l&&r<=nr){
f(p,l,r);
return ;
}
push_down(p,l,r);
int mid=(l+r)>>1;
if(nl<=mid)update(nl,nr,l,mid,ls(p));
if(mid+1<=nr)update(nl,nr,mid+1,r,rs(p));
push_up(p);
}
int main(){
// scanf("%d",&T);
// T=1;
while(scanf("%d",&n)!=EOF){
scanf("%d",&q);
scanf("%s",ch+1);
build(1,1,n);
for(int i=1;i<=q;i++){
int l,r;
scanf("%d%d",&l,&r);
update(l,r,1,n,1);
printf("%lld\n",ans3[1]-ans2[1]*(ans2[1])-((ans1[1]==n+1)?0:ans1[1]-1));
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 13888kb
input:
3 2 010 1 2 2 3 5 1 00000 1 5
output:
1 3 5
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 5ms
memory: 14024kb
input:
1 1 0 1 1
output:
1
result:
ok single line: '1'
Test #3:
score: -100
Wrong Answer
time: 62ms
memory: 14032kb
input:
2 2 01 2 2 2 2 2 2 01 1 2 1 2 1 2 1 1 1 1 1 1 2 1 1 1 1 1 2 2 00 1 2 1 2 2 2 11 1 2 1 2 2 2 01 2 2 1 1 2 2 10 2 2 1 2 2 2 01 1 2 1 2 1 2 0 1 1 1 1 2 2 01 1 2 2 2 1 2 0 1 1 1 1 1 2 1 1 1 1 1 2 2 10 1 2 1 1 1 2 0 1 1 1 1 2 2 01 1 2 1 2 2 2 10 1 2 1 1 1 2 0 1 1 1 1 1 2 0 1 1 1 1 1 2 1 1 1 1 1 2 2 10 1 ...
output:
0 2 1 2 0 1 0 1 2 0 0 2 0 1 2 0 1 2 1 0 1 2 1 0 0 1 2 2 1 0 1 2 2 2 1 0 1 0 0 1 0 1 0 2 2 1 0 1 2 1 1 0 2 0 2 2 1 0 0 1 2 0 0 1 0 1 0 1 1 0 1 2 2 0 0 2 0 1 0 1 1 0 1 0 1 0 0 1 0 1 0 1 2 0 2 0 1 0 0 1 1 0 1 0 1 2 0 2 1 0 0 2 1 2 0 1 2 2 1 0 0 1 2 0 2 0 0 1 0 1 1 0 1 0 1 0 1 0 1 2 1 0 2 1 0 2 0 1 0 1 ...
result:
wrong answer 2nd lines differ - expected: '3', found: '2'