#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(rx - lx == 1) {
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 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);
if(bigger_right >= left_bound) {
flag |= 1;
}
return flag;
}
int mid = (lx + rx) / 2;
int s1 = get(l, r, y_l, y_r, 2 * x + 1, lx, mid);
int s2 = get(l, r, y_l, y_r, 2 * x + 2, mid, rx);
return s1 | s2;
}
int get(int l, int r, int y_l, int y_r) {
return get(l, r, y_l, y_r, 0, 0, size);
}
void add(int l, int r, int y_l, int y_r, int x, int lx, int rx) {
if(lx >= r || rx <= l) {
return;
}
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);
if(rx - lx == 1) {
return;
}
int mid = (lx + rx) / 2;
add(l, r, y_l, y_r, 2 * x + 1, lx, mid);
add(l, r, y_l, y_r, 2 * x + 2, mid, rx);
}
void add(int l, int r, int y_l, int y_r) {
add(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.get(l, r, rectangles[i].y, rectangles[i].y + rectangles[i].h);
seg.add(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();
// dbg(inf)
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);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
494 ms |
209508 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
245 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
310 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
275 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
410 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
359 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
380 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
381 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
412 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
379 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |