답안 #575459

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
575459 2022-06-10T15:25:56 Z czhang2718 Sunčanje (COCI18_suncanje) C++17
0 / 130
1173 ms 211460 KB
#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){
    	// cout << "insert  " << i << " " << lx << " " << rx << nl;
        se[x].insert(i);
        mn[x]=*se[x].begin();
        mx[x]=*--se[x].end();
        // cout << "mx[" << x << "] " << mx[x] << nl;
        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(mn[2*x+1], mn[2*x+2]);
    mx[x]=max(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;
    // cout << "get_max " << mx[x] << nl;
    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){
    	// assert(se[x].find(i)!=se[x].end());
    	// cout << "se " << lx << "-" << rx << nl;
    	// for(int p:se[x]) cout << p << " ";
    	// 	cout << nl;
    	// cout << "erase " << i << nl;
    	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;
        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(mn[2*x+1], mn[2*x+2]);
    mx[x]=max(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;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 65 ms 82504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 110 ms 92684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 229 ms 106460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 300 ms 119252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 511 ms 143624 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 511 ms 146200 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 515 ms 145248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 769 ms 177420 KB Output is correct
2 Incorrect 542 ms 148564 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 934 ms 185860 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1173 ms 211460 KB Output isn't correct
2 Halted 0 ms 0 KB -