// When they saw the star, they were overjoyed. On coming to the house,
// they saw the child with his mother Mary, and they bowed down and
// worhipped him. Then they opened their treasures and presented him with
// gifts of gold, frankincense and myrrh.
// Matthew 2:10-11
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define MP make_pair
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define MT make_tuple
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
#ifdef DEBUG
#define debug(args...) printf(args)
#else
#define debug(args...)
#endif
#define INF 1000000005
#define LINF 1000000000000000005
#define MOD 1000000007
#define MAXN 300005
struct store {
int x, t, a, b;
bool operator< (const store& o) const {
return x < o.x;
}
};
struct qry {
int l, y, id;
bool operator< (const qry& o) const {
return l < o.l;
}
};
struct ev {
int t, x, v;
bool operator< (const ev& o) const {
return t < o.t;
}
};
struct ray {
int x;
mutable int h, t;
bool operator< (const ray& o) const {
return x < o.x;
}
bool operator> (const ray& o) const {
return x > o.x;
}
};
struct upd {
int x, h, s, e;
bool operator< (const upd& o) const {
return x < o.x;
}
};
int n, k, q;
store stores[MAXN];
qry qrys[MAXN];
vector<ev> evs[MAXN];
int cnt[MAXN];
vii dis;
int m;
vector<upd> zigu, zagu;
void insert(bool b, ray r, int s, int e) {
if (s > e) return;
r.h = abs(r.h);
debug("%d %d %d: %d %d\n", b, s, e, r.x, r.h);
if (!b) {
zigu.pb((upd) {r.x, r.h, s, e});
} else {
zagu.pb((upd) {r.x, r.h, s, e});
}
}
void dfs(int s = 0, int e = q - 1, int u = 1, int lo = 0, int hi = m) {
}
int main() {
scanf("%d%d%d", &n, &k, &q);
REP (i, 0, n) {
int x, t, a, b; scanf("%d%d%d%d", &x, &t, &a, &b);
x *= 2;
stores[i] = (store) {x, t, a, b};
dis.pb(MP(a, i));
dis.pb(MP(b, i + n));
}
REP (i, 0, q) {
int l, y; scanf("%d%d", &l, &y);
l *= 2;
qrys[i] = (qry) {l, y, i};
dis.pb(MP(y, i + 2 * n));
}
sort(ALL(dis));
int prv = -1;
for (auto [a, b] : dis) {
if (a != prv) {
m++;
prv = a;
}
if (b < n) {
stores[b].a = m - 1;
} else if (b < 2 * n) {
stores[b - n].b = m - 1;
} else {
qrys[b - 2 * n].y = m - 1;
}
}
REP (i, 0, n) {
debug("%d %d %d %d\n", stores[i].x, stores[i].t, stores[i].a, stores[i].b);
}
REP (i, 0, q) {
debug("%d %d\n", qrys[i].l, qrys[i].y);
}
sort(qrys, qrys + q);
REP (i, 0, n) {
evs[stores[i].t].pb((ev) {stores[i].a, stores[i].x, 1});
evs[stores[i].t].pb((ev) {stores[i].b + 1, stores[i].x, -1});
}
REP (i, 1, k + 1) {
sort(ALL(evs[i]));
{
set<ray> rays;
for (ev e : evs[i]) {
//debug(" %d %d %d\n", e.t, e.x, e.v);
if (e.v == 1) {
if (cnt[e.x]++ > 0) {
continue;
}
auto it = rays.upper_bound((ray) {e.x, INF, INF});
if (it != rays.end()) {
insert(0, *it, it -> t, e.t - 1);
it -> t = e.t;
int isect = it -> x - e.x >> 1;
it -> h = isect;
}
if (it == rays.begin()) {
rays.insert((ray) {e.x, INF, e.t});
} else {
it = prev(it);
assert(it -> x != e.x);
int isect = e.x - it -> x >> 1;
rays.insert((ray) {e.x, isect, e.t});
}
} else {
if (--cnt[e.x] > 0) {
continue;
}
auto it = rays.lower_bound((ray) {e.x, -1, -1});
assert(it -> x == e.x);
insert(0, *it, it -> t, e.t - 1);
if (next(it) != rays.end()) {
auto nxt = next(it);
insert(0, *nxt, nxt -> t, e.t - 1);
nxt -> t = e.t;
nxt -> h += it -> h;
mnto(nxt -> h, INF);
}
rays.erase(it);
}
}
while (!rays.empty()) {
auto it = rays.begin();
insert(0, *it, it -> t, m);
rays.erase(it);
}
for (ev e : evs[i]) {
cnt[e.x] = 0;
}
}
/*
{
set<ray, greater<ray>> rays;
for (ev e : evs[i]) {
//debug(" %d %d %d\n", e.t, e.x, e.v);
if (e.v == 1) {
auto it = rays.upper_bound((ray) {e.x, INF, INF});
if (it != rays.end()) {
insert(1, *it, it -> t, e.t - 1);
it -> t = e.t;
int isect = it -> x - e.x >> 1;
it -> h = isect;
}
if (it == rays.begin()) {
rays.insert((ray) {e.x, INF, e.t});
} else {
it = prev(it);
if (it -> x == e.x) {
continue;
}
int isect = e.x - it -> x >> 1;
rays.insert((ray) {e.x, isect, e.t});
}
} else {
auto it = rays.lower_bound((ray) {e.x, -1, -1});
assert(it -> x == e.x);
insert(1, *it, it -> t, e.t - 1);
if (next(it) != rays.end()) {
auto nxt = next(it);
insert(1, *nxt, nxt -> t, e.t - 1);
nxt -> t = e.t;
nxt -> h += it -> h;
mnto(nxt -> h, INF);
}
rays.erase(it);
}
}
while (!rays.empty()) {
auto it = rays.begin();
insert(1, *it, it -> t, m);
rays.erase(it);
}
}
*/
}
}
/*
4 2 4
3 1 1 10
9 2 2 4
7 2 5 7
4 1 8 10
5 3
5 6
5 9
1 10
*/
Compilation message
new_home.cpp: In function 'int main()':
new_home.cpp:154:27: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
154 | int isect = it -> x - e.x >> 1;
| ~~~~~~~~^~~~~
new_home.cpp:162:23: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
162 | int isect = e.x - it -> x >> 1;
| ~~~~^~~~~~~~~
new_home.cpp:100:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
100 | scanf("%d%d%d", &n, &k, &q);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:102:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
102 | int x, t, a, b; scanf("%d%d%d%d", &x, &t, &a, &b);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:109:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
109 | int l, y; scanf("%d%d", &l, &y);
| ~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
7244 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
7244 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
316 ms |
68216 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
322 ms |
66376 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
7244 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
7244 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |