QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#198901#5144. Set of Intervals275307894aWA 5ms5860kbC++142.1kb2023-10-03 18:29:202023-10-03 18:29:20

Judging History

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

  • [2023-10-03 18:29:20]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:5860kb
  • [2023-10-03 18:29:20]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar() 
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=2e5+5,M=N*60+5,K=600+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=2e9+7;mt19937 rnd(263082);
int n,A[N],B[N],Ns[N],Nh,g[N],w[N];
int flag[9][9],vis[5];
void dfs(int ww){
	if(ww==n) {for(int i=1;i<=n;i++) if(!vis[i]) flag[A[i]][B[i]]=1;return;}
	for(int i=1;i<=n;i++)if(!vis[i]){
		for(int j=i+1;j<=n;j++) if(!vis[j]){
			int a=A[i],b=B[i];vis[j]=1;
			for(int x=A[i];x<=B[i];x++) for(int y=A[j];y<=B[j];y++) if(x<=y) A[i]=x,B[i]=y,dfs(ww+1),A[i]=a,B[i]=b;
			vis[j]=0;
		}
	}
}
void Solve(){
	int i,j;scanf("%d",&n);
	for(i=1;i<=n;i++) scanf("%d%d",&A[i],&B[i]);if(n==1){puts("1");return;}
	Nh=0;for(i=1;i<=n;i++) Ns[++Nh]=A[i],Ns[++Nh]=B[i]+1;
	sort(Ns+1,Ns+Nh+1);Nh=unique(Ns+1,Ns+Nh+1)-Ns-1;
	for(i=1;i<=n;i++) A[i]=LB(Ns+1,Ns+Nh+1,A[i])-Ns,B[i]=LB(Ns+1,Ns+Nh+1,B[i]+1)-Ns-1;
	fill(g+1,g+Nh+1,0);for(i=1;i<=n;i++) g[A[i]]++,g[B[i]+1]--;
	for(i=1;i<=Nh;i++) g[i]+=g[i-1];Nh--;for(i=1;i<=Nh;i++) w[i]=Ns[i+1]-Ns[i];
	if(n>4){
		ll ans=0;for(i=1;i<=Nh;i++) ans+=w[i];
		ans=ans*(ans-1)/2;
		ll s=0;if(g[1]==1) {s=w[1];if(!g[2]) s+=w[2];}ans-=1ll*s*(s-1)/2;
		s=0;if(g[Nh]==1) {s=w[Nh];if(!g[Nh-1]) s+=w[Nh-1];}ans-=1ll*s*(s-1)/2;
		if(g[1]==1&&g[Nh]==1){
			int flag=0;for(i=1;i<=n;i++) if(A[i]==1&&B[i]==Nh) {flag=1;break;}
			if(flag) ans-=1ll*w[1]*w[Nh];
		}
		printf("%lld\n",ans);return;
	}
	Me(flag,0);
	dfs(1);
	ll ans=0;for(i=1;i<=Nh;i++) {
		if(flag[i][i]) ans+=1ll*w[i]*(w[i]-1)/2;
		for(j=i+1;j<=Nh;j++) if(flag[i][j]) ans+=1ll*w[i]*w[j];
	}
	printf("%lld\n",ans);
}
int main(){
	int t=1;
	scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 5860kb

input:

4
1
1 1000000000
2
1 1000000000
1 1000000000
4
1 2
3 4
5 6
7 8
4
1 3
2 4
5 8
6 7

output:

1
499999999500000000
26
28

result:

ok 4 number(s): "1 499999999500000000 26 28"

Test #2:

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

input:

10000
1
778216842 910688403
1
513404058 890988011
1
1 1000000000
1
1 1000000000
1
758932694 848837772
1
516433381 715411928
1
1 1000000000
1
1 1000000000
1
1 1000000000
1
1 1000000000
1
1 1000000000
1
652548522 898071173
1
1 1000000000
1
509357508 603420032
1
1 1000000000
1
657294869 887475066
1
1 1...

output:

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
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
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
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
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
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
...

result:

ok 10000 numbers

Test #3:

score: -100
Wrong Answer
time: 5ms
memory: 5852kb

input:

10000
2
427286995 863604876
582970459 874563920
2
181948005 565025282
799528580 848659925
2
1 1000000000
716032287 836380611
2
383809946 544540272
520881396 990456979
2
156308569 178412791
731100211 963724967
2
426113388 802990296
556666621 560014605
2
1 1000000000
575838571 811122140
2
255734272 64...

output:

87849603321470913
18821102290156188
93415145870999600
75195165925255965
5141989504048811
442694765891625
163164533531625565
56483863859672889
37024984393194673
36132096841419954
13344950918059726
96344716027188244
141071338084326444
3932968549941246
63833225117266922
49459548807361176
70057738855053...

result:

wrong answer 3rd numbers differ - expected: '113106465274673025', found: '93415145870999600'