QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#648976#4636. Optimal AssortmentKevin5307WA 432ms15392kbC++233.2kb2024-10-17 21:08:342024-10-17 21:08:35

Judging History

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

  • [2024-10-17 21:08:35]
  • 评测
  • 测评结果:WA
  • 用时:432ms
  • 内存:15392kb
  • [2024-10-17 21:08:34]
  • 提交

answer

//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
mt19937_64 rng(20210448);
int n,q;
ll l[200200],r[200200],v[200200];
ull prior[200200];
ll s1[200200],s2[200200];
int ls[200200],rs[200200];
int siz[200200];
void pushup(int x)
{
	siz[x]=siz[ls[x]]+siz[rs[x]]+1;
	s1[x]=s1[ls[x]]+s1[rs[x]]+l[x];
	s2[x]=s2[ls[x]]+s2[rs[x]]+l[x]*v[x];
}
int merge(int u,int v)
{
	if(!u||!v) return u+v;
	if(prior[u]>prior[v])
	{
		rs[u]=merge(rs[u],v);
		pushup(u);
		return u;
	}
	else
	{
		ls[v]=merge(u,ls[v]);
		pushup(v);
		return v;
	}
}
void split(int x,int ind,int &a,int &b)
{
	if(!x)
	{
		a=b=0;
		return ;
	}
	if(mp(v[x],x)<mp(v[ind],ind))
	{
		a=x;
		split(rs[x],ind,rs[a],b);
		pushup(a);
		return ;
	}
	else
	{
		b=x;
		split(ls[x],ind,a,ls[b]);
		pushup(b);
		return ;
	}
}
void splits(int x,int s,int &a,int &b)
{
	if(!x)
	{
		a=b=0;
		return ;
	}
	if(siz[ls[x]]>=s)
	{
		b=x;
		split(ls[x],s,a,ls[b]);
		pushup(b);
		return ;
	}
	else
	{
		a=x;
		split(rs[x],s-siz[ls[x]]-1,rs[a],b);
		pushup(a);
		return ;
	}
}
pair<ll,ll> query(int x,ll A,ll B)
{
	if(!B)
	{
		if(!x) return mp(0,1);
		if(s1[rs[x]]) return query(rs[x],A,B);
		if(l[x]) return mp(v[x],1);
		return query(ls[x],A,B);
	}
	if(!x) return mp(A,max(B,1ll));
	ll A2=A+s2[rs[x]]+l[x]*v[x],B2=B+s1[rs[x]]+l[x];
	if(A2>=B2*v[x]) return query(rs[x],A,B);
	return query(ls[x],A+s2[rs[x]]+l[x]*v[x],B+s1[rs[x]]+l[x]);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>q;
	for(int i=1;i<=n;i++)
		cin>>v[i];
	for(int i=0;i<=n;i++)
		cin>>l[i];
	for(int i=0;i<=n;i++)
		cin>>r[i];
	for(int i=1;i<=n;i++)
	{
		prior[i]=rng();
		siz[i]=1;
	}
	int rt=0;
	for(int i=1;i<=n;i++)
	{
		int a,b;
		split(rt,i,a,b);
		rt=merge(a,merge(i,b));
	}
	auto pr=query(rt,0,r[0]);
	ll g=__gcd(pr.first,pr.second);
	cout<<pr.first/g<<"/"<<pr.second/g<<'\n';
	while(q--)
	{
		int op;
		cin>>op;
		if(op==1)
		{
			int x;
			ll l,r;
			cin>>x>>l>>r;
			if(!x)
			{
				::l[0]=l;
				::r[0]=r;
			}
			else
			{
				int A,B,C;
				split(rt,x,A,B);
				splits(B,1,B,C);
				// assert(B==x);
				::l[x]=l;
				::r[x]=r;
				pushup(x);
				rt=merge(A,merge(B,C));
			}
		}
		else
		{
			int x;
			ll v;
			cin>>x>>v;
			int A,B,C;
			split(rt,x,A,B);
			splits(B,1,B,C);
			rt=merge(A,C);
			// assert(B==x);
			::v[x]=v;
			pushup(x);
			split(rt,x,A,C);
			rt=merge(A,merge(B,C));
		}
		auto pr=query(rt,0,r[0]);
		ll g=__gcd(pr.first,pr.second);
		cout<<pr.first/g<<"/"<<pr.second/g<<'\n';
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2 5
4 2
4 3 2
4 3 2
2 1 2
1 1 2 3
1 0 0 0
1 1 0 0
1 2 0 0

output:

16/9
10/9
1/1
2/1
2/1
0/1

result:

ok 6 lines

Test #2:

score: -100
Wrong Answer
time: 432ms
memory: 15392kb

input:

200000 200000
959139 199252 470888 74578 802746 396295 386884 721198 628655 722503 207868 647942 87506 792718 761498 917727 843338 908043 952768 268783 375312 414369 319712 96230 277106 168102 263554 936674 246545 667941 198849 268921 191459 436316 134606 802932 515506 837311 465964 394766 17626 650...

output:

146975138162163/147727408
146975138162163/147727408
146975138162163/147727408
146975138162163/147727408
146975138162163/147727408
146975138162163/147727408
146975138162163/147727408
146975138162163/147727408
1344211823228281/2583921134
1344211823228281/2583921134
7393132614757085/14211566237
7393132...

result:

wrong answer 1st lines differ - expected: '311567211361053/313072603', found: '146975138162163/147727408'