Submission #633328

# Submission time Handle Problem Language Result Execution time Memory
633328 2022-08-22T06:27:16 Z minhcool 코알라 (JOI13_koala) C++17
100 / 100
153 ms 19984 KB
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
 
const int oo = 1e18 + 7, mod = 1e9 + 7;
 
const int N = 1e5 + 5;
 
int k, m, n, d, aa, a[N], b[N], dp[N];
set<int> remainders;
unordered_map<int, int> uomp;
 
struct it{
	int n;
	int arr[N << 2], laz[N << 2];
	it(int _n): n(_n){
		for(int i = 1; i <= (4 * n); i++) arr[i] = laz[i] = -oo;
	}
	void lazy(int id){
		if(laz[id] = -oo) return;
		arr[id << 1] = max(arr[id << 1], laz[id]);
		laz[id << 1] = max(laz[id << 1], laz[id]);
		arr[id << 1 | 1] = max(arr[id << 1 | 1], laz[id]);
		laz[id << 1 | 1] = max(laz[id << 1 | 1], laz[id]);
		laz[id] = -oo;
	}
	void update(int id, int l, int r, int L, int R, int val){
		if(l > R || r < L || l > r) return;
		if(l >= L && r <= R){
		    //cout << id << " " << val << "\n";
			arr[id] = max(arr[id], val);
			laz[id] = max(laz[id], val);
			return; 
		}
		lazy(id);
		int mid = (l + r) >> 1;
		update(id << 1, l, mid, L, R, val);
		update(id << 1 | 1, mid + 1, r, L, R, val);
		arr[id] = max(arr[id << 1], arr[id << 1 | 1]);
	}
	int get(int id, int l, int r, int L, int R){
	    //cout << id << " " << l << " " << r << " " << arr[id] << "\n";
		if(l > R || r < L) return -oo;
		if(l >= L && r <= R){
			return arr[id];
		}
		lazy(id);
		int mid = (l + r) >> 1;
		return max(get(id << 1, l, mid, L, R), get(id << 1 | 1, mid + 1, r, L, R));
	}
};
 
void input(){
	cin >> k >> m >> d >> aa >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i] >> b[i];
	}
}
 
void process(){
	remainders.insert(k % d);
	remainders.insert(m % d);
	for(int i = 1; i <= n; i++) remainders.insert(a[i] % d);	
	int cnt = 0;
	for(auto it : remainders){
		cnt++;
		uomp[it] = cnt;
	}
	for(int i = 1; i <= n + 1; i++) dp[i] = -oo;
	it tmp(cnt);
	a[n + 1] = m;
	tmp.update(1, 1, cnt, uomp[k % d], uomp[k % d], ((k / d) * aa));
	for(int i = 1; i <= n + 1; i++){
		int x = tmp.get(1, 1, cnt, 1, uomp[a[i] % d] - 1);
		int y = tmp.get(1, 1, cnt, uomp[a[i] % d], cnt);
	//	cout << x << " " << y << "\n";
		dp[i] = max(x - aa, y);
		//dp[i] += (a[i] / d) * aa;
		dp[i] -= (a[i] / d) * aa;
		dp[i] += b[i];
		//cout << dp[i] << "\n";
		tmp.update(1, 1, cnt, uomp[a[i] % d], uomp[a[i] % d], dp[i] + (a[i] / d) * aa);
	}
}
 
void output(){
	cout << dp[n + 1];
}
 
signed main(){
	ios_base::sync_with_stdio(0);
	input();
	process();
	output();
}

Compilation message

koala.cpp: In member function 'void it::lazy(long long int)':
koala.cpp:29:14: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   29 |   if(laz[id] = -oo) return;
      |      ~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6612 KB Output is correct
2 Correct 4 ms 6616 KB Output is correct
3 Correct 4 ms 6616 KB Output is correct
4 Correct 3 ms 6612 KB Output is correct
5 Correct 4 ms 6612 KB Output is correct
6 Correct 3 ms 6612 KB Output is correct
7 Correct 3 ms 6604 KB Output is correct
8 Correct 4 ms 6616 KB Output is correct
9 Correct 4 ms 6644 KB Output is correct
10 Correct 4 ms 6612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 10812 KB Output is correct
2 Correct 41 ms 10564 KB Output is correct
3 Correct 24 ms 9272 KB Output is correct
4 Correct 40 ms 10780 KB Output is correct
5 Correct 27 ms 9044 KB Output is correct
6 Correct 18 ms 8020 KB Output is correct
7 Correct 28 ms 9788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 109 ms 16544 KB Output is correct
2 Correct 147 ms 19620 KB Output is correct
3 Correct 153 ms 19896 KB Output is correct
4 Correct 109 ms 19984 KB Output is correct
5 Correct 75 ms 14376 KB Output is correct
6 Correct 52 ms 12072 KB Output is correct