Submission #808694

# Submission time Handle Problem Language Result Execution time Memory
808694 2023-08-05T09:34:07 Z vjudge1 코알라 (JOI13_koala) C++11
100 / 100
159 ms 15964 KB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define endl '\n'
#define MASK(i) (1LL << (i))
#define ull unsigned long long
#define ld long double
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define BIT(x , i) ((x >> (i)) & 1)
#define TASK "task"
#define sz(s) (int) (s).size()
 
using namespace std;
const int mxN = 5e5 + 227;
const int inf = 1e9 + 277;
const int mod = 1e9 + 7;
const ll infll = 1e18 + 7;
const int base = 307;
const int LOG = 20;
 
template <typename T1, typename T2> bool minimize(T1 &a, T2 b) {
	if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b) {
	if (a < b) {a = b; return true;} return false;
}
 
 
struct IT{
	int n;
	vector<ll> t;
	IT(){}
	IT(int _n) {
		n = _n;
		t.resize(n * 4 + 7, -infll);
	}
 
	void update(int v, int tl, int tr, int pos, ll val)
	{
		if(tl == tr) t[v] = max(t[v], val);
		else {
			int tm = (tl + tr) / 2;
			if(pos <= tm) update(v * 2, tl, tm, pos, val);
			else update(v * 2 + 1, tm + 1, tr, pos, val);
			t[v] = max(t[v * 2], t[v * 2 + 1]);
		}
	}
 
	ll getmax(int v, int tl, int tr, int l, int r)
	{
		if(l > r) return -infll;
		if(tl == l && tr == r) return t[v];
		int tm = (tl + tr) / 2;
		ll m1 = getmax(v * 2, tl, tm, l, min(r, tm));
		ll m2 = getmax(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
		return max(m1, m2);
	}
 
	void update(int pos, ll val)
	{
		update(1, 1, n, pos, val);
	}
	ll getmax(int l, int r)
	{
		return getmax(1, 1, n, l, r);
	}
} tot;
 
 
ll sta;
ll fin;
ll d;
ll de;
ll n;
ll a[mxN];
ll val[mxN];
ll idx[mxN];
ll dp[mxN];
map<int, int> cnt;
map<int, int> pos;
map<int, int> pre;
 
void solve()
{
	cin >> sta >> fin >> d >> de >> n;
	for(int i = 1; i <= n; i++) {
		cin >> a[i] >> val[i];
	}
 
	a[0] = sta;
	a[n + 1] = fin;
 
	de = -de;
 
	vector<int> rem;
	int timer = 0;
	for(int i = 0; i <= n + 1; i++) rem.pb(a[i] % d);
	sort(all(rem));
	rem.erase(unique(all(rem)), rem.end());
	for(auto it : rem) pos[it] = ++timer;
 
	tot = IT(n + 227);
	
 
	memset(dp, -0x3f, sizeof(dp));
	dp[0] = 0;
	for(int i = 1; i <= n + 1; i++) {
		dp[i] = 1LL * ((a[i] - a[0] + d - 1) / d) * de + val[i];
		// maximize(dp[i], seg[pos[a[i] % d]].getmax(1, idx[i] - 1) + 1LL * (a[i] / d) * de + val[i]);
		// seg[pos[a[i] % d]].update(idx[i], dp[i] - 1LL * (a[i] / d) * de);
		maximize(dp[i], tot.getmax(pos[a[i] % d], pos[a[i] % d]) + 1LL * (a[i] / d) * de + val[i]);
		maximize(dp[i], tot.getmax(1, pos[a[i] % d] - 1) + 1LL * (a[i] / d + 1) * de + val[i]);
		maximize(dp[i], tot.getmax(pos[a[i] % d] + 1, n + 20) + 1LL * (a[i] / d) * de + val[i]); 
		tot.update(pos[a[i] % d], dp[i] - 1LL * (a[i] / d) * de);
		// cout << pos[a[i] % d] << ' ' << dp[i] - 1LL * (a[i] / d) * de << endl;
	}
 
	// for(int i = 1; i <= n + 1; i++) {
	// 	for(int j = 0; j < i; j++) {
	// 		maximize(dp[i], dp[j] + 1LL * ((a[i] - a[j] + d - 1) / d) * de + val[i]);
	// 	}
	// }
 
 
 
	// cout << dp[1] << endl;
	// cout << dp[2] << endl;
	// cout << dp[5] << endl;
	cout << dp[n + 1];
}
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
 
    int tc = 1;
    //cin >> tc;
    while(tc--) {
    	solve();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4308 KB Output is correct
2 Correct 3 ms 4308 KB Output is correct
3 Correct 3 ms 4308 KB Output is correct
4 Correct 2 ms 4180 KB Output is correct
5 Correct 3 ms 4308 KB Output is correct
6 Correct 2 ms 4308 KB Output is correct
7 Correct 2 ms 4180 KB Output is correct
8 Correct 2 ms 4308 KB Output is correct
9 Correct 2 ms 4308 KB Output is correct
10 Correct 2 ms 4308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 9496 KB Output is correct
2 Correct 62 ms 11132 KB Output is correct
3 Correct 29 ms 8924 KB Output is correct
4 Correct 61 ms 11336 KB Output is correct
5 Correct 35 ms 8552 KB Output is correct
6 Correct 21 ms 6872 KB Output is correct
7 Correct 46 ms 10400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 157 ms 12332 KB Output is correct
2 Correct 159 ms 15712 KB Output is correct
3 Correct 150 ms 15964 KB Output is correct
4 Correct 139 ms 15908 KB Output is correct
5 Correct 105 ms 11364 KB Output is correct
6 Correct 81 ms 9480 KB Output is correct