QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#21291 | #2822. 不等式 | glory_to_the_qy# | WA | 1ms | 19948kb | C++20 | 2.9kb | 2022-03-04 14:40:02 | 2022-05-08 02:50:38 |
Judging History
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[1000010],b[1000010];
// double p[1000010];
struct node
{
double x;
int id;
}p[1000010];
bool cmp(node p1,node p2)
{
return p1.x<p2.x;
}
struct line
{
int k=0,b=0;
line(){}
line(int kk,int bb){k=kk,b=bb;}
}c[1000010];
line operator + (line a,line b){return line(a.k+b.k,a.b+b.b);}
int c2[1000010],pos[1000010];
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)
{
// cout<<l<<' '<<r<<" "<<v<<":"<<c2[x<<1]<<'\n'
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(".in","r",stdin);
//freopen(".out","w",stdout);
int n=qr;
for(int i=1;i<=n;i++)
{
in(a[i]),in(b[i]);
if(a[i]<0)a[i]*=-1,b[i]*=-1;
p[i]=(node){-1.0*b[i]/a[i],i};
}
sort(p+1,p+1+n,cmp);
for(int i=1;i<=n;i++)
{
pos[p[i].id]=i;
}
int sum=0;
for(int i=1;i<=n;i++)
{
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);
// cout<<pp<<" "<<p[pp].x<<'\n';
line now=query(1,n+1,pp,1);
printf("%.5f\n",now.k*(p[pp].x)+now.b);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 19948kb
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.00000 82310.68963 86210.45246 117511.88113 213287.62275 245465.21306 248846.39270 345182.52769 445820.76720 456415.40907 553014.99413 555508.82070 609095.42505 627287.53595 634829.78099 691329.76791 751826.75252 817445.25946 872809.58412 932503.05835 966074.55533 1036159.43608 1108510.99111 117486...
result:
wrong answer 2nd numbers differ - expected: '21040.3674840', found: '82310.6896300', error = '2.9120367'