제출 #610919

#제출 시각아이디문제언어결과실행 시간메모리
610919PiejanVDCRoller Coaster Railroad (IOI16_railroad)C++17
0 / 100
1193 ms57392 KiB
#include "railroad.h" #include <bits/stdc++.h> using namespace std; const int mxN = (int)2e5+5; vector<int>st(8*mxN); int l,r,val; vector<int>lazy(8*mxN); int query(int i, int j, int p) { if(i > r || j < l) return 0; if(i >= l && j <= r) return st[p]+lazy[p]; int mid = (i+j)/2; lazy[2*p] += lazy[p]; lazy[2*p+1] += lazy[p]; lazy[p] = 0; return query(i, mid, 2*p) + query(mid+1, j, 2*p+1); } void update(int i, int j, int p) { if(i > r || j < l) return; if(i >= l && j <= r) { lazy[p] += val; return; } int mid = (i+j)/2; lazy[2*p] += lazy[p]; lazy[2*p+1] += lazy[p]; lazy[p] = 0; update(i, mid, 2*p); update(mid+1, j, 2*p+1); } long long plan_roller_coaster(vector<int>s, vector<int>t) { set<int>S; int n = (int)s.size(); for(auto z : s) S.insert(z); for(auto z : t) S.insert(z); map<int,int>rev; auto it = S.begin(); for(int i = 0 ; i < 2*n ; i++, it++) rev[*it] = i; for(int i = 0 ; i < n ; i++) { if(s[i] <= t[i]) { auto ff = S.lower_bound(s[i]); auto ss = S.lower_bound(t[i]); ss--; l = rev[*ff], r = rev[*ss]; val = 1; update(0, 2*n-1, 1); } else { auto ss = S.lower_bound(s[i]); auto ff = S.lower_bound(t[i]); ss--; l = rev[*ff], r = rev[*ss]; val = -1; update(0, 2*n-1, 1); } } long long ret = 0; for(int i = 0 ; i < n ; i++) { l = r = i; if(query(0, 2*n-1, 1) > 1) ret = 1; } return ret; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...