#include <bits/stdc++.h>
using namespace std;
struct event {
int x, y1, y2, index;
bool add;
event() {}
event(int _x, int _y1, int _y2, bool _add, int _index) {
x = _x, y1 = _y1, y2 = _y2, add = _add, index = _index;
}
bool operator < (event e) {
return x != e.x ? x < e.x : add < e.add;
}
};
int n;
void Task() {
ios_base :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
if (fopen("test.inp", "r")) {
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
}
void Solve() {
vector <event> vecEvent;
cin >> n;
vector <pair <int, int>> vecY(n);
for (int i = 0; i < n; ++i) {
int x, y, a, b;
cin >> x >> y >> a >> b;
vecEvent.push_back(event(x, y, y + b, true, i));
vecEvent.push_back(event(x + a, y, y + b, false, i));
vecY[i] = {y, y + b};
}
vector <bool> vecAns(n, true);
sort(vecEvent.begin(), vecEvent.end());
n = vecEvent.size();
set <pair <pair <int, bool>, int>> setY;
for (int i = 0; i < n; ++i) {
event e = vecEvent[i];
if (e.add) {
bool valid = true;
auto it = setY.lower_bound({{e.y1, true}, - 1});
vector <int> vecErase;
while (it != setY.end() && (!(*it).first.second || (*it).first.first <= e.y2)) {
int j = (*it).second;
if (e.index < j) {
valid = false;
} else if (e.index > j) {
vecErase.push_back(j);
}
it++;
}
for (auto j : vecErase) {
setY.erase({{vecY[j].first, true}, j});
setY.erase({{vecY[j].second, false}, j});
vecAns[j] = false;
}
if (valid) {
setY.insert({{e.y1, true}, e.index});
setY.insert({{e.y2, false}, e.index});
} else {
vecAns[e.index] = false;
}
} else {
setY.erase({{e.y1, true}, e.index});
setY.erase({{e.y2, false}, e.index});
}
}
for (auto i : vecAns) {
cout << (i ? "DA\n" : "NE\n");
}
}
int main() {
Task();
Solve();
}
Compilation message
suncanje.cpp: In function 'void Task()':
suncanje.cpp:24:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
24 | freopen("test.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
suncanje.cpp:25:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
25 | freopen("test.out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
820 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
10 ms |
1172 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
20 ms |
1868 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
26 ms |
1988 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
45 ms |
3420 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
45 ms |
3320 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
42 ms |
3432 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
6048 KB |
Output is correct |
2 |
Incorrect |
45 ms |
4756 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
74 ms |
6180 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
94 ms |
6352 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |