#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define OPT ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define endl "\n"
#define all(v) v.begin(), v.end()
#define mpr make_pair
#define pb push_back
#define ts to_string
#define fi first
#define se second
#define inf 0x3F3F3F3F
#define bpc __builtin_popcount
#define print(v) for(int i = 0; i < v.size(); i++) \
cout << v[i] << " "; \
cout<<endl;
/*
int ternarySearch(int l, int r, int key, int ar[])
{
if (r >= l)
{
int mid1 = l + (r - l) / 3;
int mid2 = r - (r - l) / 3;
if (ar[mid1] == key) {
return mid1;
}
if (ar[mid2] == key) {
return mid2;
}
if (key < ar[mid1]) {
return ternarySearch(l, mid1 - 1, key, ar);
}
else if (key > ar[mid2]) {
return ternarySearch(mid2 + 1, r, key, ar);
}
else {
return ternarySearch(mid1 + 1, mid2 - 1, key, ar);
}
}
return -1;
}
*/
struct DSU {
vector<int> e;
void init(int n)
{
e.assign(n, -1);
}
int get(int x)
{
if (e[x] < 0)
return x;
return e[x] = get(e[x]);
}
bool together(int a, int b)
{
return get(a) == get(b);
}
int s(int x)
{
return -e[get(x)];
}
bool unite(int x, int y)
{
x = get(x);
y = get(y);
if (x == y) return false;
if (e[x] > e[y]) swap(x, y);
e[x] += e[y];
e[y] = x;
return true;
}
};
struct cor
{
int lx, ly, rx, ry, id;
};
struct shot
{
int x, y, col, id;
};
bool cmp1(cor &a, cor &b)
{
if (a.lx == b.lx) return a.rx <= b.rx;
return a.lx <= b.lx;
}
bool cmp2(shot &a, shot &b)
{
if (a.x == b.x) return a.y <= b.y;
return a.x <= b.x;
}
int main()
{
int n, m;
cin >> n >> m;
vector<cor> a(n + 1);
vector<shot> b(m + 1);
set<int> tim;
for (int i = 1; i <= n; i++)
{
cin >> a[i].lx >> a[i].ly >> a[i].rx >> a[i].ry;
a[i].id = i;
tim.insert(a[i].lx);
tim.insert(a[i].rx);
}
sort(a.begin() + 1, a.end(), cmp1);
for (int i = 1; i <= m; i++)
{
cin >> b[i].x >> b[i].y >> b[i].col;
b[i].id = i;
tim.insert(b[i].x);
tim.insert(b[i].y);
}
sort(b.begin() + 1, b.end(), cmp2);
int i = 1;
int j = 1;
unordered_set<int> onc;
vector<unordered_set<int>> ans(n + 1);
for (int t : tim)
{
unordered_set<int> deleted;
for (int x : onc)
{
if (a[x].ry < t)
{
deleted.insert(x);
}
}
for (int x : deleted)
{
onc.erase(x);
}
while (i <= n && t == a[i].lx)
{
onc.insert(i);
i++;
}
while (j <= m && t == b[j].x)
{
for (int x : onc)
{
if (b[j].y >= a[x].ly && b[j].y <= a[x].ry)
{
ans[a[x].id].insert(b[j].id);
}
}
j++;
}
}
for (int i = 1; i <= n; i++)
{
cout << ans[i].size() << endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2082 ms |
304016 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2080 ms |
281428 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2081 ms |
188308 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2069 ms |
192736 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2081 ms |
171056 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |