QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#775451#9786. Magical Bagsucup-team5697#WA 9ms47996kbC++141.7kb2024-11-23 15:57:152024-11-23 15:57:15

Judging History

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

  • [2024-11-23 15:57:15]
  • 评测
  • 测评结果:WA
  • 用时:9ms
  • 内存:47996kb
  • [2024-11-23 15:57:15]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;bool Mbe;
namespace MAOJUN{

typedef pair<int,int> pi;
const int N=4e5+5;
int n,V=0,d[N],s[N];

pi a[N];bool vs[N],L[N],R[N];
#define fi first
#define se second
vector<int>v1[N],v2[N],q1[N],q2[N];
int tr[N];
inline void U(int p){for(;p<=V;p+=p&-p)tr[p]++;}
inline int Q(int l,int r){int x=0;for(l--;r>l;r&=r-1)x+=tr[r];for(;l>r;l&=l-1)x-=tr[l];return x;}
inline void main(){
	scanf("%d",&n);
	int sum=0;
	for(int i=1,k,x;i<=n;i++){
		scanf("%d",&k);
		int l=1e9,r=0;
		while(k--){scanf("%d",&x);l=min(l,x);r=max(r,x);}
		a[i]=pi(l,r);
		d[++V]=l;if(l!=r)d[++V]=r;
	}
	sum=V;
	sort(d+1,d+V+1);
	for(int i=1;i<=n;i++){
		a[i].fi=lower_bound(d+1,d+V+1,a[i].fi)-d;
		a[i].se=lower_bound(d+1,d+V+1,a[i].se)-d;
	}
	sort(a+1,a+n+1,[&](pi x,pi y){return x.fi^y.fi?x.fi>y.fi:x.se<y.se;});
	int mn=1e9+1,m=0;
	for(int i=1;i<=n;i++)
		if(a[i].se<mn){
			mn=a[i].se;
			if(a[i].fi!=a[i].se)a[++m]=a[i];
		}else{
			v1[a[i].fi].emplace_back(a[i].se);
			v2[a[i].se].emplace_back(a[i].fi);
		}
	n=m;sort(a+1,a+n+1);
	for(int i=1;i<=n;i++){
		q1[a[i].fi].emplace_back(i);
		q2[a[i].se].emplace_back(i);
	}
	for(int i=1;i<=V;i++){
		for(int j:v1[i])U(j);
		for(int j:q1[i])L[j]=!Q(a[j].fi,a[j].se);
	}
	memset(tr,0,sizeof tr);
	for(int i=V;i;i--){
		for(int j:v2[i])U(j);
		for(int j:q2[i])R[j]=!Q(a[j].fi,a[j].se);
	}
	for(int i=1,j;i<=n;i=j+1){
		for(j=i;j<n&&a[j+1].fi<a[j].se;)j++;
		if(L[i]&&R[j]&&a[j].fi>a[i].se)sum-=2;
		else sum-=L[i]||R[j];
	}
	printf("%d\n",sum);
}

}bool Med;int main(){
#ifdef LOCAL
	freopen("1.in","r",stdin);
	freopen("data.out","w",stdout);
	atexit([](){fprintf(stderr,"%dms\n%lfMB\n",clock(),(&Mbe-&Med)/1024./1024);});
#endif
	MAOJUN::main();
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 4ms
memory: 47224kb

input:

4
3 4 7 10
2 1 9
4 11 2 8 14
3 6 12 13

output:

7

result:

ok 1 number(s): "7"

Test #2:

score: 0
Accepted
time: 0ms
memory: 46220kb

input:

4
1 1
1 2
1 3
1 4

output:

4

result:

ok 1 number(s): "4"

Test #3:

score: 0
Accepted
time: 9ms
memory: 47712kb

input:

4
3 4 7 10
2 1 9
4 11 2 8 14
3 6 12 13

output:

7

result:

ok 1 number(s): "7"

Test #4:

score: 0
Accepted
time: 4ms
memory: 47996kb

input:

4
1 1
1 2
1 3
1 4

output:

4

result:

ok 1 number(s): "4"

Test #5:

score: -100
Wrong Answer
time: 4ms
memory: 47820kb

input:

100
4 372861091 407948190 424244630 359746969
6 568180757 527358812 494745349 665803213 674832670 586694351
4 696340797 775899164 919971335 716827187
4 123145962 344250363 122030550 251739234
4 342654413 368648894 150539766 255189030
1 194505887
3 755984448 736803561 745474041
4 709314938 498953418 ...

output:

178

result:

wrong answer 1st numbers differ - expected: '177', found: '178'