Submission #808696

# Submission time Handle Problem Language Result Execution time Memory
808696 2023-08-05T09:34:28 Z vjudge1 코알라 (JOI13_koala) C++17
100 / 100
171 ms 14160 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 4344 KB Output is correct
4 Correct 2 ms 4180 KB Output is correct
5 Correct 2 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 4244 KB Output is correct
10 Correct 3 ms 4308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 9464 KB Output is correct
2 Correct 60 ms 9428 KB Output is correct
3 Correct 28 ms 7640 KB Output is correct
4 Correct 62 ms 9444 KB Output is correct
5 Correct 36 ms 7504 KB Output is correct
6 Correct 21 ms 6232 KB Output is correct
7 Correct 45 ms 9464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 171 ms 12328 KB Output is correct
2 Correct 167 ms 13824 KB Output is correct
3 Correct 153 ms 14160 KB Output is correct
4 Correct 127 ms 14052 KB Output is correct
5 Correct 94 ms 10192 KB Output is correct
6 Correct 75 ms 8564 KB Output is correct