#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
//#include "temp.cpp"
#include <cstdio>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x) cerr << #x <<" "; print(x); cerr << endl;
#else
#define dbg(x)
#endif
#define sz(x) (int)x.size()
#define len(x) (int)x.length()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define clr(x) (x).clear()
#define uniq(x) x.resize(unique(all(x)) - x.begin());
#define blt __builtin_popcount
#define pb push_back
#define popf pop_front
#define popb pop_back
void print(long long t) {cerr << t;}
void print(int t) {cerr << t;}
void print(string t) {cerr << t;}
void print(char t) {cerr << t;}
void print(double t) {cerr << t;}
void print(long double t) {cerr << t;}
void print(unsigned long long t) {cerr << t;}
template <class T, class V> void print(pair <T, V> p);
template <class T> void print(vector <T> v);
template <class T> void print(set <T> v);
template <class T, class V> void print(map <T, V> v);
template <class T> void print(multiset <T> v);
template <class T, class V> void print(T v[],V n) {cerr << "["; for(int i = 0; i < n; i++) {print(v[i]); cerr << " "; } cerr << "]";}
template <class T, class V> void print(pair <T, V> p) {cerr << "{"; print(p.first); cerr << ","; print(p.second); cerr << "}";}
template <class T> void print(vector <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";}
template <class T> void print(set <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";}
template <class T> void print(multiset <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void print(map <T, V> v) {cerr << "[ "; for (auto i : v) {print(i); cerr << " ";} cerr << "]";}
template <class T> void print(deque <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define nl '\n'
// for random generations
mt19937 myrand(chrono::steady_clock::now().time_since_epoch().count());
// for grid problems
int dx[8] = {-1,0,1,0,1,-1,1,-1};
int dy[8] = {0,1,0,-1,1,1,-1,-1};
// lowest / (1 << 17) >= 1e5 / (1 << 18) >= 2e5 / (1 << 21) >= 1e6
void fastIO() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
}
// file in/out
void setIO(string str = "") {
fastIO();
if (str != "" && str != "input") {
freopen((str + ".in").c_str(), "r", stdin);
freopen((str + ".out").c_str(), "w", stdout);
}
if(str == "input") {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
}
// Indexed Set
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 1e5 + 10;
vector<int> compress_x, compress_y;
int n, answ[N];
struct rect {
int x, y, w, h;
};
struct segment {
int l, r;
};
// bit
struct fenwick {
int size;
vector<long long> tree;
void init(int size_) {
tree.assign(size_ + 2, 0);
size = size_;
}
void upd(int u, long long v) {
while(u <= size) {
tree[u] = max(tree[u], v);
u += u & (-u);
}
}
long long qry(int u) {
long long sum = 0;
while(u > 0) {
sum = max(sum, tree[u]);
u -= u & (-u); // lsb
}
return sum;
}
};
struct segTree {
int size = 1;
vector<int> tree[N * 30];
fenwick ft[N * 30];
void init(int s) {
while(size < s) {
size *= 2;
}
}
void add_to_the_tree(int l, int r, int y_l, int y_r, int x, int lx, int rx) {
if(lx >= r || rx <= l) {
return;
}
{
tree[x].push_back(y_l);
tree[x].push_back(y_r);
}
if(lx >= l && rx <= r) {
tree[x].push_back(y_l);
tree[x].push_back(y_r);
return;
}
int mid = (lx + rx) / 2;
add_to_the_tree(l, r, y_l, y_r, 2 * x + 1, lx, mid);
add_to_the_tree(l, r, y_l, y_r, 2 * x + 2, mid, rx);
}
void add_to_the_tree(int l, int r, int y_l, int y_r) {
add_to_the_tree(l, r, y_l, y_r, 0, 0, size);
}
void build(int x, int lx, int rx) {
//
sort(all(tree[x]));
uniq(tree[x]);
ft[x].init(sz(tree[x]) + 1);
if(rx - lx == 1) {
return;
} else {
int mid = (lx + rx) / 2;
build(2 * x + 1, lx, mid);
build(2 * x + 2, mid, rx);
}
}
void build() {
build(0, 0, size);
}
int add_get(int l, int r, int y_l, int y_r, int x, int lx, int rx) {
if(lx >= r || rx <= l) {
return 0;
}
if(lx >= l && rx <= r) {
int flag = 0;
int left_bound = lower_bound(all(tree[x]), y_l) - tree[x].begin() + 1;
int right_bound = lower_bound(all(tree[x]), y_r) - tree[x].begin() + 1;
long long bigger_right = ft[x].qry(right_bound);
ft[x].upd(left_bound, right_bound);
if(bigger_right >= left_bound) {
flag |= 1;
}
return flag;
}
int left_bound = lower_bound(all(tree[x]), y_l) - tree[x].begin() + 1;
int right_bound = lower_bound(all(tree[x]), y_r) - tree[x].begin() + 1;
ft[x].upd(left_bound, right_bound);
int mid = (lx + rx) / 2;
int s1 = add_get(l, r, y_l, y_r, 2 * x + 1, lx, mid);
int s2 = add_get(l, r, y_l, y_r, 2 * x + 2, mid, rx);
return s1 | s2;
}
int add_get(int l, int r, int y_l, int y_r) {
return add_get(l, r, y_l, y_r, 0, 0, size);
}
};
segTree seg;
void solve_() {
cin >> n, seg.init(n + 10);
vector<rect> rectangles;
for(int i = 1; i <= n; i++) {
int x, y, w, h; cin >> x >> y >> w >> h;
//
compress_x.push_back(x);
compress_x.push_back(x + w);
//
rectangles.push_back({x, y, w, h});
}
sort(all(compress_x));
uniq(compress_x)
// dbg(compress_x)
for(int i = n - 1; i >= 0; i--) {
int l = lower_bound(all(compress_x), rectangles[i].x) - compress_x.begin() + 1;
int r = lower_bound(all(compress_x), rectangles[i].x + rectangles[i].w) - compress_x.begin() + 1;
// dbg(l)
// dbg(r)
seg.add_to_the_tree(l, r + 1, rectangles[i].y, rectangles[i].y + rectangles[i].h);;
}
seg.build();
for(int i = n - 1; i >= 0; i--) {
int l = lower_bound(all(compress_x), rectangles[i].x) - compress_x.begin() + 1;
int r = lower_bound(all(compress_x), rectangles[i].x + rectangles[i].w) - compress_x.begin() + 1;
answ[i] = seg.add_get(l, r, rectangles[i].y, rectangles[i].y + rectangles[i].h);
// dbg(answ[i])
}
for(int i = 0; i < n; i++) {
if(answ[i]) {
cout << "NE" << "\n";
} else {
cout << "DA" << "\n";
}
}
}
int main() {
setIO();
auto solve = [&](int test_case)-> void {
for(int i = 1; i <= test_case; i++) {
// cout << "Case #" << i << ": ";
solve_();
}
};
int test_cases = 1;
// cin >> test_cases;
solve(test_cases);
return 0;
}
Compilation message
suncanje.cpp: In function 'void setIO(std::string)':
suncanje.cpp:67:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
67 | freopen((str + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
suncanje.cpp:68:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
68 | freopen((str + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
suncanje.cpp:72:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
72 | freopen("input.txt", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
suncanje.cpp:73:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
73 | freopen("output.txt", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
96 ms |
167864 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
142 ms |
171872 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
227 ms |
180188 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
250 ms |
180888 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
476 ms |
197200 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
532 ms |
197264 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
453 ms |
193972 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
905 ms |
224344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1040 ms |
231448 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1137 ms |
232592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |