QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#21318#2822. 不等式glory_to_the_qy#AC ✓992ms68088kbC++203.0kb2022-03-04 15:16:232022-05-08 02:52:32

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-08 02:52:32]
  • 评测
  • 测评结果:AC
  • 用时:992ms
  • 内存:68088kb
  • [2022-03-04 15:16:23]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<vector>
#include<queue>
#include<algorithm>
#include<string>
#include<sstream>
#include<cctype>
#include<cmath>
#include<iomanip>
#include<map>
#include<stack>
#include<set>
#include<functional>
#define in(x) x=read()
#define qr read()
#define int ll
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
namespace fastIO
{
    #define BUF_SIZE 100000
    bool IOerror=0;
    inline char nc()
	{
        static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE;
        if (p1==pend){
            p1=buf; pend=buf+fread(buf,1,BUF_SIZE,stdin);
            if (pend==p1){IOerror=1;return -1;}
        }
        return *p1++;
    }
    inline bool blank(char ch){return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';}
    inline ll read()
	{
        bool sign=0; char ch=nc();ll x=0;
        for (;blank(ch);ch=nc());
        if (IOerror)return 0;
        if (ch=='-')sign=1,ch=nc();
        for (;ch>='0'&&ch<='9';ch=nc())x=x*10+ch-'0';
        if (sign)x=-x;
        return x;
    }
    #undef BUF_SIZE
};
using namespace fastIO;
int a[2000020],b[2000020];
struct node
{
	int x,y;
	// long double x;
	int id;
}p[2000020];
bool cmp(node p1,node p2)
{
	return p1.x*p2.y<p2.x*p1.y;
	// return p1.x<p2.x;
}
struct line
{
	int k=0,b=0;
	line(){}
	line(int kk,int bb){k=kk,b=bb;}
}c[2000020];
line operator + (line a,line b){return line(a.k+b.k,a.b+b.b);}
int c2[2000020],pos[2000020];
void add(int nl,int nr,int l,int r,int k,int b,int x)
{
	if(l<=nl&&nr<=r)
	{
		c[x].k+=k;
		c[x].b+=b;
		return;
	}
	int mid=(nl+nr)/2;
	if(l<=mid)add(nl,mid,l,r,k,b,x<<1);
	if(r>mid)add(mid+1,nr,l,r,k,b,x<<1|1);
}
void add2(int l,int r,int p,int v,int x)
{
	c2[x]+=v;
	if(l==r)return;
	int mid=(l+r)/2;
	if(p<=mid)add2(l,mid,p,v,x<<1);
	else add2(mid+1,r,p,v,x<<1|1);
}
line query(int l,int r,int p,int x)
{
	line ans=c[x];
	if(l==r)return ans;
	int mid=(l+r)/2;
	if(p<=mid)ans=ans+query(l,mid,p,x<<1);
	else ans=ans+query(mid+1,r,p,x<<1|1);
	return ans;
}
int find(int l,int r,int v,int x)
{
	if(l==r)return l;
	int mid=(l+r)/2;
	if(c2[x<<1]<v)return find(mid+1,r,v-c2[x<<1],x<<1|1);
	else return find(l,mid,v,x<<1);
}
signed main()
{
	// freopen("i.in","r",stdin);
	// freopen("i.out","w",stdout);
	int n=qr;
	for(int i=1;i<=n;i++)in(a[i]);
	for(int i=1;i<=n;i++)in(b[i]);
	for(int i=1;i<=n;i++)
	{
		if(a[i]<0)a[i]*=-1,b[i]*=-1;
		if(a[i]!=0)p[i]=(node){-b[i],a[i],i};
		else p[i]=(node){0,1,i};
	}
	sort(p+1,p+1+n,cmp);
	for(int i=1;i<=n;i++)
	{
		pos[p[i].id]=i;
	}
	int sum=0,ad=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]==0)ad+=abs(b[i]);
		else
		{
			sum+=a[i];
			add(1,n+1,1,pos[i],-a[i],-b[i],1);
			add(1,n+1,pos[i]+1,n+1,a[i],b[i],1);
			add2(1,n+1,pos[i],a[i],1);
		}
		int pp=find(1,n+1,(sum+1)/2,1);
		line now=query(1,n+1,pp,1);
		printf("%.8f\n",abs(now.k*(1.0*p[pp].x/p[pp].y)+now.b+ad));
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 15ms
memory: 35460kb

