# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
163357 |
2019-11-12T19:58:53 Z |
TadijaSebez |
Golf (JOI17_golf) |
C++11 |
|
3852 ms |
605208 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int N=100050;
const int H=4*N;
const int inf=1e9+7;
struct compress
{
vector<int> all;
void Add(int x){ all.pb(x);}
void Build(){ sort(all.begin(),all.end());all.erase(unique(all.begin(),all.end()),all.end());}
int Get(int x){ return lower_bound(all.begin(),all.end(),x)-all.begin()+1;}
int sz(){ return all.size();}
} xs,ys;
struct rec
{
int type,x,l,r;
rec(int t, int a, int b, int c):type(t),x(a),l(b),r(c){}
};
vector<rec> rs;
int X1[N],Y1[N],X2[N],Y2[N];
vector<pair<int,int>> Add[H],Del[H];
vector<int> fir,las;
int n,sx,sy,ex,ey;
void Build(int type)
{
for(int i=1;i<=n;i++) Add[X1[i]].pb({Y1[i],Y2[i]}),Del[X2[i]].pb({Y1[i],Y2[i]});
set<pair<int,int>> st;
st.insert({1,1});st.insert({ys.sz(),ys.sz()});
for(int x=1;x<=xs.sz();x++)
{
for(auto p:Del[x])
{
auto it=st.find(p),l=it,r=it;l--;r++;
rs.pb(rec(type,x,l->second,r->first));
st.erase(it);
}
if(sx==x)
{
auto r=st.lower_bound({sy,-inf}),l=r;l--;
fir.pb(rs.size());
rs.pb(rec(type,x,l->second,r->first));
}
if(ex==x)
{
auto r=st.lower_bound({ey,-inf}),l=r;l--;
las.pb(rs.size());
rs.pb(rec(type,x,l->second,r->first));
}
for(auto p:Add[x])
{
st.insert(p);
auto it=st.find(p),l=it,r=it;l--;r++;
rs.pb(rec(type,x,l->second,r->first));
}
}
for(int i=1;i<=xs.sz();i++) Add[i].clear(),Del[i].clear();
for(int i=1;i<=n;i++) swap(X1[i],Y1[i]),swap(X2[i],Y2[i]);swap(sx,sy);swap(ex,ey);swap(xs,ys);
}
const int M=H*2;
bool was[N];
int dist[N];
queue<int> q;
struct SegmentTree
{
set<pair<int,int>> node[M];
SegmentTree(){}
void Ins(int x, int l, int r, int id)
{
for(l+=H,r+=H;l<=r;l>>=1,r>>=1)
{
if(l%2==1) node[l++].insert({x,id});
if(r%2==0) node[r--].insert({x,id});
}
}
void Take(int x, int l, int r, int d)
{
for(x+=H;x;x>>=1)
{
while(1)
{
auto it=node[x].lower_bound({l,-inf});
if(it==node[x].end() || it->first>r) break;
int id=it->second;
node[x].erase(it);
if(!was[id]) was[id]=1,dist[id]=d+1,q.push(id);
}
}
}
} ST[2];
int main()
{
scanf("%i %i %i %i",&sx,&sy,&ex,&ey);
scanf("%i",&n);
xs.Add(0);xs.Add(inf);ys.Add(0);ys.Add(inf);xs.Add(sx);xs.Add(ex);ys.Add(sy);ys.Add(ey);
for(int i=1;i<=n;i++) scanf("%i %i %i %i",&X1[i],&X2[i],&Y1[i],&Y2[i]),xs.Add(X1[i]),xs.Add(X2[i]),ys.Add(Y1[i]),ys.Add(Y2[i]);
xs.Build();ys.Build();
sx=xs.Get(sx);ex=xs.Get(ex);sy=ys.Get(sy);ey=ys.Get(ey);
for(int i=1;i<=n;i++) X1[i]=xs.Get(X1[i]),X2[i]=xs.Get(X2[i]),Y1[i]=ys.Get(Y1[i]),Y2[i]=ys.Get(Y2[i]);
Build(0);Build(1);
for(int i=0;i<rs.size();i++) ST[rs[i].type].Ins(rs[i].x,rs[i].l,rs[i].r,i);
for(int i:fir)
{
if(rs[i].type==0)
{
if(ex==rs[i].x && ey>=rs[i].l && ey<=rs[i].r) return 0*printf("1\n");
}
else
{
if(ey==rs[i].x && ex>=rs[i].l && ex<=rs[i].r) return 0*printf("1\n");
}
q.push(i),was[i]=1;
}
while(q.size())
{
int x=q.front();
q.pop();
ST[rs[x].type^1].Take(rs[x].x,rs[x].l,rs[x].r,dist[x]);
}
int ans=1e9+7;
for(int i:las) if(was[i]) ans=min(ans,dist[i]);
printf("%i\n",ans+1);
return 0;
}
Compilation message
golf.cpp: In function 'void Build(int)':
golf.cpp:59:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for(int i=1;i<=n;i++) swap(X1[i],Y1[i]),swap(X2[i],Y2[i]);swap(sx,sy);swap(ex,ey);swap(xs,ys);
^~~
golf.cpp:59:60: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
for(int i=1;i<=n;i++) swap(X1[i],Y1[i]),swap(X2[i],Y2[i]);swap(sx,sy);swap(ex,ey);swap(xs,ys);
^~~~
golf.cpp: In function 'int main()':
golf.cpp:102:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<rs.size();i++) ST[rs[i].type].Ins(rs[i].x,rs[i].l,rs[i].r,i);
~^~~~~~~~~~
golf.cpp:94:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i %i %i %i",&sx,&sy,&ex,&ey);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
golf.cpp:95:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i",&n);
~~~~~^~~~~~~~~
golf.cpp:97:114: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i=1;i<=n;i++) scanf("%i %i %i %i",&X1[i],&X2[i],&Y1[i],&Y2[i]),xs.Add(X1[i]),xs.Add(X2[i]),ys.Add(Y1[i]),ys.Add(Y2[i]);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
94304 KB |
Output is correct |
2 |
Correct |
72 ms |
94456 KB |
Output is correct |
3 |
Correct |
68 ms |
94332 KB |
Output is correct |
4 |
Correct |
60 ms |
94456 KB |
Output is correct |
5 |
Correct |
67 ms |
95480 KB |
Output is correct |
6 |
Correct |
82 ms |
95480 KB |
Output is correct |
7 |
Correct |
85 ms |
95456 KB |
Output is correct |
8 |
Correct |
73 ms |
95528 KB |
Output is correct |
9 |
Correct |
67 ms |
95440 KB |
Output is correct |
10 |
Correct |
82 ms |
95480 KB |
Output is correct |
11 |
Correct |
68 ms |
95480 KB |
Output is correct |
12 |
Correct |
80 ms |
95480 KB |
Output is correct |
13 |
Correct |
66 ms |
95480 KB |
Output is correct |
14 |
Correct |
68 ms |
95480 KB |
Output is correct |
15 |
Correct |
64 ms |
94840 KB |
Output is correct |
16 |
Correct |
77 ms |
95480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
94304 KB |
Output is correct |
2 |
Correct |
72 ms |
94456 KB |
Output is correct |
3 |
Correct |
68 ms |
94332 KB |
Output is correct |
4 |
Correct |
60 ms |
94456 KB |
Output is correct |
5 |
Correct |
67 ms |
95480 KB |
Output is correct |
6 |
Correct |
82 ms |
95480 KB |
Output is correct |
7 |
Correct |
85 ms |
95456 KB |
Output is correct |
8 |
Correct |
73 ms |
95528 KB |
Output is correct |
9 |
Correct |
67 ms |
95440 KB |
Output is correct |
10 |
Correct |
82 ms |
95480 KB |
Output is correct |
11 |
Correct |
68 ms |
95480 KB |
Output is correct |
12 |
Correct |
80 ms |
95480 KB |
Output is correct |
13 |
Correct |
66 ms |
95480 KB |
Output is correct |
14 |
Correct |
68 ms |
95480 KB |
Output is correct |
15 |
Correct |
64 ms |
94840 KB |
Output is correct |
16 |
Correct |
77 ms |
95480 KB |
Output is correct |
17 |
Correct |
71 ms |
95840 KB |
Output is correct |
18 |
Correct |
70 ms |
95736 KB |
Output is correct |
19 |
Correct |
70 ms |
95704 KB |
Output is correct |
20 |
Correct |
85 ms |
95736 KB |
Output is correct |
21 |
Correct |
124 ms |
95932 KB |
Output is correct |
22 |
Correct |
119 ms |
95736 KB |
Output is correct |
23 |
Correct |
70 ms |
95864 KB |
Output is correct |
24 |
Correct |
76 ms |
95736 KB |
Output is correct |
25 |
Correct |
83 ms |
95836 KB |
Output is correct |
26 |
Correct |
76 ms |
95736 KB |
Output is correct |
27 |
Correct |
65 ms |
94996 KB |
Output is correct |
28 |
Correct |
68 ms |
95608 KB |
Output is correct |
29 |
Correct |
75 ms |
95712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
94304 KB |
Output is correct |
2 |
Correct |
72 ms |
94456 KB |
Output is correct |
3 |
Correct |
68 ms |
94332 KB |
Output is correct |
4 |
Correct |
60 ms |
94456 KB |
Output is correct |
5 |
Correct |
67 ms |
95480 KB |
Output is correct |
6 |
Correct |
82 ms |
95480 KB |
Output is correct |
7 |
Correct |
85 ms |
95456 KB |
Output is correct |
8 |
Correct |
73 ms |
95528 KB |
Output is correct |
9 |
Correct |
67 ms |
95440 KB |
Output is correct |
10 |
Correct |
82 ms |
95480 KB |
Output is correct |
11 |
Correct |
68 ms |
95480 KB |
Output is correct |
12 |
Correct |
80 ms |
95480 KB |
Output is correct |
13 |
Correct |
66 ms |
95480 KB |
Output is correct |
14 |
Correct |
68 ms |
95480 KB |
Output is correct |
15 |
Correct |
64 ms |
94840 KB |
Output is correct |
16 |
Correct |
77 ms |
95480 KB |
Output is correct |
17 |
Correct |
71 ms |
95840 KB |
Output is correct |
18 |
Correct |
70 ms |
95736 KB |
Output is correct |
19 |
Correct |
70 ms |
95704 KB |
Output is correct |
20 |
Correct |
85 ms |
95736 KB |
Output is correct |
21 |
Correct |
124 ms |
95932 KB |
Output is correct |
22 |
Correct |
119 ms |
95736 KB |
Output is correct |
23 |
Correct |
70 ms |
95864 KB |
Output is correct |
24 |
Correct |
76 ms |
95736 KB |
Output is correct |
25 |
Correct |
83 ms |
95836 KB |
Output is correct |
26 |
Correct |
76 ms |
95736 KB |
Output is correct |
27 |
Correct |
65 ms |
94996 KB |
Output is correct |
28 |
Correct |
68 ms |
95608 KB |
Output is correct |
29 |
Correct |
75 ms |
95712 KB |
Output is correct |
30 |
Runtime error |
3852 ms |
605208 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
31 |
Halted |
0 ms |
0 KB |
- |