QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#304314#7897. Largest DigitPetroTarnavskyi#WA 1ms3568kbC++202.0kb2024-01-13 17:35:582024-01-13 17:35:58

Judging History

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

  • [2024-01-13 17:35:58]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3568kb
  • [2024-01-13 17:35:58]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); i--)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

struct Fenwick
{
	int n;
	vector<LL> v;
	
	void init(int _n)
	{
		n = _n;
		v.clear();
		v.assign(n, 0);
	}
	
	void upd(int i, int x)
	{
		for (; i < n; i |= (i + 1))
			v[i] += x;
	}
	
	LL query(int i)
	{
		LL ans = 0;
		for (; i >= 0; i = (i & (i + 1)) - 1)
			ans += v[i];
		return ans;
	}
	
	int lowerBound(LL x)
	{
		LL sum = 0;
		int i = -1;
		int lg = 31 - __builtin_clz(n);
		while (lg >= 0)
		{
			int j = i + (1 << lg);
			if (j < n && sum + v[j] < x)
			{
				sum += v[j];
				i = j;
			}
			lg--;
		}
		return i + 1;
	}
}cnt, sum;


int n;
LL k;
VI a, b;

void add(int i, bool add)
{
	int j = lower_bound(ALL(b), a[i]) - b.begin();
	cnt.upd(j, add ? 1 : -1);
	sum.upd(j, add ? a[i] : -a[i]);
}

bool ok()
{
	int c = cnt.query(n - 1);
	int j = cnt.lowerBound((c + 1) / 2);
	LL x = b[j];
	LL s1 = sum.query(j);
	LL s2 = sum.query(n - 1) - s1;
	int i = cnt.query(j);
	LL need = x * i - s1 + s2 - x * (c - i);
	return need <= k;
}

void solve()
{
	cin >> n >> k;
	cnt.init(n);
	sum.init(n);
	a.clear();
	a.resize(n);
	b.clear();
	b.resize(n);
	FOR (i, 0, n)
	{
		cin >> a[i];
		a[i] -= i;
		b[i] = a[i];
	}
	sort(ALL(b));
	int ans = 0;
	int r = 0;
	FOR (l, 0, n)
	{
		while (r < n && ok())
		{
			add(r, 1);
			r++;
		}
		int val = r - l;
		if (!ok())
			val--;
		ans = max(ans, val);
		add(l, 0);
	}
	cout << ans << '\n';
}

int main()
{
	ios::sync_with_stdio(0); 
	cin.tie(0);
	cout << fixed << setprecision(15);
	
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3568kb

input:

2
178 182 83 85
2 5 3 6

output:

27
27

result:

wrong answer 1st lines differ - expected: '7', found: '27'