QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#133407#4935. Exchange BottleneckPlentyOfPenalty#WA 13ms10588kbC++201.1kb2023-08-02 09:09:292023-08-02 09:09:31

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-02 09:09:31]
  • 评测
  • 测评结果:WA
  • 用时:13ms
  • 内存:10588kb
  • [2023-08-02 09:09:29]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+9;
int n,m,b[N];
struct segment{
	int l,r,mid;
	int min,max;
}p[N<<2];
void build(int u,int l,int r){
	p[u].l=l,p[u].r=r,p[u].mid=(l+r)>>1;
	p[u].min=INT_MAX;
	if(l==r){
		return;
	}
	build(u<<1,l,p[u].mid);
	build(u<<1|1,p[u].mid+1,r);
}
void update(int u,int k,int x){
	if(p[u].l==p[u].r){
		p[u].min=x;
		return;
	}
	if(k<=p[u].mid){
		update(u<<1,k,x);
	}else{
		update(u<<1|1,k,x);
	}
	p[u].min=min(p[u<<1].min,p[u<<1|1].min);
}
int query(int u,int l,int r){
	if(p[u].l==l&&p[u].r==r)return p[u].min;
	if(r<=p[u].mid)return query(u<<1,l,r);
	if(l>p[u].mid)return query(u<<1|1,l,r);
	return min(query(u<<1,l,p[u].mid),query(u<<1|1,p[u].mid+1,r));
}
int main(){
#ifdef memset0
	freopen("E.in","r",stdin);
#endif
	ios::sync_with_stdio(0),cin.tie(0);
	cin>>n;
	build(1,1,n);
	update(1,1,0);
	int ans=0;
	for(int i=2;i<=n;i++){
		cin>>b[i];
		int x=-1;
		if(b[i]){
			x=query(1,1,i-1);
		}else{
			x=query(1,i-1,i-1);
		}
		update(1,i,x+1);
		ans=max(ans,x+1);
		// cerr<<i<<" "<<x+1<<endl;
	}
	cout<<ans<<endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5464kb

input:

5
1 0 1 0

output:

2

result:

ok single line: '2'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3604kb

input:

7
1 1 1 1 1 1

output:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 2ms
memory: 5588kb

input:

2
0

output:

1

result:

ok single line: '1'

Test #4:

score: -100
Wrong Answer
time: 13ms
memory: 10588kb

input:

90580
1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 1 1 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 0 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 ...

output:

5

result:

wrong answer 1st lines differ - expected: '2', found: '5'