# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
400402 |
2021-05-07T23:16:45 Z |
Ozy |
Plahte (COCI17_plahte) |
C++17 |
|
251 ms |
37676 KB |
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); i++)
#define repa(i,a,b) for (int i = (a); i >= (b); i--)
#define lli long long int
struct cua{
lli x1;
lli y1;
lli x2;
lli y2;
};
cua cuadros[80002];
lli n,m,a,b,c,d,cont,ult,k;
lli padres[19][80002];
set<lli> colores[80002];
lli res[80002];
struct eve {
lli x;
lli arriba;
lli abajo;// color
lli tipo;
lli id;
bool operator < (const eve &a)
const {
if (x != a.x) return x < a.x;
else return tipo < a.tipo;
}
};
set<pair <lli, lli> > activos;
eve eventos[240002];
eve act;
lli contenido(lli y) {
auto par = (*activos.lower_bound({y, 0}));
lli pas = par.second;
if (cuadros[pas].y1 <= y) return pas;
else{
lli ult = 0;
repa(i,18,0) {
if (padres[i][pas] == 0) continue;
if (cuadros[ padres[i][pas] ].y1 <= y) ult = padres[i][pas];
else pas = padres[i][pas];
}
return ult;
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
cont = 1;
rep(i,1,n) {
cin >> a >> b >> c >> d;
cuadros[i] = {a,b,c,d};
eventos[cont++] = {a,d,b,1,i};
eventos[cont++] = {c,d,b,3,i};
}
rep(i,1,m) {
cin >> a >> b >> c;
eventos[cont++] = {a,b,c,2,i+n};
}
sort(eventos+1, eventos+cont);
k = cont;
rep(T,1,k-1) {
act = eventos[T];
if (act.tipo == 1) {
ult = contenido(act.arriba);
padres[0][act.id] = ult;
cont = 0;
while (ult > 0){
padres[cont+1][act.id] = padres[cont][ult];
ult = padres[cont][ult];
cont++;
}
activos.insert({act.arriba, act.id});
}
else if (act.tipo == 2) {
ult = contenido(act.arriba);
if (ult == 0) continue;
if (colores[ult].find(act.abajo) == colores[ult].end()) colores[ult].insert(act.abajo);
}
else {
res[act.id] = colores[act.id].size();
ult = padres[0][act.id];
if (ult) {
if (colores[ult].size() < colores[act.id].size()) swap(colores[ult], colores[act.id]);
for (auto pos : colores[act.id]) {
if (colores[ult].find(pos) == colores[ult].end()) colores[ult].insert(pos);
}
}
colores[act.id].clear();
activos.erase({act.arriba, act.id});
}
}
rep(i,1,n) cout << res[i] << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
12352 KB |
Output is correct |
2 |
Correct |
65 ms |
11648 KB |
Output is correct |
3 |
Correct |
3 ms |
4044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
94 ms |
16088 KB |
Output is correct |
2 |
Correct |
83 ms |
15260 KB |
Output is correct |
3 |
Correct |
3 ms |
4044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
147 ms |
24848 KB |
Output is correct |
2 |
Correct |
154 ms |
22212 KB |
Output is correct |
3 |
Correct |
3 ms |
4100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
246 ms |
37676 KB |
Output is correct |
2 |
Correct |
218 ms |
30292 KB |
Output is correct |
3 |
Correct |
3 ms |
4096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
251 ms |
37116 KB |
Output is correct |
2 |
Correct |
250 ms |
32780 KB |
Output is correct |
3 |
Correct |
3 ms |
4136 KB |
Output is correct |