QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#153247#7078. Tower of the SorcererPetroTarnavskyiWA 3ms8136kbC++172.5kb2023-08-29 19:20:252023-08-29 19:20:26

Judging History

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

  • [2023-08-29 19:20:26]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:8136kb
  • [2023-08-29 19:20:25]
  • 提交

answer

#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FILL(a, b) memset(a, b, sizeof(a))

#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;

const int INF = 1000'000'447;
const LL LINF = 1ll * INF * INF;

const int MAX = 1 << 19;

struct Segtree
{
	int n;
	LL t[MAX];
	
	void init(int nn)
	{
		n = 1;
		while (n < nn) n *= 2;
		FOR (i, 0, 2 * n) t[i] = LINF;
	}
	
	LL mn(int v, int tl, int tr, int l, int r)
	{
		if (l <= tl && tr <= r)
			return t[v];
		if (l >= tr || tl >= r)
			return LINF;
		int m = (tl + tr) / 2;
		LL ans = LINF;
		if (l < m)
			ans = min(ans, mn(v * 2, tl, m, l, r));
		if (r > m)
			ans = min(ans, mn(v * 2 + 1, m, tr, l, r));
		return ans;
	}
	
	LL mn(int l, int r)
	{
		return mn(1, 0, n, l, r);
	}
	
	void change(int v, int l, int r, int i, LL x)
	{
		if (l + 1 == r)
		{
			t[v] = x;
			return;
		}
		int m = (l + r) / 2;
		if (i < m)
			change(v * 2, l, m, i, x);
		else
			change(v * 2 + 1, m, r, i, x);
		t[v] = min(t[v * 2], t[v * 2 + 1]);
	}
	
	void change(int i, LL x)
	{
		change(1, 0, n, i, x);
	}
};

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n, d;
	cin >> n >> d;
	
	Segtree st;
	st.init(n + 1);
	
	vector<PII> a(n);
	int mx = d;
	FOR (i, 0, n)
	{
		cin >> a[i].F >> a[i].S;
		mx = max(mx, a[i].F);
	}
	
	a.PB({d, 0});
	sort(ALL(a));
	int b = lower_bound(ALL(a), MP(d, 0)) - a.begin();
	n++;
		
	vector<LL> pref(n + 1);
	FOR (i, 0, n)
	{
		LL val = (a[i].S - 1) / mx * a[i].F;
		pref[i + 1] = pref[i] + val;
	}
	vector<LL> dp(n, LINF);
	dp[b] = pref[b];
	st.change(b, pref[b] - pref[b + 1]);
	
	FOR (i, b + 1, n)
	{
		int x = 1;
		int l = lower_bound(ALL(a), MP(x, -1)) - a.begin();
		int hp = a[i].S - 1;
		while (x <= hp)
		{
			int k = hp / x;
			int q = k * a[i].F;
			//if (dp[i] < q)
			//	break;
			int nx = hp / k;
			int r = lower_bound(ALL(a), MP(nx + 1, -1)) - a.begin();
			dp[i] = min(dp[i], pref[i] + st.mn(l, r) + q);
			if (r >= i) break;
			x = nx + 1;
			l = r;
		}
		int r = n;
		dp[i] = min(dp[i], pref[i] + st.mn(l, r));
		st.change(i, dp[i] - pref[i + 1]);
	}
	cout << dp[n - 1] << '\n';

	cerr << db(clock()) / CLOCKS_PER_SEC << '\n';
	
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 8136kb

input:

4 1
3 2
4 4
5 6
1 6

output:

0

result:

wrong answer 1st lines differ - expected: '9', found: '0'