QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#153252#7078. Tower of the SorcererPetroTarnavskyiWA 11ms7984kbC++172.6kb2023-08-29 19:23:512023-08-29 19:23:52

Judging History

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

  • [2023-08-29 19:23:52]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:7984kb
  • [2023-08-29 19:23:51]
  • 提交

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);
			x = nx + 1;
			l = r;
			if (r >= i) break;
			
		}
		int r = n;
		dp[i] = min(dp[i], pref[i] + st.mn(l, r));
		st.change(i, dp[i] - pref[i + 1]);
		if (a[i].F >= a[n - 1].S && i != n - 1) i = n - 2; 
	}
	cout << dp[n - 1] << '\n';

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

详细

Test #1:

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

input:

4 1
3 2
4 4
5 6
1 6

output:

9

result:

ok single line: '9'

Test #2:

score: -100
Wrong Answer
time: 11ms
memory: 7956kb

input:

5000 679
84191 46042
81916 66659
74636 72443
10252 57443
21838 54620
84896 58466
20832 29643
45949 20576
50399 51434
56472 90759
68909 94348
39459 1731
81207 17614
26465 11775
93861 24936
25017 64663
21042 37570
32903 68583
68840 58347
93849 10841
10190 77131
10595 1959
57163 59047
16066 89850
73741...

output:

14297

result:

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