# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
715907 |
2023-03-28T11:52:00 Z |
vjudge1 |
Plahte (COCI17_plahte) |
C++17 |
|
704 ms |
67092 KB |
#include <bits/stdc++.h>
#define int long long
using namespace std;
struct segtree{
vector<int> tree;
int size;
void init(int n){
size = 1;
while(size < n) size *= 2;
tree.resize(2 * size - 1, 0);
}
void propagate(int x, int lx, int rx){
if(tree[x] == -1 || lx == rx) return;
tree[2 * x + 1] = tree[x];
tree[2 * x + 2] = tree[x];
tree[x] = -1;
}
void update(int l, int r, int v, int x, int lx, int rx){
propagate(x, lx, rx);
if(r < lx || rx < l) return;
if(l <= lx && rx <= r){
tree[x] = v;
return;
}
int mx = (lx + rx) / 2;
update(l, r, v, 2 * x + 1, lx, mx);
update(l, r, v, 2 * x + 2, mx + 1, rx);
}
void update(int l, int r, int v){
update(l, r, v, 0, 0, size - 1);
}
int query(int i, int x, int lx, int rx){
propagate(x, lx, rx);
if(lx == rx) return tree[x];
int mx = (lx + rx) / 2;
if(i <= mx) return query(i, 2 * x + 1, lx, mx);
return query(i, 2 * x + 2, mx + 1, rx);
}
int query(int i){
return query(i, 0, 0, size - 1);
}
};
struct event
{
int x, y1, y2, type, idx;
bool operator<(event other){
if(x == other.x) return type < other.type;
return x < other.x;
}
};
int parent[160002];
vector<int> adj[160002];
set<int> colors[160002];
int ans[160002];
void dfs(int u, int p){
for(auto v : adj[u]){
if(v != p){
dfs(v, u);
if(colors[u].size() < colors[v].size()) swap(colors[u], colors[v]);
for(auto i : colors[v]){
colors[u].insert(i);
}
}
}
ans[u] = colors[u].size();
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, m;
cin >> n >> m;
vector<event> events;
int squares[n + 1][4];
int points[m + 1][2];
map<int, int> d;
for (int i = 1; i <= n; i++)
{
cin >> squares[i][0] >> squares[i][1] >> squares[i][2] >> squares[i][3];
d[squares[i][1]]; d[squares[i][3]];
//events.push_back({x1, y1, y2, 0, i});
//events.push_back({x2, y1, y2, 2, i});
}
for(int i = 1; i <= m; i++){
int c;
cin >> points[i][0] >> points[i][1] >> c;
d[points[i][1]];
colors[i + n].insert(c);
//events.push_back({x, y, y, 1, i});
}
int idx = 0;
for(auto& i : d){
i.second = idx++;
}
for (int i = 1; i <= n; i++)
{
events.push_back({squares[i][0], d[squares[i][1]], d[squares[i][3]], 0, i});
events.push_back({squares[i][2], d[squares[i][1]], d[squares[i][3]], 2, i});
}
for(int i = 1; i <= m; i++){
events.push_back({points[i][0], d[points[i][1]], d[points[i][1]], 1, i + n});
}
sort(events.begin(), events.end());
segtree st;
st.init(idx);
for(auto i : events){
if(i.type == 0){
parent[i.idx] = st.query(i.y1);
adj[parent[i.idx]].push_back(i.idx);
adj[i.idx].push_back(parent[i.idx]);
st.update(i.y1, i.y2, i.idx);
}else if(i.type == 1){
parent[i.idx] = st.query(i.y1);
adj[parent[i.idx]].push_back(i.idx);
adj[i.idx].push_back(parent[i.idx]);
}else{
st.update(i.y1, i.y2, parent[i.idx]);
}
}
dfs(0, -1);
for(int i = 1; i <= n; i++)
cout<<ans[i]<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
155 ms |
29688 KB |
Output is correct |
2 |
Correct |
166 ms |
30424 KB |
Output is correct |
3 |
Correct |
7 ms |
11604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
188 ms |
32388 KB |
Output is correct |
2 |
Correct |
198 ms |
31592 KB |
Output is correct |
3 |
Correct |
8 ms |
11616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
344 ms |
47656 KB |
Output is correct |
2 |
Correct |
346 ms |
42068 KB |
Output is correct |
3 |
Correct |
7 ms |
11608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
648 ms |
67092 KB |
Output is correct |
2 |
Correct |
704 ms |
62688 KB |
Output is correct |
3 |
Correct |
6 ms |
11612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
654 ms |
65592 KB |
Output is correct |
2 |
Correct |
663 ms |
61252 KB |
Output is correct |
3 |
Correct |
6 ms |
11604 KB |
Output is correct |