#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 80001;
int N,M,par[MX], ans[MX];
int C[MX], Y[MX];
int B[MX], D[MX];
set<int> tmp[MX];
vector<array<int,3>> ins;
set<array<int,3>> cur;
vi child[MX];
int getPar(int y) {
auto it = cur.lb({y,0,0});
if (it == cur.end()) return 0;
if ((*it)[1] == -1) return par[(*it)[2]];
return (*it)[2];
}
void comb(int a, int b) {
bool swa = 0;
if (sz(tmp[a]) < sz(tmp[b])) swap(a,b), swa = 1;
for (int i: tmp[b]) tmp[a].insert(i);
tmp[b].clear();
if (swa) swap(tmp[a],tmp[b]);
}
void dfs(int x) {
for (int i: child[x]) {
dfs(i);
comb(x,i);
}
ans[x] = sz(tmp[x]);
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> N >> M;
FOR(i,1,N+1) {
int A,C; cin >> A >> B[i] >> C >> D[i];
ins.pb({A,-1,i}); ins.pb({C,1,i});
}
FOR(i,1,M+1) {
int X; cin >> X >> Y[i] >> C[i];
ins.pb({X,0,i});
}
sort(all(ins));
for (auto a: ins) {
if (a[1] == -1) {
par[a[2]] = getPar(B[a[2]]);
cur.insert({B[a[2]],-1,a[2]});
cur.insert({D[a[2]],1,a[2]});
// cout << "AH " << a[2] << " " << par[a[2]] << "\n";
} else if (a[1] == 0) {
// cout << getPar(Y[a[2]]) << "\n";
tmp[getPar(Y[a[2]])].insert(C[a[2]]);
} else {
cur.erase({B[a[2]],-1,a[2]});
cur.erase({D[a[2]],1,a[2]});
}
}
FOR(i,1,N+1) child[par[i]].pb(i);
dfs(0);
FOR(i,1,N+1) cout << ans[i] << "\n";
}
/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* special cases (n=1?)
* overflow (ll vs int?)
* array bounds
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
96 ms |
10732 KB |
Output is correct |
2 |
Correct |
107 ms |
12088 KB |
Output is correct |
3 |
Correct |
8 ms |
12088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
120 ms |
17096 KB |
Output is correct |
2 |
Correct |
133 ms |
17468 KB |
Output is correct |
3 |
Correct |
9 ms |
17468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
228 ms |
27200 KB |
Output is correct |
2 |
Correct |
236 ms |
27200 KB |
Output is correct |
3 |
Correct |
9 ms |
27200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
410 ms |
41196 KB |
Output is correct |
2 |
Correct |
457 ms |
41196 KB |
Output is correct |
3 |
Correct |
8 ms |
41196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
367 ms |
49308 KB |
Output is correct |
2 |
Correct |
370 ms |
49308 KB |
Output is correct |
3 |
Correct |
8 ms |
49308 KB |
Output is correct |