Submission #575469

#TimeUsernameProblemLanguageResultExecution timeMemory
575469czhang2718Sunčanje (COCI18_suncanje)C++17
0 / 130
1214 ms208388 KiB
#include "bits/stdc++.h" using namespace std; #define rep(i, a, b) for(int i=a; i<=b; i++) #define all(x) begin(x), end(x) #define sz(x) (int) x.size() #define f first #define s second #define nl "\n" #define pb push_back typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pii; const int MOD=1e9+7; const int N=4e5+1; int n; int a[N], b[N], c[N], d[N]; bool bad[N]; int M; set<int> se[4*N]; int mn[4*N]; int mx[4*N]; // range insert // range kill // range get max void ins(int l, int r, int i, int x=0, int lx=0, int rx=M+1){ if(lx>=r || rx<=l) return; if(lx>=l && rx<=r){ se[x].insert(i); mn[x]=*se[x].begin(); mx[x]=*--se[x].end(); if(rx-lx>1){ mn[x]=min({mn[x], mn[2*x+1], mn[2*x+2]}); mx[x]=max({mx[x], mx[2*x+1], mx[2*x+2]}); } return; } int m=(lx+rx)/2; ins(l, r, i, 2*x+1, lx, m); ins(l, r, i, 2*x+2, m, rx); mn[x]=min({sz(se[x])?*se[x].begin():(int)1e9, mn[2*x+1], mn[2*x+2]}); mx[x]=max({sz(se[x])?*--se[x].end():0, mx[2*x+1], mx[2*x+2]}); } int get_min(int l, int r, int x=0, int lx=0, int rx=M+1){ if(lx>=r || rx<=l) return 1e9; if(lx>=l && rx<=r) return mn[x]; int m=(lx+rx)/2; return min({sz(se[x])?*se[x].begin():(int)1e9, get_min(l, r, 2*x+1, lx, m), get_min(l, r, 2*x+2, m, rx)}); } int get_max(int l, int r, int x=0, int lx=0, int rx=M+1){ if(lx>=r || rx<=l) return 0; if(lx>=l && rx<=r) return mx[x]; int m=(lx+rx)/2; return max({sz(se[x])?*--se[x].end():0, get_max(l, r, 2*x+1, lx, m), get_max(l, r, 2*x+2, m, rx)}); } void del(int l, int r, int i, int x=0, int lx=0, int rx=M+1){ if(lx>=r || rx<=l) return; if(lx>=l && rx<=r){ if(se[x].find(i)==se[x].end()) return; se[x].erase(i); mn[x]=se[x].size()?*se[x].begin():1e9; mx[x]=se[x].size()?*--se[x].end():0; if(rx-lx>1){ mn[x]=min({mn[x], mn[2*x+1], mn[2*x+2]}); mx[x]=max({mx[x], mx[2*x+1], mx[2*x+2]}); } return; } int m=(lx+rx)/2; del(l, r, i, 2*x+1, lx, m); del(l, r, i, 2*x+2, m, rx); mn[x]=min({sz(se[x])?*se[x].begin():(int)1e9, mn[2*x+1], mn[2*x+2]}); mx[x]=max({sz(se[x])?*--se[x].end():0, mx[2*x+1], mx[2*x+2]}); } int main(){ cin.tie(0)->sync_with_stdio(0); cin >> n; set<int> s; map<int, int> mp; rep(i,1,n){ cin >> a[i] >> b[i] >> c[i] >> d[i]; c[i]+=a[i]-1; d[i]+=b[i]-1; s.insert(a[i]); s.insert(b[i]); s.insert(c[i]); s.insert(d[i]); } M=sz(s); int cnt=0; for(int x:s){ mp[x]=++cnt; } map<int, vi> st, nd; rep(i,1,n){ a[i]=mp[a[i]]; b[i]=mp[b[i]]; c[i]=mp[c[i]]; d[i]=mp[d[i]]; st[a[i]].pb(i); nd[c[i]].pb(i); } // sweep line 1 for(int x:s){ for(int i:st[x]){ // cout << "process " << i << nl; int y1=b[i]; int y2=d[i]; int mx=get_max(y1, y2+1); // cout << "max " << mx << nl; if(mx>i) bad[i]=1; ins(y1, y2+1, i); } for(int i:nd[x]){ int y1=b[i]; int y2=d[i]; del(y1, y2+1, i); } } rep(i,0,4*M+4) mn[i]=1e9, mx[i]=0, se[i].clear(); // sweep line 2 for(int x:s){ for(int i:st[x]){ // cout << "rect " << i << nl; int y1=b[i]; int y2=d[i]; // cout << "kill " << y1 << " " << y2+1 << nl; while(true){ int die=get_min(y1, y2+1); if(die>i) break; // cout << "del " << die << nl; bad[die]=1; del(b[die], d[die]+1, die); } ins(y1, y2+1, i); } for(int i:nd[x]){ int y1=b[i]; int y2=d[i]; del(y1, y2+1, i); } } rep(i,1,n) cout << (bad[i]?"NE":"DA") << nl; }
#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...