Submission #575469

# Submission time Handle Problem Language Result Execution time Memory
575469 2022-06-10T17:19:59 Z czhang2718 Sunčanje (COCI18_suncanje) C++17
0 / 130
1214 ms 208388 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){
        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 time Memory Grader output
1 Incorrect 60 ms 82308 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 138 ms 92352 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 198 ms 105756 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 291 ms 118236 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 532 ms 142096 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 539 ms 144396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 504 ms 143740 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 781 ms 175148 KB Output is correct
2 Incorrect 562 ms 146860 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 923 ms 183328 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1214 ms 208388 KB Output isn't correct
2 Halted 0 ms 0 KB -