# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
238186 |
2020-06-10T06:58:39 Z |
Mlxa |
Plahte (COCI17_plahte) |
C++14 |
|
226 ms |
81352 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define all(x) x.begin(), x.end()
#define x first
#define y second
#define mp make_pair
#define mt make_tuple
const int N = 2e5;
const int INF = 0x3f3f3f3f;
const int OPEN = 0;
const int QUERY = 1;
const int CLOSE = 2;
struct event {
int x;
int yl;
int yr;
int i; // index / color
int tp; // 0 - open, 1 - query, 2 - close
event(int a, int b, int c, int d, int e) : x(a), yl(b), yr(c), i(d), tp(e) {}
};
bool operator<(event a, event b) {
return tie(a.x, a.tp) < tie(b.x, b.tp);
}
int n;
int m;
vector<event> line;
vector<int> g[N];
vector<int> roots;
vector<int> srt;
vector<int> tree[2 * N];
int len[N];
void add(event e) {
len[e.i] = e.yr - e.yl;
for (int l = e.yl + N, r = e.yr + N; l <= r; l /= 2, r /= 2) {
if (l % 2 == 1) {
tree[l++].push_back(e.i);
}
if (r % 2 == 0) {
tree[r--].push_back(e.i);
}
}
}
void pop(vector<int> &vec, int val) {
assert(vec.size() && vec.back() == val);
vec.pop_back();
}
void del(event e) {
for (int l = e.yl + N, r = e.yr + N; l <= r; l /= 2, r /= 2) {
if (l % 2 == 1) {
pop(tree[l++], e.i);
}
if (r % 2 == 0) {
pop(tree[r--], e.i);
}
}
}
int query(int i) {
int res = -1;
for (i += N; i > 0; i /= 2) {
if (tree[i].empty()) {
continue;
}
int cur = tree[i].back();
if (res == -1 || len[res] > len[cur]) {
res = cur;
}
}
return res;
}
set<int> col[N];
int ans[N];
void solve(int v) {
for (int u : g[v]) {
solve(u);
if (col[v].size() < col[u].size()) {
swap(col[v], col[u]);
}
col[v].insert(all(col[u]));
col[u].clear();
}
ans[v] = (int)col[v].size();
}
signed main() {
#ifdef LC
assert(freopen("input.txt", "r", stdin));
#endif
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int a, b, c, d, i = 0; i < n; ++i) {
cin >> a >> b >> c >> d;
line.emplace_back(a, b, d, i, OPEN);
line.emplace_back(c, b, d, i, CLOSE);
srt.push_back(b);
srt.push_back(d);
}
for (int x, y, k, i = 0; i < m; ++i) {
cin >> x >> y >> k;
line.emplace_back(x, y, y, k, QUERY);
srt.push_back(y);
}
sort(all(line));
sort(all(srt));
for (event ev : line) {
ev.yl = lower_bound(all(srt), ev.yl) - srt.begin();
ev.yr = lower_bound(all(srt), ev.yr) - srt.begin();
int par = query((ev.yl + ev.yr) / 2);
if (ev.tp == OPEN) {
if (par == -1) {
roots.push_back(ev.i);
} else {
g[par].push_back(ev.i);
}
add(ev);
} else if (ev.tp == CLOSE) {
del(ev);
} else {
assert(ev.tp == QUERY);
if (par != -1) {
col[par].insert(ev.i);
}
}
}
for (int v : roots) {
solve(v);
}
for (int i = 0; i < n; ++i) {
cout << ans[i] << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
136 ms |
32632 KB |
Output is correct |
2 |
Correct |
121 ms |
32532 KB |
Output is correct |
3 |
Correct |
18 ms |
23808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
137 ms |
37220 KB |
Output is correct |
2 |
Correct |
133 ms |
35452 KB |
Output is correct |
3 |
Correct |
17 ms |
23808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
226 ms |
48372 KB |
Output is correct |
2 |
Correct |
217 ms |
42292 KB |
Output is correct |
3 |
Correct |
19 ms |
23808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
199 ms |
81132 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
194 ms |
81352 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |