QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#185369#5144. Set of IntervalsPhantomThreshold#WA 27ms3788kbC++202.3kb2023-09-21 22:07:152023-09-21 22:07:15

Judging History

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

  • [2023-09-21 22:07:15]
  • 评测
  • 测评结果:WA
  • 用时:27ms
  • 内存:3788kb
  • [2023-09-21 22:07:15]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	int T;
	cin>>T;
	while(T--)
	{
		int n;
		cin>>n;
		vector<tuple<int,int,int>> a,b;
		for(int i=1;i<=n;i++)
		{
			int l,r;
			cin>>l>>r;
			a.emplace_back(l,r,i);
		}
		if(n==1)
		{
			cout<<1<<endl;
			continue;
		}
		const int MAGIC=4;
		sort(a.begin(),a.end(),[&](const auto &x,const auto &y){return get<0>(x)<get<0>(y);});
		for(int i=0;i<min(MAGIC,n);i++)b.push_back(a[i]);
		sort(a.begin(),a.end(),[&](const auto &x,const auto &y){return get<1>(x)<get<1>(y);});
		for(int i=0;i<min(MAGIC,n);i++)b.push_back(a[i]);
		sort(b.begin(),b.end());
		b.resize(unique(b.begin(),b.end())-b.begin());
		vector<int> events;
		for(int i=0;i<(int)b.size();i++)
		{
			events.push_back(get<0>(b[i]));
			events.push_back(get<1>(b[i])+1);
			get<2>(b[i])=i;
		}
		int szb=b.size();
		auto check=[&](int x,int y)
		{
			for(int a1=0;a1<szb;a1++)
			{
				if(get<0>(b[a1])<=x and x<=get<1>(b[a1]))
				{
					for(int b1=0;b1<szb;b1++)
					{
						if(a1!=b1 and get<0>(b[b1])<=y and y<=get<1>(b[b1]))
							return true;
						if(a1!=b1 and get<0>(b[b1])<=y)
						{
							for(int b2=0;b2<szb;b2++)
							{
								if(a1!=b2 and y<=get<1>(b[b2]))
									return true;
							}
						}
					}
				}
				if(get<0>(b[a1])<=x)
				{
					for(int a2=0;a2<szb;a2++)
					{
						if(a1!=a2 and x<=get<1>(b[a2]))
						{
							for(int b1=0;b1<szb;b1++)
							{
								if(a1!=b1 and a2!=b1 and get<0>(b[b1])<=y and y<=get<1>(b[b1]))
									return true;
								if(a1!=b1 and a2!=b1 and get<0>(b[b1])<=y)
								{
									for(int b2=0;b2<szb;b2++)
									{
										if(a1!=b2 and a2!=b2 and y<=get<1>(b[b2]))
											return true;
									}
								}
							}
						}
					}
				}
			}
			return false;
		};
		sort(events.begin(),events.end());
		events.resize(unique(events.begin(),events.end())-events.begin());
		int sz=events.size();
		long long ans=0;
		for(int i=0;i+1<sz;i++)
		{
			int li=events[i],ri=events[i+1]-1;
			for(int j=i;j+1<sz;j++)
			{
				int lj=events[j],rj=events[j+1]-1;
				if(check(li,lj))
				{
					if(i==j)
						ans+=1ll*(ri-li+1)*(ri-li)/2;
					else
						ans+=1ll*(ri-li+1)*(rj-lj+1);
				}
			}
		}
		cout<<ans<<"\n";
	}
	
	return 0;
}

详细

Test #1:

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

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: 9ms
memory: 3788kb

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

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: 3772kb

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: 0
Accepted
time: 18ms
memory: 3636kb

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
472067404581630345
249958855814317444
141269847957056879
462920441405890245
470908383701333985
217198902062578400
491757841228436784
463134981388354119
469535771775776550
456342968477934315
488107381636243122
152242736076698604
221437298614345742
481438730537131050
477662426236416...

result:

ok 10000 numbers

Test #6:

score: -100
Wrong Answer
time: 27ms
memory: 3500kb

input:

10000
5
1 1000000000
58885552 222348761
653224442 875794028
782748888 908948156
729989823 904558984
5
1 1000000000
154439740 255994676
527167448 918981258
945176657 968197828
538331560 799069409
5
115868506 237575430
265858274 458701633
617598986 897974926
614297267 701594502
873895258 994959335
5
1...

output:

488759388365275685
482656974886654995
275314125949289706
398554690679225045
430182531288241947
488613112689238710
184307169357649442
416910021803580597
457140396280870475
498893543411199200
363370900749230015
485068887761019144
200128617859733066
342870798621426864
496887077905699922
323951756389276...

result:

wrong answer 3rd numbers differ - expected: '370448890332099571', found: '275314125949289706'