# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
145067 |
2019-08-18T16:52:10 Z |
gs18103 |
코알라 (JOI13_koala) |
C++14 |
|
317 ms |
10356 KB |
#include <bits/stdc++.h>
#define fi first
#define se second
#define LINF 1000000000000000LL
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair <ll, ll> pll;
int t[101010];
ll b[101010], tree[404040], lazy[404040];
void update_lazy(int node, int s, int e) {
tree[node] = max(lazy[node], tree[node]);
if(s != e) {
lazy[node*2] = max(lazy[node*2], lazy[node]);
lazy[node*2+1] = max(lazy[node*2+1], lazy[node]);
}
lazy[node] = -LINF;
}
void update_range(int node, int s, int e, int l, int r, ll val) {
update_lazy(node, s, e);
if(s > r || e < l) return;
if(s >= l && e <= r) {
tree[node] = max(tree[node], val);
lazy[node*2] = max(lazy[node*2], val);
lazy[node*2+1] = max(lazy[node*2+1], val);
return;
}
int m = (s + e) / 2;
update_range(node*2, s, m, l, r, val);
update_range(node*2+1, m+1, e, l, r, val);
tree[node] = max(tree[node*2], tree[node*2+1]);
}
ll cal(int node, int s, int e, int l, int r) {
update_lazy(node, s, e);
if(s > r || e < l) return -LINF;
if(s >= l && e <= r) return tree[node];
int m = (s + e) / 2;
return max(cal(node*2, s, m, l, r), cal(node*2+1, m+1, e, l, r));
}
vector <int> num;
int main() {
int K, m, d, n;
ll a;
cin >> K >> m >> d >> a >> n;
for(int i = 1; i <= n; i++) {
cin >> t[i] >> b[i];
t[i] -= K;
num.eb(t[i]%d);
}
num.eb((m-K)%d);
sort(all(num));
for(int i = 0; i < 404040; i++) {
lazy[i] = -LINF;
tree[i] = -LINF;
}
update_range(1, 0, num.size()-1, 0, 0, 0LL);
update_range(1, 0, num.size()-1, 1, num.size()-1, -a);
for(int i = 1; i <= n; i++) {
int k = lower_bound(all(num), t[i]%d) - num.begin();
ll val = cal(1, 0, num.size()-1, k, k) + b[i];
update_range(1, 0, num.size()-1, 0, k, val);
if(k < num.size()-1) update_range(1, 0, num.size()-1, k+1, num.size()-1, val - a);
}
int k = lower_bound(all(num), (m-K)%d) - num.begin();
cout << cal(1, 0, num.size()-1, k, k) - a * (ll)((m - K) / d);
}
Compilation message
koala.cpp: In function 'int main()':
koala.cpp:70:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(k < num.size()-1) update_range(1, 0, num.size()-1, k+1, num.size()-1, val - a);
~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
6648 KB |
Output is correct |
2 |
Correct |
10 ms |
6648 KB |
Output is correct |
3 |
Correct |
9 ms |
6648 KB |
Output is correct |
4 |
Correct |
8 ms |
6648 KB |
Output is correct |
5 |
Correct |
9 ms |
6648 KB |
Output is correct |
6 |
Correct |
9 ms |
6648 KB |
Output is correct |
7 |
Correct |
7 ms |
6636 KB |
Output is correct |
8 |
Correct |
9 ms |
6648 KB |
Output is correct |
9 |
Correct |
10 ms |
6648 KB |
Output is correct |
10 |
Correct |
9 ms |
6648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
287 ms |
10356 KB |
Output is correct |
2 |
Correct |
270 ms |
9928 KB |
Output is correct |
3 |
Correct |
172 ms |
8948 KB |
Output is correct |
4 |
Correct |
271 ms |
10240 KB |
Output is correct |
5 |
Correct |
160 ms |
8988 KB |
Output is correct |
6 |
Correct |
98 ms |
8060 KB |
Output is correct |
7 |
Incorrect |
213 ms |
9328 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
317 ms |
10240 KB |
Output is correct |
2 |
Correct |
308 ms |
10224 KB |
Output is correct |
3 |
Correct |
299 ms |
10220 KB |
Output is correct |
4 |
Correct |
279 ms |
10224 KB |
Output is correct |
5 |
Correct |
189 ms |
8880 KB |
Output is correct |
6 |
Correct |
144 ms |
8440 KB |
Output is correct |