QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#559948#4636. Optimal AssortmentWorld_CreaterWA 208ms42636kbC++172.0kb2024-09-12 10:51:282024-09-12 10:51:28

Judging History

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

  • [2024-09-12 10:51:28]
  • 评测
  • 测评结果:WA
  • 用时:208ms
  • 内存:42636kb
  • [2024-09-12 10:51:28]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int inf=1e6+5;
int n,q,a[500005],l[500005],r[500005];
typedef long long ll;
struct segtree{
	struct node{
		ll cnt,sum;
		node operator +(const node &b) const
		{
			return {cnt+b.cnt,sum+b.sum};
		}
	}tree[4000005];
	#define lc(x) (x<<1)
	#define rc(x) (x<<1|1)
	#define M(l,r) ((l+r)>>1)
	void modify(int p,int l,int r,int x,int y)
	{
		tree[p].cnt+=y;
		tree[p].sum+=1ll*x*y;
		if(l==r) return ;
		int mid=M(l,r);
		if(x<=mid) modify(lc(p),l,mid,x,y);
		else modify(rc(p),mid+1,r,x,y);
	}
	node query(int p,int l,int r,int L,int R)
	{
		// cerr<<l<<" "<<r<<" "<<L<<" "<<R<<"\n";
		if(L<=l&&r<=R) return tree[p];
		int mid=M(l,r);
		if(L<=mid&&mid<R) return query(lc(p),l,mid,L,R)+query(rc(p),mid+1,r,L,R);
		if(L<=mid) return query(lc(p),l,mid,L,R);
		if(mid<R) return query(rc(p),mid+1,r,L,R);
	}
	int solve(int p,int l,int r)
	{
		if(l==r) return l;
		int mid=M(l,r);
		// cerr<<tree[rc(p)].sum<<" "<<(tree[rc(p)].cnt+::r[0])*(mid+1)<<"\n";
		if(tree[rc(p)].sum<=(tree[rc(p)].cnt+::r[0])*(mid+1)) return solve(lc(p),l,mid);
		else return solve(rc(p),mid+1,r);
	}
}T;
void solve()
{
	int p=T.solve(1,0,inf);
	auto ans=T.query(1,0,inf,p+1,inf);
	ans.cnt+=r[0];
	if(ans.sum==0) cout<<"0/1\n";
	else 
	{
		ll g=__gcd(ans.sum,ans.cnt);
		ans.sum/=g;
		ans.cnt/=g;
		cout<<ans.sum<<"/"<<ans.cnt<<"\n";
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>q;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<=n;i++)
	{
		cin>>l[i];
		if(i!=0) T.modify(1,0,inf,a[i],l[i]);
	}
	for(int i=0;i<=n;i++)
	{
		cin>>r[i];
	}
	solve();
	while(q--)
	{
		int opt;
		cin>>opt;
		if(opt==1)
		{
			int x,y,z;
			cin>>x>>y>>z;
			if(x!=0) T.modify(1,0,inf,a[x],-l[x]);
			l[x]=y;
			r[x]=z;
			if(x!=0) T.modify(1,0,inf,a[x],l[x]);
		}
		if(opt==2)
		{
			int x,y;
			cin>>x>>y;
			T.modify(1,0,inf,a[x],-l[x]);
			a[x]=y;
			T.modify(1,0,inf,a[x],l[x]);
		}
		solve();
	}
}

詳細信息

Test #1:

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

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

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:

509813598430217/512575453
509813598430217/512575453
509813598430217/512575453
509813598430217/512575453
509813598430217/512575453
509813598430217/512575453
509813598430217/512575453
509813598430217/512575453
509813598430217/512575453
509813598430217/512575453
509813598430217/512575453
50981359843021...

result:

wrong answer 1st lines differ - expected: '311567211361053/313072603', found: '509813598430217/512575453'