input:

1000
61238 60248 73732 -26564 -93007 4478 -39783 -29386 6714 -96099 58853 29344 88517 -7643 -16343 97123 82004 96690 -63916 13672 -72104 -93128 -33526 4108 -5475 -53323 57787 15891 -9523 -10161 -96799 -83119 77140 97223 -56595 -95821 24758 73652 58307 -22694 -62422 2448 59087 -47128 67302 -53844 -61...

output:

0.00000000
21040.36748424
46739.80116921
118552.38717790
134885.29092434
138647.75621190
181413.09688518
262021.97248594
332218.48922124
448697.73650370
526654.98272315
604758.26702374
622459.03207159
625160.86508377
633787.79890868
654740.71916129
679518.08033462
721477.04651084
781941.45609318
792...

result:

ok 1000 numbers

Test #2:

score: 0
Accepted
time: 992ms
memory: 67932kb

input:

500000
72535 50164 -41705 -27256 99923 -47337 -84129 -19076 -28224 47616 20591 30941 35900 -30965 1834 -33114 62440 56631 -45421 84047 77094 -86440 30282 -60892 44910 89786 -566 -87476 60388 13980 63363 91246 10736 59064 7550 30290 -68811 73956 90454 6060 76719 -58321 66048 -6321 -39195 24249 -20336...

output:

0.00000000
60376.94023575
66670.53084762
164077.41409903
182310.20162680
183734.78403529
249323.81726768
322652.87507493
323189.07599915
351287.64262628
410937.41781270
460816.52990261
493996.43378330
550307.89969791
578503.94492680
601978.57889295
638641.18395758
676441.88346797
708724.77208968
710...

result:

ok 500000 numbers

Test #3:

score: 0
Accepted
time: 10ms
memory: 35508kb

input:

1000
-10425 -17041 36906 59558 -60841 -7805 31449 14104 85461 50561 11774 -20252 93500 58651 -57215 -37974 -19429 58555 63645 15237 90613 89871 78596 42579 -22620 64026 -81175 -38726 -49550 -32689 15165 92873 -16518 -83443 -59029 23471 -74111 -98979 -82859 -3338 -1030 83309 46000 3043 -78665 72668 -...

output:

0.00000000
29129.99190188
68274.97203707
225727.51341245
238356.06173469
295364.92508341
346368.60778094
431636.91382456
450419.46670472
471618.48976726
531798.94833608
637242.20677323
774871.32762446
829664.16243980
859853.69716145
902210.12613825
949635.05732762
992598.22728095
1071512.19234466
11...

result:

ok 1000 numbers

Test #4:

score: 0
Accepted
time: 2ms
memory: 36140kb

input:

1000
-61825 -50967 96854 79449 67720 25513 30223 -79637 -51388 -32693 83255 -24889 -65899 -12087 -68993 46694 -8115 34771 97971 95070 60311 -58812 7269 -48380 -11935 -58285 68563 76645 47700 -81487 12769 -85920 -51948 -60010 70982 -52948 2782 86662 -91091 86941 -90638 -29034 6669 53496 -37180 -31106...

output:

0.00000000
2790.11768702
26580.61749760
28434.70087729
31900.80853514
33196.37987892
72675.25924807
234209.46744452
296648.28091561
360573.08235075
361893.62327788
474454.22236502
629188.66388585
702715.57905714
827378.25818242
848383.00460487
871521.98511161
1003754.22161191
1110723.00623619
122904...

result:

ok 1000 numbers

Test #5:

score: 0
Accepted
time: 8ms
memory: 36884kb

input:

1000
64701 12956 98586 54145 -79377 8893 22728 62220 -94794 92406 71653 -43144 42708 -59000 -96943 -60145 18033 -77522 20852 -62583 -68415 6199 -77462 -77694 -36011 -80297 -94508 -33000 49541 -29509 -11838 78222 -28841 -66724 38255 -53453 30240 -13672 -22140 23630 43841 19604 64885 35473 -5664 -3885...

output:

0.00000000
54514.37240537
80128.40158846
141290.83650948
233404.28089210
269382.00234927
318600.40926724
319893.72172935
401340.74264695
451697.44516233
488304.90020129
566540.01473930
579573.36900201
580515.38049153
631295.81786897
707118.51923729
730376.37803390
735772.27542373
824388.94261017
883...

result:

ok 1000 numbers

Test #6:

