Submission #671373

#TimeUsernameProblemLanguageResultExecution timeMemory
6713734EVERSunčanje (COCI18_suncanje)C++11
104 / 130
1336 ms216856 KiB
/****************************** * author : @hihihihi * * date : 13 / 12 / 2022 * ******************************/ #include <bits/stdc++.h> // #pragma GCC optimize("O2") // #pragma GCC target("avx,avx2,fma") // #pragma GCC optimize ("O3,unroll-loops,no-stack-protector") // #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // template #define PB push_back #define ALL(i_) i_.begin(), i_.end() #define LOG2(x_) (31 - __builtin_clz(x_)) #define getBit(x_, i_) ((x_ >> i_) & (ll) 1) #define rd(l_, r_) (l_ + rng() % (r_ - l_ + 1)) #define FOR(i_, a_, b_) for(int i_ = (int) (a_); i_ <= (int) (b_); ++i_) #define FORD(i_, a_, b_) for(int i_ = (int) (a_); i_ >= (int) (b_); --i_) // debugger void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef DEBUG #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif typedef long long ll; typedef long double ld; template<class X, class Y> bool minimize(X &x, const Y &y){ X eps = 1e-9; if (x > y + eps) { x = y; return 1; } return 0; } template<class X, class Y> bool maximize(X &x, const Y &y) { X eps = 1e-9; if (x + eps < y) { x = y; return 1; } return 0; } template<class T> T Abs(const T &x) { return (x < 0 ? -x : x); } template<class T> using heap_min = priority_queue<T, vector<T>, greater<T>>; template<class T> using heap_max = priority_queue<T>; const int mod = (int) 1e9 + 7; template<class X, class Y> void Add(X &x, const Y &y){ x += y; if(x >= mod) x -= mod; if(x < 0) x += mod; } const int oo = (int) 1e9 + 99; const array<int, 2> dxy8[] = { {-1, 0}, {1, 0}, {0, 1}, {0, -1}, {1, -1}, {1, 1}, {-1, 1}, {-1, -1} }; const array<int, 2> dxy4[] = { {-1, 0}, {1, 0}, {0, 1}, {0, -1} }; const int maxn = (int) 1e5 + 11; const int LOG = (int) LOG2(maxn) + 3; void File(){ #define TASK "SUNCANJE" if(fopen(TASK".inp", "r")) { freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout); } } struct item{ int x1, y1, x2, y2; item(int x1_ = 0, int y1_ = 0, int x2_ = 0, int y2_ = 0){ x1 = x1_; y1 = y1_; x2 = x2_; y2 = y2_; } } rect[maxn]; int n, m; void ReadInput(){ cin >> n; FOR(i, 1, n) { int x, y, a, b; cin >> x >> y >> a >> b; rect[i] = item(x, y, x + a, y + b); } } struct SegmentTree{ vector<set<array<int, 2>>> seg[2]; void Init(int n){ FOR(i, 0, 1){ seg[i].resize(4 * n + 11, {}); } } bool Check(set<array<int, 2>> &se, int l, int r){ if(se.empty()) return 0; auto it = se.lower_bound({l, -1}); if(it != se.end() && (*it)[0] <= r) return 1; if(it != se.begin()){ --it; if((*it)[1] >= l) return 1; } return 0; } void Insert(set<array<int, 2>> &se, int l, int r){ if(se.empty()){ se.insert({l, r}); return; } auto lf = se.upper_bound({l, -1}); auto rt = se.upper_bound({r, oo}); if(lf != se.begin()){ --lf; if((*lf)[1] < l) ++lf; } vector<array<int, 2>> temp; while(lf != rt){ temp.PB(*lf); ++lf; } for(auto x : temp){ se.erase(x); minimize(l, x[0]); maximize(r, x[1]); } se.insert({l, r}); } bool Add(int u, int v, int l, int r, int node = 1, int lf = 0, int rt = m){ if(u > rt || v < lf) return 0; if(lf >= u && rt <= v){ bool res = Check(seg[0][node], l, r) | Check(seg[1][node], l, r); Insert(seg[0][node], l, r); return res; } bool res = Check(seg[0][node], l, r); Insert(seg[1][node], l, r); int mid = (lf + rt) >> 1; res |= Add(u, v, l, r, node << 1, lf, mid); res |= Add(u, v, l, r, node << 1 | 1, mid + 1, rt); return res; } } SEG; int res[maxn]; void Solve(){ vector<int> cpr; FOR(i, 1, n) { cpr.PB(rect[i].x1); cpr.PB(rect[i].x2); cpr.PB(rect[i].y1); cpr.PB(rect[i].y2); } sort(ALL(cpr)); cpr.resize(unique(ALL(cpr)) - cpr.begin()); FOR(i, 1, n){ rect[i].x1 = lower_bound(ALL(cpr), rect[i].x1) - cpr.begin(); rect[i].x2 = lower_bound(ALL(cpr), rect[i].x2) - cpr.begin(); rect[i].y1 = lower_bound(ALL(cpr), rect[i].y1) - cpr.begin(); rect[i].y2 = lower_bound(ALL(cpr), rect[i].y2) - cpr.begin(); } m = (int) cpr.size() - 1; SEG.Init(m); FORD(i, n, 1){ res[i] = SEG.Add(rect[i].x1, rect[i].x2, rect[i].y1, rect[i].y2); } FOR(i, 1, n) cout << (res[i] ? "NE" : "DA") << "\n"; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); File(); ReadInput(); Solve(); cerr << "\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms.\n"; return 0; }

Compilation message (stderr)

suncanje.cpp: In function 'void File()':
suncanje.cpp:94:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |         freopen(TASK".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
suncanje.cpp:95:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   95 |         freopen(TASK".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...