QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#631159#5144. Set of Intervals999WA 8ms5956kbC++141.6kb2024-10-11 22:26:072024-10-11 22:26:07

Judging History

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

  • [2024-10-11 22:26:07]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:5956kb
  • [2024-10-11 22:26:07]
  • 提交

answer

#include<bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;++a)
#define Dor(a,b,c) for(int a=b;a>=c;--a)
#define CC(_...) fprintf(stderr,_)
using namespace std;
typedef long long LL;
const int N=200007;
int n,e,ml,sr,L[N],R[N],E[N],D[N],W[N],F[N];
void magic() {
	scanf("%d",&n);
	e=sr=0;
	For(i,1,n) {
		scanf("%d%d",&L[i],&R[i]);
		E[++e]=R[i],E[++e]=L[i]-1;
	}
	if(n==1) {
		puts("1");
		return;
	}
	sort(E+1,E+1+e),e=unique(E+1,E+1+e)-E-1;
	For(i,1,e) D[i]=W[i]=F[i]=0;
	F[e]=E[e];
	For(i,1,n) {
		int l=lower_bound(E+1,E+1+e,L[i]-1)-E;
		int r=lower_bound(E+1,E+1+e,R[i])-E;
		if(r==e) ml=L[i];
		else sr=max(sr,R[i]);
		D[l+1]++,D[r+1]--,W[r]++;
		F[l]=L[i]-1;
	}
	if(W[e]>1) sr=E[e];
	Dor(i,e,1) if(!F[i]) F[i]=F[i+1];
	LL ans=0;
	int p=0;
	For(i,2,e) {
		D[i]+=D[i-1];
		if(!D[i]) {
			if(p>=2&&p<=n-2) {
				ans+=1LL*(E[i]-E[i-1])*(E[i]-E[i-1]-1)/2;
				ans+=1LL*(E[i]-E[i-1])*(E[e]-E[i]);
			}
			else if(p==1&&n>=3) {
				int c=0,l=E[e];
				For(j,1,n) {
					if(L[j]>E[i]) {
						l=min(l,L[j]);
						++c;
					}
				}
				if(c>=3) ans+=1LL*(E[i]-E[i-1])*(E[e]-l);
				else {
					int s=0,d=D[i];
					For(j,i+1,e) if(d+=D[j]) s+=E[j]-E[j-1];
					ans+=1LL*(E[i]-E[i-1])*s;
				}
			}
		}
		else {
			if(D[i]>1||p&&i!=e) {
				ans+=1LL*(E[i]-E[i-1])*(E[i]-E[i-1]-1)/2;
				ans+=1LL*(E[i]-E[i-1])*(E[e]-E[i]);
			}
			else {
				int r=E[e];
				if(D[i]==1&&ml<=E[i]) {
					r=sr;
				}
				ans+=1LL*(E[i]-E[i-1])*max(0,r-F[i]);
			}
		}
		p+=W[i];
	}
	printf("%lld\n",ans);
}
int main() {
	int T; scanf("%d",&T);
	while(T--) magic();
	return 0;
}

詳細信息

Test #1:

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

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: 2ms
memory: 5880kb

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: 0
Accepted
time: 5ms
memory: 5828kb

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
113106465274673025
75195165925255965
5141989504048811
1256173734724260
207604390726385765
56483863859672889
37024984393194673
36132096841419954
22573394495301601
143688903920213372
166852999281224709
3932968549941246
63833225117266922
49459548807361176
70057738855...

result:

ok 10000 numbers

Test #4:

score: 0
Accepted
time: 7ms
memory: 5956kb

input:

10000
3
1 1000000000
521067549 666980062
562319713 714009993
3
42407212 75107815
610219669 973789020
873806856 902158965
3
1 1000000000
673648508 809445815
599994567 757240668
3
92939611 410549965
597447135 678622426
676819188 811525072
3
230740729 455081734
606008912 926990742
615223886 822068791
3...

output:

174329051362239765
269965111370246655
187516336041444375
122087055515083130
166464628402586213
303666532800970347
176358932288144970
330593156050995465
59827455776692524
247444999637419584
134334952548458322
199454344726240709
186982464464105447
274043263510447662
200274422590053105
2387307446491590...

result:

ok 10000 numbers

Test #5:

score: -100
Wrong Answer
time: 8ms
memory: 5908kb

input:

10000
4
1 1000000000
10072295 202681835
541668966 608745666
552976904 565764167
4
2825267 24347784
40987434 217972832
805197125 991276445
661928934 813950270
4
134841372 295761427
396522424 401387669
700936283 822533151
684880705 891949933
4
211151840 381825097
582143597 671077771
502785782 73287089...

output:

419468468529738122
472067404564990696
249958855713556448
141269847836096195
462920441405890245
470908383701333985
217198901923717178
491757841228436784
463134981388354119
469535771775776550
456342968477934315
488107381636243122
152242735892791526
221437298433110155
481438730537131050
477662426236416...

result:

wrong answer 2nd numbers differ - expected: '472067404581630345', found: '472067404564990696'