# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
548204 |
2022-04-12T17:31:52 Z |
Evang |
Plahte (COCI17_plahte) |
C++17 |
|
268 ms |
31296 KB |
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
#ifdef _DEBUG
#define dout(x) clog << "Line " << __LINE__ << ": " << #x << "=" << (x) << el
#else
#define dout(x)
#endif
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define uid(a,b) uniform_int_distribution<int>(a,b)(rng)
#define ins insert
#define ssize(x) (int((x).size()))
#define bs(args...) binary_search(args)
#define lb(args...) lower_bound(args)
#define ub(args...) upper_bound(args)
#define all(x) (x).begin(),(x).end()
#define mp(a, b) make_pair(a, b)
#define mt(args...) make_tuple(args)
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define die exit(0)
template<typename T>
using vc = vector<T>;
template<typename T>
using uset = unordered_set<T>;
template<typename A, typename B>
using umap = unordered_map<A, B>;
template<typename T, typename Comp>
using pq = std::priority_queue<T, vc<T>, Comp>;
template<typename T>
using maxpq = pq<T, less<T>>;
template<typename T>
using minpq = pq<T, greater<T>>;
template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using db = double;
using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
using pdb = pair<db, db>;
using pld = pair<ld, ld>;
using vi = vc<int>;
using vll = vc<ll>;
using vpi = vc<pi>;
using vpll = vc<pll>;
using vpdb = vc<pdb>;
using vpld = vc<pld>;
using str = string;
constexpr char el = '\n';
constexpr char sp = ' ';
constexpr int inf = 0x3f3f3f3f;
constexpr ll llinf = 0x3f3f3f3f3f3f3f3fLL;
// ---------------------------------------------------------------------
const int N = 8e4+5;
int n, m, ans[N], a[N], b[N], c[N], d[N], co[N], y[N], pa[N];
vi cc, adj[N];
set<int> colors[N];
struct segtree {
int size=1, tr[12*N];
void init() {
while(size < ssize(cc))
size *= 2;
}
void push(int i){
if(tr[i] != inf && i<size)
tr[2*i] = tr[2*i+1] = tr[i];
tr[i] = inf;
}
void set(int l, int r, int i, int il, int ir, int x){
if(ir < l || r < il)
return;
if(l <= il && ir <= r){
tr[i] = x;
return;
}
push(i);
int im = (il+ir)/2;
set(l, r, 2*i, il, im, x);
set(l, r, 2*i+1, im+1, ir, x);
}
void set(int l, int r, int x){
set(l, r, 1, 0, size-1, x);
}
int get(int i){
i += size;
int ans = -1;
while(i>0){
if(tr[i] != inf)
ans = tr[i];
i /= 2;
}
return ans;
}
}seg;
void unik(vi &v){
sort(all(v));
vi u{v[0]};
for(int i = 1; i < ssize(v); ++i)
if(v[i] != v[i-1])
u.pb(v[i]);
swap(u, v);
}
void dfs(int v){
for(int u: adj[v]){
dfs(u);
if(ssize(colors[v])<ssize(colors[u]))
swap(colors[v], colors[u]);
for(int x: colors[u])
colors[v].ins(x);
}
ans[v] = ssize(colors[v]);
}
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
cout << fixed; clog << fixed; clog << unitbuf;
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("debug.txt", "w", stderr);
#else
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
#endif
memset(pa, -1, sizeof pa);
cin >> n >> m;
vc<tuple<int, int, int>> e;
for(int i = 0; i < n; ++i){
cin >> a[i] >> b[i] >> c[i] >> d[i];
cc.pb(b[i]);
cc.pb(d[i]);
e.eb(a[i], 0, i);
e.eb(c[i], 2, i);
}
for(int i = 0; i < m; ++i){
int x;
cin >> x >> y[i] >> co[i];
e.eb(x, 1, i);
cc.pb(y[i]);
}
unik(cc);
seg.init();
for(int i = 0; i < n; ++i){
b[i] = lb(all(cc), b[i])-cc.begin();
d[i] = lb(all(cc), d[i])-cc.begin();
}
for(int i = 0; i < m; ++i)
y[i] = lb(all(cc), y[i])-cc.begin();
seg.set(0, ssize(cc)-1, -1);
sort(all(e));
for(auto[_, t, i]: e){
if(t==0){
int j = seg.get(b[i]);
if(~j){
adj[j].pb(i);
pa[i] = j;
}
seg.set(b[i], d[i], i);
}else if(t==1){
int j = seg.get(y[i]);
if(~j)
colors[j].ins(co[i]);
}else
seg.set(b[i], d[i], pa[i]);
}
#ifdef _DEBUG
clog << "Line " << __LINE__ << ":\n";
for(int i = 0; i < n; ++i){
for(int x: colors[i])
clog << x << sp;
clog << el;
}
clog << el;
#endif
#ifdef _DEBUG
clog << "Line " << __LINE__ << ":\n";
for(int i = 0; i < n; ++i){
for(int j: adj[i])
clog << j << sp;
clog << el;
}
clog << el;
#endif
for(int i = 0; i < n; ++i)
if(pa[i]==-1)
dfs(i);
for(int i = 0; i < n; ++i)
cout << ans[i] << el;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
78 ms |
13300 KB |
Output is correct |
2 |
Correct |
71 ms |
13836 KB |
Output is correct |
3 |
Correct |
3 ms |
6228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
14828 KB |
Output is correct |
2 |
Correct |
98 ms |
14116 KB |
Output is correct |
3 |
Correct |
4 ms |
6228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
155 ms |
21964 KB |
Output is correct |
2 |
Correct |
153 ms |
18684 KB |
Output is correct |
3 |
Correct |
3 ms |
6228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
256 ms |
31296 KB |
Output is correct |
2 |
Correct |
262 ms |
27184 KB |
Output is correct |
3 |
Correct |
3 ms |
6228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
268 ms |
29328 KB |
Output is correct |
2 |
Correct |
228 ms |
26072 KB |
Output is correct |
3 |
Correct |
3 ms |
6292 KB |
Output is correct |