score: 0
Accepted
time: 2ms
memory: 35952kb

input:

1000
48175 12749 -61459 39318 87673 84688 53381 99380 -41961 74090 81458 20797 -67101 -61294 -93637 30002 31575 64837 82148 -93582 85834 -55522 82400 -75251 83169 -99328 -35842 33732 63856 93931 -19563 -6035 -75307 52896 -60812 -2658 7096 -8073 -52671 33232 -86272 -20335 -83582 8235 56187 -1369 -912...

output:

0.00000000
42465.01509081
47133.94962495
49347.91477245
158118.78864642
205540.61571887
207566.61467563
245299.43940110
308349.51615341
353626.87275647
394683.75644892
419007.33613083
422091.95161026
474747.10024166
539590.72609946
625609.91183440
679560.35655206
680641.09297161
741204.16344019
8324...

result:

ok 1000 numbers

Test #7:

score: 0
Accepted
time: 969ms
memory: 67020kb

input:

500000
-37274 -91965 47525 24618 57211 23151 8445 -54498 46859 82915 -94092 67940 20006 -43695 -36185 51956 16227 26339 -16412 38957 53689 19558 55085 83943 -65052 -99026 -68516 35326 23942 -23495 -66467 80839 22808 4310 -950 -49236 -87106 -58402 99240 27427 33345 -14321 -72696 -9090 18213 -33266 -2...

output:

0.00000000
64218.17741532
80783.80787256
111354.61190952
113899.53632825
161635.84803622
173883.03854813
262132.41808393
267176.46335495
268395.41739130
389285.33741784
458350.88853795
503355.15023795
516494.53003776
536519.15429045
601184.33870388
670156.76755799
724582.69075584
806292.38991295
847...

result:

ok 500000 numbers

Test #8:

score: 0
Accepted
time: 968ms
memory: 67068kb

input:

500000
-60760 -63142 42737 -73452 -39875 -29298 67663 13222 -88683 98557 -69983 -71005 10596 -54666 44321 57640 34829 -42363 -83245 88161 48592 -53081 -69849 -48359 61001 -10142 8855 8965 59304 -93058 56898 -32157 -24518 -67057 6052 70990 96221 36755 1032 79249 8353 -89123 -95344 -4813 -22499 26620 ...

output:

0.00000000
78956.43033163
81831.18187987
87237.59366661
199764.81243419
276005.73404778
286092.40475413
369929.76117737
414428.25741981
438180.32851386
476341.81636987
601570.86687905
628142.58457224
734786.34005663
787860.27704331
841679.25253456
910414.82755102
913285.95383391
950559.76757735
9741...

result:

ok 500000 numbers

Test #9:

score: 0
Accepted
time: 956ms
memory: 68088kb

input:

500000
-75755 17681 32965 95584 20522 26879 -21149 -92029 -2086 40964 -19043 10276 -42053 -50450 55781 26443 -79949 31685 28162 -5736 42789 -55511 636 79200 -59234 -7548 -39416 -73589 -50508 53398 50090 85561 83874 69308 -77780 -99287 -7813 99321 24617 78381 61382 81411 -25601 39173 -80308 39802 988...

output:

0.00000000
19538.38668075
140900.82064550
192720.21409441
249702.18898560
295603.65048544
356899.46049548
402480.69984729
407965.71330807
411359.55654196
490718.06013322
587402.87917939
664390.45689946
691538.74719925
767762.11847352
850199.82321877
900176.53896104
960011.09920906
1017615.51635582
1...

result:

ok 500000 numbers

Test #10:

score: 0
Accepted
time: 978ms
memory: 67660kb

input:

500000
20100 21572 -35594 -41343 -52497 69714 14056 32038 18275 75066 59060 82158 13876 -24420 83116 65764 58785 46635 9591 -66193 79246 -63255 -35359 90131 -36034 -90826 -52404 -62961 9477 -65632 21897 -44243 -27123 -20830 71616 -48715 77470 36530 -76765 46815 -62284 8069 38405 -76046 -11175 -248 -...

output:

0.00000000
34042.58891155
74440.64537313
112133.25310210
180044.83581502
182665.32223083
207636.71176521
278710.71262587
353875.96652035
515444.13977106
554250.83854032
556211.06769882
583004.87256262
656827.22471813
712839.68284706
830963.64358209
862170.77330235
889145.43351407
920071.46553060
928...

result:

ok 500000 numbers