# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
668260 |
2022-12-03T12:31:00 Z |
slo |
Walk (CEOI06_walk) |
C++14 |
|
43 ms |
7420 KB |
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL)
#define forw(i,l,r) for(int i=l; i<r; i++)
#define fore(i,l,r) for(int i=l; i<=r; i++)
#define forb(i,r,l) for(int i=r; i>=l; i--)
#define rep(i,n) forw(i,0,n)
#define Pi acos(-1.0)
#define mp make_pair
#define ins insert
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define sz(a) (a.size())
#define all(a) a.begin(), a.end()
#define numZeroBitStart(x) (__builtin_clz(x))
#define numZeroBitEnd(x) (__builtin_ctz(x))
#define numOneBit(x) (__builtin_popcount(x))
#define parityOfNumOneBit(x) (__builtin_parity(x))
typedef long long ll;
typedef unsigned long long int ull;
typedef pair<int,int> pii;
typedef pair<int,ll> pill;
typedef pair<ll,int> plli;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
template <class X, class Y>
bool maximize(X &x, const Y &y){
X eps=1e-9;
if(x+eps<y){
x=y; return true;
}
return false;
}
template <class X, class Y>
bool minimize(X &x, const Y &y){
X eps=1e-9;
if(x>y+eps){
x=y; return true;
}
return false;
}
/*-----------------MAIN PROGRAM-----------------*/
const int N=1e5+7;
const int INF=1e9+7;
struct Rec{
int x1=0, y1=0, x2=0, y2=0;
};
int n, xf, yf;
Rec rec[N];
void read(){
cin>>xf>>yf>>n;
fore(i,1,n){
cin>>rec[i].x1>>rec[i].y1>>rec[i].x2>>rec[i].y2;
if(rec[i].y1>rec[i].y2) swap(rec[i].y1,rec[i].y2);
}
}
void solve(){
vpii evt;
fore(i,1,n) evt.pb(mp(rec[i].x1,i));
sort(all(evt));
int xPre=0;
set<pill> active;
active.ins(mp(0,0));
rep(i,sz(evt)){
const int xCur=evt[i].fi-1;
if(xCur>=xf) break;
const int& id=evt[i].se;
auto itl=active.lower_bound(mp(rec[id].y1,-INF));
if(itl!=active.end()){
auto itr=active.upper_bound(mp(rec[id].y2,-INF));
stack<pill> rem;
for(auto it=itl; it!=itr; it++)
rem.push(*it);
pill lhs, rhs=rem.top();
while(!rem.empty()){
active.erase(active.find(rem.top()));
if(sz(rem)==1) lhs=rem.top();
rem.pop();
}
lhs.se+=(lhs.fi-(rec[id].y1-1))+xCur-xPre;
lhs.fi=rec[id].y1-1;
rhs.se+=(rec[id].y2+1-rhs.fi)+xCur-xPre;
rhs.fi=rec[id].y2+1;
active.ins(lhs), active.ins(rhs);
xPre=xCur;
}
}
ll ans=xf-xPre;
auto it=active.lower_bound(mp(yf,-INF));
int add=(it->se)+(it->fi)-yf;
if(it!=active.begin()){
it--;
minimize(add,(it->se)+yf-(it->fi));
}
ans+=add;
cout<<ans;
}
int main(){
fastIO;
read();
solve();
return 0;
}
Compilation message
walk.cpp: In function 'void solve()':
walk.cpp:5:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
5 | #define forw(i,l,r) for(int i=l; i<r; i++)
| ^
walk.cpp:8:18: note: in expansion of macro 'forw'
8 | #define rep(i,n) forw(i,0,n)
| ^~~~
walk.cpp:81:5: note: in expansion of macro 'rep'
81 | rep(i,sz(evt)){
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
2 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
3 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
4 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
5 |
Runtime error |
37 ms |
6856 KB |
Execution killed with signal 11 |
6 |
Runtime error |
12 ms |
2868 KB |
Execution killed with signal 11 |
7 |
Runtime error |
22 ms |
4244 KB |
Execution killed with signal 11 |
8 |
Runtime error |
41 ms |
7420 KB |
Execution killed with signal 11 |
9 |
Runtime error |
42 ms |
7240 KB |
Execution killed with signal 11 |
10 |
Runtime error |
43 ms |
7384 KB |
Execution killed with signal 11 |