#include <bits/stdc++.h>
#define MAX 10001
#define INF LLONG_MAX
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ins insert
#define ff first
#define ss second
#define gett(x,m) get<m>(x)
#define all(a) a.begin(),a.end()
#define lb(a,b) lower_bound(all(a),b)
#define ub(a,b) upper_bound(all(a),b)
#define sortv(a) sort(all(a))
#define sorta(a,sz) sort(a,a+sz)
#define inputar(a,b){\
for(int i=0;i<b;i++){\
cin >> a[i];\
}\
}
#define inputvec(a,b){\
for(int i=0;i<b;i++){\
ll num;\
cin >> num;\
a.pb(num);\
}\
}
#define outputar(a,b){\
for(int i=0;i<b;i++){\
cout << a[i] << " ";\
}\
cout << "\n";\
}
#define outputvec(a){\
for(auto x:a){\
cout << x << " ";\
}\
cout << "\n";\
}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef tuple<ll,ll,ll> tll;
typedef pair<ll,ll> pll;
typedef double db;
typedef long double ldb;
inline void USACO(string filename){
freopen((filename+".in").c_str(),"r",stdin);
freopen((filename+".out").c_str(),"w",stdout);
}
ll n,q,t=1,m,n2,m2,k,cnt=0,a[MAX],b[MAX],d[MAX],d2[MAX],x,y,z,x2,y2,z2,res1=0,cnt1,cnt2,cnt3;
ll c[501][501];
ll fact[MAX];
ll inv_fact[MAX];
//char c;
string str[MAX];
string s1,s2;
vector<tuple<ll,ll,ll>> v;
vector<pll> v1,v2,v3,v4;
const int mod = 998244353;
ll modmul(ll x,ll y,ll md){
if(y==1){
return x;
}
if(y%2){
return (x+modmul(x,y-1,md))%md;
}
else{
return (modmul((x+x)%md,y/2,md))%md;
}
}
ll powmod(ll x,ll y,ll md){
x%=md;
if(x==0){
return 0;
}
ll res=1;
while(y){
if(y%2==1){
res*=x;
res%=md;
}
x*=x;
x%=md;
y/=2;
}
return res;
}
ll pow2(ll x,ll y){
if(x==0){
return 0;
}
ll res=1;
while(y>0){
if(y%2==1){
if(res>=1e18/x){
res=1e18;
}
else{
res*=x;
}
}
if(x>=1e18/x){
x=1e18;
}
else{
x*=x;
}
y/=2;
}
return res;
}
ll inv(ll n,ll md){
return powmod(n,md-2,md);
}
ll nCkm(ll n,ll k,ll md){
if(n-k<0){
return 0;
}
return fact[n]*inv_fact[k]%md*inv_fact[n-k]%md;
}
ll nCk(ll x,ll y){
if(x<y){
return 0;
}
ll res=1;
if(y>x-y){
for(int i=y+1;i<=x;i++){
res*=i;
}
for(int i=2;i<=x-y;i++){
res/=i;
}
}
else{
for(int i=x-y+1;i<=x;i++){
res*=i;
}
for(int i=2;i<=y;i++){
res/=i;
}
}
return res;
}
ll countbits(ll x){
ll cnt=0;
while(x){
cnt+=x&1;
x>>=1;
}
return cnt;
}
ll gcd(ll x,ll y){
if(y==0){
return x;
}
return gcd(y,x%y);
}
ll lcm(ll x,ll y){
return x*y/gcd(x,y);
}
bool alpha(char c1,char c2){
ll h1,h2;
if(c1>='a'){
h1=c1-'a';
}
else{
h1=c1-'A';
}
if(c2>='a'){
h2=c2-'a';
}
else{
h2=c2-'A';
}
if(h1==h2){
return c1<c2;
}
else{
return h1<h2;
}
}
ll dx[4]={1,0,0,-1};
ll dy[4]={0,1,-1,0};
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
pll f(pll x,pll y){
if(x.ff>y.ff || (x.ff==y.ff && x.ss<y.ss)){
return mp(x.ff,x.ss);
}
else{
return mp(y.ff,y.ss);
}
}
struct segtree{
int size;
vector<pll> maximum;
/*
void build(vector<int> &a,int x,int lx,int rx){
if(rx-lx==1){
if(lx<(int)a.size()){
maximum[x]=a[lx];
}
return;
}
int m=(lx+rx)/2;
build(a,2*x+1,lx,m);
build(a,2*x+2,m,rx);
maximum[x]=max(maximum[2*x+1],maximum[2*x+2]);
}
void build(vector<int> &a){
build(a,0,0,size);
}
*/
void init(int n){
size=1;
while(size<n){
size*=2;
}
pll p={-INF,-1};
maximum.assign(2*size,p);
}
pll get_max(int l,int r,int x,int lx,int rx){
if(lx>=r || rx<=l){
return mp(-INF,(ll)-1);
}
if(lx>=l && rx<=r){
return maximum[x];
}
pll s1,s2;
int m=(lx+rx)/2;
s1=get_max(l,r,2*x+1,lx,m);
s2=get_max(l,r,2*x+2,m,rx);
return f(s1,s2);
}
pll get_max(int l,int r){
return get_max(l,r,0,0,size);
}
void set(int i,int v,int num,int x,int lx,int rx){
if(rx-lx==1){
maximum[x]=pll(v,num);
return;
}
int m=(lx+rx)/2;
if(i<m){
set(i,v,num,2*x+1,lx,m);
}
else{
set(i,v,num,2*x+2,m,rx);
}
maximum[x]=f(maximum[2*x+1],maximum[2*x+2]);
}
void set(int i,int v,int num){
set(i,v,num,0,0,size);
}
};
vector<vector<ll>> g;
set<ll> cnte[MAX];
ll res[MAX];
ll used[MAX];
void dfs(ll v){
used[v]=1;
ll h=-1;
ll ind=-1;
for(auto x:g[v]){
if(!used[x]){
dfs(x);
}
if(cnte[x].size()>h){
ind=x;
h=cnte[x].size();
}
}
if(ind!=-1){
swap(cnte[v],cnte[ind]);
}
for(auto x:g[v]){
if(x==ind){
continue;
}
for(auto y:cnte[x]){
cnte[v].ins(y);
}
}
res[v]=max(res[v],(ll)cnte[v].size());
}
struct sheet{
ll x,y,x1,y1;
};
struct ball{
ll x,y,z;
};
sheet sheets[MAX];
ball balls[MAX];
void solve(){
cin >> n >> m;
g.resize(n+1);
for(int i=0;i<n;i++){
cin >> sheets[i].x >> sheets[i].y >> sheets[i].x1 >> sheets[i].y1;
}
for(int i=0;i<m;i++){
cin >> balls[i].x >> balls[i].y >> balls[i].z;
}
unordered_map<ll,ll,custom_hash> c;
vector<ll> d;
for(int i=0;i<n;i++){
d.pb(sheets[i].x);
d.pb(sheets[i].x1);
}
for(int i=0;i<m;i++){
d.pb(balls[i].x);
}
sortv(d);
ll cnt=0;
for(int i=0;i<2*n+m;i++){
if(i && d[i]==d[i-1]){
continue;
}
c[d[i]]=cnt;
cnt++;
}
for(int i=0;i<n;i++){
sheets[i].x=c[sheets[i].x];
sheets[i].x1=c[sheets[i].x1];
}
for(int i=0;i<m;i++){
balls[i].x=c[balls[i].x];
}
c.clear();
d.clear();
for(int i=0;i<n;i++){
d.pb(sheets[i].y);
d.pb(sheets[i].y1);
}
for(int i=0;i<m;i++){
d.pb(balls[i].y);
}
sortv(d);
cnt=0;
for(int i=0;i<2*n+m;i++){
if(i && d[i]==d[i-1]){
continue;
}
c[d[i]]=cnt;
cnt++;
}
for(int i=0;i<n;i++){
sheets[i].y=c[sheets[i].y];
sheets[i].y1=c[sheets[i].y1];
}
for(int i=0;i<m;i++){
balls[i].y=c[balls[i].y];
}
segtree st;
st.init(MAX);
pll line[MAX];
vector<vector<ll>> start(MAX);
vector<vector<ll>> ended(MAX);
for(int i=0;i<n;i++){
start[sheets[i].x].pb(i);
ended[sheets[i].x1].pb(i);
}
for(int i=0;i<2*n+m;i++){
for(auto sh:start[i]){
line[sheets[sh].y]=(mp(i,sh));
st.set(sheets[sh].y,i,sh);
}
for(auto sh:ended[i]){
line[sheets[sh].y]=mp(-INF,-1);
st.set(sheets[sh].y,-INF,-1);
pll p=st.get_max(0,sheets[sh].y);
if(p.ss!=-1){
g[p.ss].pb(sh);
}
}
}
vector<vector<pll>> vec(MAX);
for(int i=0;i<m;i++){
vec[balls[i].x].pb(mp(balls[i].y,balls[i].z));
}
vector<ll> arr(2*n+m,-1);
for(int i=0;i<2*n+m;i++){
for(auto sh:start[i]){
arr[sheets[sh].y]=sh;
}
for(auto bl:vec[i]){
ll h=-1;
for(int j=bl.ff;j>=0;j--){
if(arr[j]==-1){
continue;
}
if(bl.ff>=sheets[arr[j]].y && bl.ff<=sheets[arr[j]].y1){
h=arr[j];
break;
}
}
if(h!=-1){
cnte[h].ins(bl.ss);
}
}
for(auto sh:ended[i]){
arr[sheets[sh].y]=-1;
}
}
for(int i=0;i<n;i++){
if(!used[i]){
dfs(i);
}
}
for(int i=0;i<n;i++){
cout << res[i] << "\n";
}
}
int main(){
//ios::sync_with_stdio(0);
//cin.tie(0);
//cout.tie(0);
//USACO("poetry");
//freopen("input.txt","r",stdin);
//cin >> t;
ll cnt1=1;
while(t--){
solve();
cnt1++;
}
}
/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
ifstream fin("template.in");
ofstream fout("template.out");
*/
/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
ifstream fin("template.in");
ofstream fout("template.out");
*/
/*
ll b[51][51];
b[0][0] = 1;
for (int n = 1; n <= 50; ++n){
b[n][0] = b[n][n] = 1;
for (int k = 1; k < n; ++k)
b[n][k] = b[n - 1][k - 1] + b[n - 1][k];
}
*/
Compilation message
plahte.cpp: In function 'void dfs(ll)':
plahte.cpp:281:26: warning: comparison of integer expressions of different signedness: 'std::set<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
281 | if(cnte[x].size()>h){
| ~~~~~~~~~~~~~~^~
plahte.cpp: In function 'void solve()':
plahte.cpp:382:33: warning: overflow in conversion from 'long long int' to 'int' changes value from '-9223372036854775807' to '1' [-Woverflow]
382 | st.set(sheets[sh].y,-INF,-1);
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
99 ms |
15676 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
124 ms |
19072 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
214 ms |
26964 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
395 ms |
42392 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
387 ms |
42316 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |