QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#298107#4636. Optimal Assortmentdefyers#WA 240ms21416kbC++171.9kb2024-01-05 17:46:552024-01-05 17:46:56

Judging History

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

  • [2024-01-05 17:46:56]
  • 评测
  • 测评结果:WA
  • 用时:240ms
  • 内存:21416kb
  • [2024-01-05 17:46:55]
  • 提交

answer

#include "bits/stdc++.h"

#pragma GCC optimize("Ofast")
#pragma GCC targetr("avx2")

using namespace std;

using ll = long long;
using pii = pair<int, int>;

const int N = 2e5 + 11;
const int V = 1e6 + 11;

int v[N], l[N], r[N];

#define int long long
struct node{
	int w, s;
};

int n, m; 

struct BIT{
	int bit[V], sum = 0;
	void add(int p, int v){ sum += v; for(int i = p; i < V; i += i & -i) bit[i] += v; }
	int qry(int p){ int ret = 0; for(int i = p; i; i -= i & -i) ret += bit[i]; return ret; }
} bit0, bit1;

void add(int profit, int quantity){
	bit0.add(profit, quantity);
	bit1.add(profit, quantity * profit);
}

void query(){
	int p = 0;
	int P = 0, Q = 1;
	for(int j = 19; j >= 0; j--){
		if(p + (1 << j) < V){
			int s0 = bit0.sum - bit0.qry(p + (1 << j) - 1);
			int s1 = bit1.sum - bit1.qry(p + (1 << j) - 1);
			// cout << s1 << ' ' << (s0 + r[0]) << ' ' << p + (1 << j) << '\n';
			if(s1 != 0 && s1 >= (s0 + r[0]) * (p + (1 << j))){
				p += (1 << j);
				P = s1; Q = s0 + r[0];
			}
		}
	}

	int g = gcd(P, Q);
	P /= g; Q /= g;
	cout << P << '/' << Q << '\n';
}

void solve(int TC) {
	cin >> n >> m;
	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++){
		add(v[i], l[i]);
	}
	query();
	for(int i = 0; i < m; i++){
		int t; cin >> t;
		if(t == 1){
			int x, y, z; cin >> x >> y >> z;
			if(v[x] != 0) add(v[x], -l[x]);
			l[x] = y, r[x] = z;
			if(v[x] != 0) add(v[x], l[x]);
		}else{
			int x, y; cin >> x >> y;
			assert(x >= 1);
			add(v[x], -l[x]);
			v[x] = y;
			add(v[x], l[x]);
		}
		query();
	}
}

int32_t main() {
	cin.tie(0)->sync_with_stdio(0);
	cout << fixed << setprecision(10);

	int t = 1;
	// cin >> t;
	for (int i = 1; i <= t; i++) {
		solve(i);
	}
}

详细

Test #1:

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

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

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:

311567211361053/313072603
311567211361053/313072603
311567211361053/313072603
311567211361053/313072603
311567211361053/313072603
311567211361053/313072603
311567211361053/313072603
311567211361053/313072603
311567211361053/313072603
311567211361053/313072603
311567211361053/313072603
31156721136105...

result:

wrong answer 142nd lines differ - expected: '312363185627235/313871594', found: '312387878380763/313896406'