#include <bits/stdc++.h>
using namespace std;
#define int int64_t //be careful about this
#define pr pair
#define ar array
#define f first
#define s second
#define vt vector
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define SZ(x) ((int)(x).size())
#define all(a) (a).begin(),(a).end()
#define allr(a) (a).rbegin(),(a).rend()
#define mem(a,b) memset(a, b, sizeof(a))
template<class A> void rd(vt<A>& v);
template<class T> void rd(T& x){ cin >> x;}
template<class H, class... T> void rd(H& h, T&... t) { rd(h); rd(t...);}
template<class A> void rd(vt<A>& x) { for(auto& a : x) rd(a);}
template<class T> bool ckmin(T& a, const T b) { return b < a ? a = b, 1 : 0;}
template<class T> bool ckmax(T& a, const T b) { return a < b ? a = b, 1 : 0;}
template<typename T>
void __p(T a) {
cout<<a;
}
template<typename T, typename F>
void __p(pair<T, F> a) {
cout<<"{";
__p(a.first);
cout<<",";
__p(a.second);
cout<<"}\n";
}
template<typename T>
void __p(std::vector<T> a) {
cout<<"{";
for(auto it=a.begin(); it<a.end(); it++)
__p(*it),cout<<",}\n"[it+1==a.end()];
}
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) {
__p(a1);
__p(a...);
}
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
cout<<name<<" : ";
__p(arg1);
cout<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
int bracket=0,i=0;
for(;; i++)
if(names[i]==','&&bracket==0)
break;
else if(names[i]=='(')
bracket++;
else if(names[i]==')')
bracket--;
const char *comma=names+i;
cout.write(names,comma-names)<<" : ";
__p(arg1);
cout<<" | ";
__f(comma+1,args...);
}
#define trace(...) cout<<"Line:"<<__LINE__<<" ", __f(#__VA_ARGS__, __VA_ARGS__)
void setIO(string s = "") {
ios_base::sync_with_stdio(0); cin.tie(0);
cout.precision(20); cout << fixed;
if(SZ(s)){
freopen((s+".in").c_str(),"r",stdin);
freopen((s+".out").c_str(),"w",stdout);
}
}
/*/--------------------------------------------------look below-----------------------------------------------------------------------------------/*/
struct Rect{
int a,b,c,d,id;
};
signed main(){
setIO();
int N,M;
rd(N,M);
vt<Rect> rect;
for(int i = 0; i < N; ++i){
Rect R;
int a,b,c,d;
rd(a,b,c,d);
R.a=a,R.b=b,R.c=c,R.d=d,R.id=i;
rect.pb(R);
}
vt<int> par(N,-1);
{
vt<pr<int,int>> events;
for(int i = 0; i < N; ++i){
events.eb(i,+1);
events.eb(i,-1);
}
sort(all(events),[&](auto l,auto r){
if(l.f == r.f)
return l.s > r.s;
if(l.s == 1 && r.s == 1)
return (rect[l.f].a == rect[r.f].a ? rect[l.f].b < rect[r.f].b : rect[l.f].a < rect[r.f].a);
if(l.s == 1 && r.s == -1)
return (rect[l.f].a == rect[r.f].c ? true : rect[l.f].a < rect[r.f].c);
if(l.s == -1 && r.s == 1)
return (rect[l.f].c == rect[r.f].a ? false : rect[l.f].c < rect[r.f].a);
if(l.s == -1 && r.s == -1)
return (rect[l.f].c == rect[r.f].c ? rect[l.f].d > rect[r.f].d : rect[l.f].c < rect[r.f].c);
});
set<ar<int,3>> s;
for(auto [i,t] : events){
if(t < 0){
s.erase(s.find({rect[i].b,i,-1}));
s.erase(s.find({rect[i].d,i,+1}));
}else{
s.insert({rect[i].b,i,-1});
s.insert({rect[i].d,i,+1});
auto itr = s.find({{rect[i].b,i,-1}});
if(itr != s.begin()){
--itr;
if((*itr)[2] < 0)
par[i] = (*itr)[1];
else
par[i] = par[(*itr)[1]];
}
}
}
}
vt<int> x(M),y(M),k(M);
for(int i = 0; i < M; ++i)
rd(x[i],y[i],k[i]);
vt<set<int>> have(N);
{
vt<pr<int,int>> events;
for(int i = 0; i < N; ++i){
events.eb(i,+1);
events.eb(i,-1);
}
for(int i = 0; i < M; ++i){
events.eb(i,0);
}
sort(all(events),[&](auto l,auto r){
if(l.s != 0 && r.s != 0){
if(l.f == r.f)
return l.s > r.s;
if(l.s == 1 && r.s == 1)
return (rect[l.f].a == rect[r.f].a ? rect[l.f].b < rect[r.f].b : rect[l.f].a < rect[r.f].a);
if(l.s == 1 && r.s == -1)
return (rect[l.f].a == rect[r.f].c ? true : rect[l.f].a < rect[r.f].c);
if(l.s == -1 && r.s == 1)
return (rect[l.f].c == rect[r.f].a ? false : rect[l.f].c < rect[r.f].a);
if(l.s == -1 && r.s == -1)
return (rect[l.f].c == rect[r.f].c ? rect[l.f].d > rect[r.f].d : rect[l.f].c < rect[r.f].c);
}else{
if(l.s != 0)
return (l.s>0?rect[l.f].a<=x[r.f]:rect[l.f].c<x[r.f]);
if(r.s != 0)
return (r.s>0?x[l.f]<rect[r.f].a:x[l.f]<=rect[r.f].c);
return x[l.f] == x[r.f] ? y[l.f] < y[r.f] : x[l.f] < x[r.f];
}
});
set<ar<int,3>> s;
for(auto [i,t] : events){
if(t < 0){
s.erase(s.find({rect[i].b,i,-1}));
s.erase(s.find({rect[i].d,i,+1}));
}else if(t == 0){
auto itr = s.lb({y[i],-1,-1});
if(itr != s.end()){
if((*itr)[2] > 0 || y[i] == rect[(*itr)[1]].b){
have[(*itr)[1]].insert(k[i]);
}else{
if(par[(*itr)[1]] >= 0){
have[par[(*itr)[1]]].insert(k[i]);
}
}
}
}else{
s.insert({rect[i].b,i,-1});
s.insert({rect[i].d,i,+1});
}
}
}
vt<int> g[N];
for(int i = 0; i < N; ++i)
if(par[i] >= 0)
g[par[i]].pb(i);
vt<int> ans(N);
function<void(int)> dfs = [&](int i) -> void {
for(auto j : g[i]){
dfs(j);
if(SZ(have[i]) < SZ(have[j]))
have[i].swap(have[j]);
for(auto x : have[j])
have[i].insert(x);
have[j].clear();
}
ans[i] = SZ(have[i]);
};
for(int i = 0; i < N; ++i)
if(par[i] < 0)
dfs(i);
for(auto i : ans)
cout << i << "\n";
return 0;
}
Compilation message
plahte.cpp: In function 'void setIO(std::string)':
plahte.cpp:81:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
81 | freopen((s+".in").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
plahte.cpp:82:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
82 | freopen((s+".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
plahte.cpp: In lambda function:
plahte.cpp:157:5: warning: control reaches end of non-void function [-Wreturn-type]
157 | });
| ^
plahte.cpp: In lambda function:
plahte.cpp:216:5: warning: control reaches end of non-void function [-Wreturn-type]
216 | });
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
81 ms |
6004 KB |
Output is correct |
2 |
Correct |
79 ms |
6252 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
99 ms |
9932 KB |
Output is correct |
2 |
Correct |
105 ms |
7972 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
196 ms |
18492 KB |
Output is correct |
2 |
Correct |
178 ms |
12268 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
324 ms |
32372 KB |
Output is correct |
2 |
Correct |
327 ms |
20252 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
335 ms |
29276 KB |
Output is correct |
2 |
Correct |
327 ms |
20540 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |