#include "bits/stdc++.h"
using namespace std;
/*ios_base::sync_with_stdio(false);
cin.tie(NULL);*/
typedef long long ll;
struct node {
int s, e;
ll mn, mx, sum;
bool lset;
ll add_val, set_val;
node *l, *r;
node (int _s, int _e, int A[] = NULL): s(_s), e(_e), mn(0), mx(0), sum(0), lset(0), add_val(0), set_val(0), l(NULL), r(NULL) {
if (A == NULL) return;
if (s == e) mn = mx = sum = A[s];
else {
l = new node(s, (s+e)>>1, A), r = new node((s+e+2)>>1, e, A);
combine();
}
}
void create_children() {
if (s == e) return;
if (l != NULL) return;
int m = (s+e)>>1;
l = new node(s, m);
r = new node(m+1, e);
}
void self_set(ll v) {
lset = 1;
mn = mx = set_val = v;
sum = v * (e-s+1);
add_val = 0;
}
void self_add(ll v) {
if (lset) { self_set(v + set_val); return; }
mn += v, mx += v, add_val += v;
sum += v*(e-s+1);
}
void lazy_propagate() {
if (s == e) return;
if (lset) {
l->self_set(set_val), r->self_set(set_val);
lset = set_val = 0;
}
if (add_val != 0) {
l->self_add(add_val), r->self_add(add_val);
add_val = 0;
}
}
void combine() {
if (l == NULL) return;
sum = l->sum + r->sum;
mn = min(l->mn, r->mn);
mx = max(l->mx, r->mx);
}
void add(int x, int y, ll v) {
if (s == x && e == y) { self_add(v); return; }
int m = (s+e)>>1;
create_children(); lazy_propagate();
if (x <= m) l->add(x, min(y, m), v);
if (y > m) r->add(max(x, m+1), y, v);
combine();
}
void set(int x, int y, ll v) {
if (s == x && e == y) { self_set(v); return; }
int m = (s+e)>>1;
create_children(); lazy_propagate();
if (x <= m) l->set(x, min(y, m), v);
if (y > m) r->set(max(x, m+1), y, v);
combine();
}
ll range_sum(int x, int y) {
if (s == x && e == y) return sum;
if (l == NULL || lset) return (sum / (e-s+1)) * (y-x+1);
int m = (s+e)>>1;
lazy_propagate();
if (y <= m) return l->range_sum(x, y);
if (x > m) return r->range_sum(x, y);
return l->range_sum(x, m) + r->range_sum(m+1, y);
}
ll range_min(int x, int y) {
if (s == x && e == y) return mn;
if (l == NULL || lset) return mn;
int m = (s+e)>>1;
lazy_propagate();
if (y <= m) return l->range_min(x, y);
if (x > m) return r->range_min(x, y);
return min(l->range_min(x, m), r->range_min(m+1, y));
}
ll range_max(int x, int y) {
if (s == x && e == y) return mx;
if (l == NULL || lset) return mx;
int m = (s+e)>>1;
lazy_propagate();
if (y <= m) return l->range_max(x, y);
if (x > m) return r->range_max(x, y);
return max(l->range_max(x, m), r->range_max(m+1, y));
}
~node() {
if (l != NULL) delete l;
if (r != NULL) delete r;
}
} *root;
int sta = 0;
ll N, L;
ll h = -1;
pair<ll,ll> stamps[205];
ll s;
void search(set<ll> vis, ll idx, ll prev, ll time){
if (stamps[idx].first == -1){
} else if (vis.size() == N){
sta = N;
for(int i =0; i < 205; i++){
stamps[i] = make_pair(-1,-1);
}
} else if (time > h) {
} else { //edge cases
ll beg = vis.size();
if (time <= stamps[idx].second){
vis.insert(idx);
}
if (vis.size() > sta){
sta = vis.size();
}
ll bak = idx - 1;
ll db = stamps[idx].first - stamps[bak].first;
if (bak < 0){
bak = s - 1;
db = L - stamps[bak].first + stamps[idx].first;
}
ll fron = idx + 1;
ll df = stamps[fron].first - stamps[idx].first;
if (fron >= s){
fron = 0;
df = L - stamps[idx].first + stamps[fron].first;
}
if (beg == vis.size()){
if (prev != bak){
search(vis, bak, idx, db + time);
}
if (prev != fron){
search(vis, fron, idx, df + time);
}
} else {
search(vis, bak, idx, db + time);
search(vis, fron, idx, df + time);
}
}
}
int main( )
{ ios_base::sync_with_stdio(false);
cin.tie(NULL);
for(int i =0; i < 205; i++){
stamps[i] = make_pair(-1,-1);
}
cin >> N >> L;
ll p[N];
ll t[N];
for(int i=0; i < N; i++){
cin >> p[i];
}
for(int i=0; i < N; i++){
cin >> t[i];
h = max(t[i],h);
}
s = 0;
priority_queue<pair<ll,ll> > st;
for(int i=0; i < N; i++){
if (min(L - p[i], p[i]) <= t[i]){
st.push(make_pair(-p[i],-t[i]));
s++;
}
}
for(int i=0; i < s; i++){
stamps[i] = make_pair(-st.top().first, -st.top().second);
st.pop();
}
set<ll> ini;
if (s > 0) {
search(ini, 0, -1, min(L - p[0], p[0]));
}
if (s > 1){
search(ini, s-1, -1, min(L - p[s-1], p[s-1]));
}
cout << sta;
}
Compilation message
ho_t3.cpp: In member function 'void node::lazy_propagate()':
ho_t3.cpp:43:28: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
lset = set_val = 0;
~~~~~~~~^~~
ho_t3.cpp: In function 'void search(std::set<long long int>, ll, ll, ll)':
ho_t3.cpp:113:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
} else if (vis.size() == N){
~~~~~~~~~~~^~~~
ho_t3.cpp:125:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (vis.size() > sta){
~~~~~~~~~~~^~~~~
ho_t3.cpp:142:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (beg == vis.size()){
~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |