QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#106417#6308. MagicPure_FuriesWA 3ms8776kbC++141.8kb2023-05-17 18:13:172023-05-17 18:13:21

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-17 18:13:21]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:8776kb
  • [2023-05-17 18:13:17]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int T[300003],HD[110003],nn,nxt[300003],n,C[300003]; 
void add_edge(int f,int t,int c){
	T[nn]=t;C[nn]=1;nxt[nn]=HD[f];HD[f]=nn++;
	T[nn]=f;C[nn]=0;nxt[nn]=HD[t];HD[t]=nn++;
}
int dis[110003],I[110003],Q[110003],SS,TT;
void bfs(int x){
	memset(dis,-1,sizeof(dis));
	SS=0;TT=0;Q[0]=x;dis[x]=0;
	while(SS<=TT){
		x=Q[SS++];
		for(int i=HD[x];~i;i=nxt[i])
			if(C[i]&&dis[T[i]]==-1)
				dis[T[i]]=dis[x]+1,
				Q[++TT]=T[i];
		if(~dis[n+n+1])break;
	}
}
bool dfs(int x,int t){
	if(x==t)return 1;
	for(int &i=I[x];~i;i=nxt[i])
		if(C[i^1]&&dis[T[i]]==dis[x]-1){
			bool d=dfs(T[i],t);
			if(d){
				C[i]++;
				C[i^1]--;
				return 1;
			}
		}
	return 0;
}
int flow(int s,int t){
	int ret=0;
	while(1){
		memcpy(I,HD,sizeof(I));
		bfs(s);
		if(dis[t]==-1)
			break;
		while(dfs(t,s))ret++;
	}return ret;
}
int ls[100003],rs[100003],N,rt;
int l[5003],r[5003];
void newnode(int &k){
	ls[++N]=ls[k];
	rs[N]=rs[k];
	add_edge(k+(n+1<<1),N+(n+1<<1),1e9);
	k=N;
}
void add(int &k,int _l,int _r,int p,int i){
	newnode(k);
	add_edge(i,k+(n+1<<1),1e9);
	if(_l==_r)return;
	if(p<=(_l+_r>>1))
		add(ls[k],_l,_l+_r>>1,p,i);
	else
		add(rs[k],_l+_r+2>>1,_r,p,i);
}
void query(int k,int _l,int _r,int l,int r,int i){
	if(l>_r||r<_l||!k)return;
	if(l<=_l&&_r<=r){add_edge(k+(n+1<<1),i,1e9);return;}
	query(ls[k],_l,_l+_r>>1,l,r,i);
	query(rs[k],_l+_r+2>>1,_r,l,r,i);
}
bool cmp(int i,int j){return l[i]<l[j];}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	memset(HD,-1,sizeof(HD));
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>l[i]>>r[i];
		l[i]--;r[i]--;I[i]=i;
		add_edge(n<<1,i,1);
		add_edge(i+n,n<<1|1,1);
	}sort(I,I+n,cmp);
	for(int i=0;i<n;i++){
		query(rt,0,n+n-1,l[I[i]],r[I[i]],i+n);
		add(rt,0,n+n-1,r[I[i]],i);
	}
	cout<<n+n-flow(n<<1,n<<1|1);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 8060kb

input:

5
2 3
6 7
1 9
5 10
4 8

output:

9

result:

ok 1 number(s): "9"

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 8776kb

input:

5000
7985 7987
42 46
1591 1593
407 410
6305 6306
1456 1457
5874 5875
7135 7137
7041 7046
6813 6815
8868 8871
665 666
4055 4056
9789 9796
7067 7068
4745 4746
5167 5171
1735 1737
2125 2128
1444 1447
1348 1352
6087 6090
1381 1384
1600 1601
5187 5190
2801 2802
8449 8450
9376 9377
4021 4024
2674 2676
490...

output:

0

result:

wrong answer 1st numbers differ - expected: '8134', found: '0'