# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
586864 |
2022-06-30T20:19:43 Z |
Bench0310 |
Flood (IOI07_flood) |
C++17 |
|
298 ms |
65536 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1000001;
vector<int> tree(4*(N+5),0);
void update(int idx,int l,int r,int ql,int qr,int x)
{
if(ql>qr) return;
if(l==ql&&r==qr) tree[idx]=x;
else
{
int m=(l+r)/2;
update(2*idx,l,m,ql,min(qr,m),x);
update(2*idx+1,m+1,r,max(ql,m+1),qr,x);
}
}
int query(int idx,int l,int r,int pos)
{
if(l==r) return tree[idx];
int m=(l+r)/2;
if(pos<=m) return max(tree[idx],query(2*idx,l,m,pos));
else return max(tree[idx],query(2*idx+1,m+1,r,pos));
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<array<int,2>> points(n+1,{0,0});
map<array<int,2>,int> hot_id;
vector<array<int,2>> hot_pos(1,{0,0});
int hot_cnt=0;
auto add_hot=[&](int x,int y)->int
{
if(hot_id.find({x,y})==hot_id.end())
{
hot_id[{x,y}]=++hot_cnt;
hot_pos.push_back({x,y});
}
return hot_id[{x,y}];
};
vector<array<int,4>> point_hots(n+1);
for(int i=1;i<=n;i++)
{
auto &[x,y]=points[i];
cin >> x >> y;
int t=0;
for(int j=0;j<=1;j++) for(int k=0;k<=1;k++) point_hots[i][t++]=add_hot(x+j,y+k);
}
int m;
cin >> m;
vector<array<int,2>> walls(m+1,{0,0});
vector<array<int,2>> wall_hots(m+1,{0,0});
for(int i=1;i<=m;i++)
{
auto &[a,b]=walls[i];
cin >> a >> b;
if(points[a]>points[b]) swap(a,b);
if(points[a][0]==points[b][0]) wall_hots[i]={point_hots[a][1],point_hots[a][3]};
else wall_hots[i]={point_hots[a][2],point_hots[a][3]};
}
vector<int> v[hot_cnt+1];
auto add_edge=[&](int a,int b)
{
v[a].push_back(b);
v[b].push_back(a);
};
auto process=[&]()
{
//extract edges
fill(tree.begin(),tree.end(),-1);
vector<array<int,2>> prv(N+1,{-1,-1}); //x,hot_id
vector<array<int,4>> events; //x,tp,[y,hot_id] or [yl,yr]
for(int i=1;i<=hot_cnt;i++) events.push_back({hot_pos[i][0],0,hot_pos[i][1],i});
for(int i=1;i<=m;i++)
{
auto [a,b]=walls[i];
auto [xa,ya]=points[a];
auto [xb,yb]=points[b];
if(xa==xb) events.push_back({xa,1,ya+1,yb});
}
sort(events.begin(),events.end());
for(auto [x,tp,yl,yr]:events)
{
if(tp==0)
{
int w=query(1,0,N,yl);
auto [px,pid]=prv[yl];
if(w<px) add_edge(yr,pid);
prv[yl]={x,yr};
}
else update(1,0,N,yl,yr,x);
}
//flip coordinates
for(int i=1;i<=n;i++) swap(points[i][0],points[i][1]);
for(int i=1;i<=hot_cnt;i++) swap(hot_pos[i][0],hot_pos[i][1]);
};
process();
process();
vector<int> cc_id(hot_cnt+1,0);
int cc_cnt=0;
for(int i=1;i<=hot_cnt;i++)
{
if(cc_id[i]!=0) continue;
cc_cnt++;
queue<int> q;
auto add=[&](int a)
{
if(cc_id[a]==0)
{
cc_id[a]=cc_cnt;
q.push(a);
}
};
add(i);
while(!q.empty())
{
int a=q.front();
q.pop();
for(int to:v[a]) add(to);
}
}
vector<int> g[cc_cnt+1];
for(int i=1;i<=m;i++)
{
auto [a,b]=wall_hots[i];
g[cc_id[a]].push_back(cc_id[b]);
g[cc_id[b]].push_back(cc_id[a]);
}
vector<int> d(cc_cnt+1,0);
array<int,3> ex={-1,-1,-1};
for(int i=1;i<=hot_cnt;i++) ex=max(ex,{hot_pos[i][0],hot_pos[i][1],i});
queue<int> q;
auto add=[&](int a,int nd)
{
if(d[a]==0)
{
d[a]=nd;
q.push(a);
}
};
add(cc_id[ex[2]],1);
while(!q.empty())
{
int a=q.front();
q.pop();
for(int to:g[a]) add(to,d[a]+1);
}
vector<int> res;
for(int i=1;i<=m;i++)
{
auto [a,b]=wall_hots[i];
if(d[cc_id[a]]==d[cc_id[b]]) res.push_back(i);
}
cout << res.size() << "\n";
for(int w:res) cout << w << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
23800 KB |
Output is correct |
2 |
Correct |
18 ms |
23764 KB |
Output is correct |
3 |
Correct |
19 ms |
23736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
23796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
19 ms |
23912 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
19 ms |
23796 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
23860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
20 ms |
23972 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
21 ms |
23988 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
23 ms |
24020 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
148 ms |
40560 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
268 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
246 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
298 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
295 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |