This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define LOCAL
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define db 0
#define EPS (1e-7) //0.0000001 the value
#define PI (acos((ld)-1.0))
#define MAXN (100006)
#define ll long long int
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
#define space " "
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define ph push
#define btinpct(x) __builtin_popcountll((x))
#define MSB(bm) ((bm==0)?-1:(63-__builtin_clzll((bm))))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
string to_string(char c) {string s(1,c);return s;}string to_string(bool b){return (b ? "true" : "false");}template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}template <typename A>string to_string(A v) {bool first = true;string res = "{";for (const auto &x : v) {if (!first) {res += ", ";}first = false;res += to_string(x);}res += "}";return res;}void degug_out() { cerr << endl; }template <typename Head, typename... Tail>void degug_out(Head H, Tail... T) {cerr << " " << to_string(H);degug_out(T...);}inline ll gcd(ll a,ll b){if(a>b)swap(a,b);if(a==0)return b;return gcd(b%a,a);}
#ifdef LOCAL
// #define degug(...) cerr << "[" << #__VA_ARGS__ << "]:", degug_out(__VA_ARGS__)
#else
// #define degug(...) 663
#define cerr if(0)cout
#endif
#warning "// FOR has been inclusive now!!!!"
ll n;
struct rectangle {
ll a,b,c,d;
} A[MAXN];
struct node {
int s,e,m;
ll v,add;
node *l,*r;
node(ll _S,ll _E){
s=_S,e=_E,m=(s+e)>>1;
v=0;add=0;
l=r=0;
}
void cl() { if(!l)l=new node(s,m); }
void cr() { if(!r)r=new node(m+1,e); }
void update(ll x,ll y,ll nval) {
if(s==x&&e==y) { add+=nval; return; }
if(x>m)cr(), r->update(x,y,nval);
else if(y<=m)cl(), l->update(x,y,nval);
else cl(), cr(), l->update(x,m,nval),r->update(m+1,y,nval);
v=(l?l->value():0)+(r?r->value():0);
}
ll value() { if(add==0) return v;
v+=add;
if(s^e){
cl(); l->add+=add;
cr(); r->add+=add;
}
add=0;
return v;
}
ll rmq(ll x,ll y){ value();
if(s==x&&e==y) return v;
if(x>m) return r?r->rmq(x,y):0;
else if(y<=m) return l?l->rmq(x,y):0;
else return (l?l->rmq(x,m):0) + (r?r->rmq(m+1,y):0);
}
};
struct node2d {
int s,e,m;
node *v;
node2d *l,*r;
node2d(ll _S,ll _E){
s=_S,e=_E,m=(s+e)>>1;
v=new node(0,1e9);
l=r=0;
}
void cl() { if(!l)l=new node2d(s,m); }
void cr() { if(!r)r=new node2d(m+1,e); }
void update(ll x,ll y,ll c,ll d,ll nval){
if(s==x&&e==y) { v->update(c,d,nval); return; }
if(x>m)cr(), r->update(x,y,c,d,nval);
else if(y<=m)cl(), l->update(x,y,c,d,nval);
else cl(), cr(), l->update(x,m,c,d,nval),r->update(m+1,y,c,d,nval);
}
ll rmq(ll x,ll y,ll c,ll d) {
if(s==x&&e==y) return v->rmq(c,d);
ll add=v->rmq(c,d);
if(x>m)return (r?r->rmq(x,y,c,d):0)+add;
else if(y<=m)return (l?l->rmq(x,y,c,d):0)+add;
else return (l?l->rmq(x,m,c,d):0)+(r?r->rmq(m+1,y,c,d):0)+add;
}
} *seg;
int main()
{
FAST
cin>>n;
FOR(i,1,n){ cin>>A[i].a>>A[i].b>>A[i].c>>A[i].d; A[i].c=A[i].a+A[i].c-1; A[i].d=A[i].b+A[i].d-1; swap(A[i].a,A[i].b), swap(A[i].c,A[i].d); }
vector<string>ans; seg=new node2d(0,1e9);
DEC(i,n,1) {
// cerr<<A[i].a<<' '<<A[i].b<<' '<<A[i].c<<' '<<A[i].d<<' '<<fen.rmq(A[i].a+1,A[i].c+1,A[i].b+1,A[i].d+1)<<'\n';
if(seg->rmq(A[i].a,A[i].c,A[i].b,A[i].d)==0) ans.eb("DA\n"); else ans.eb("NE\n");
seg->update(A[i].a,A[i].c,A[i].b,A[i].d,1);
}
reverse(all(ans));
for(auto i:ans) cout<<i;
}
/*
5
1 1 4 2
6 1 1 1
2 2 2 3
3 4 3 2
4 0 1 2
*
3
3 3 1 1
2 2 3 3
1 1 5 5
*
2
2 2 2 3
3 4 3 2
*/
Compilation message (stderr)
suncanje.cpp:42:2: warning: #warning "// FOR has been inclusive now!!!!" [-Wcpp]
#warning "// FOR has been inclusive now!!!!"
^~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |