Submission #43737

#TimeUsernameProblemLanguageResultExecution timeMemory
43737MatheusLealVPort Facility (JOI17_port_facility)C++14
10 / 100
3 ms876 KiB
#include <bits/stdc++.h> #define N 3001 #define mod (1000000000 + 7) #define f first #define s second using namespace std; typedef pair<int, int> pii; int n, ans, block[N][N], cor[N], qtd, pot[N], edge = 0, bit[N]; pii v[N]; bool nope = false; vector<int> grafo[N]; void upd(int x, int v) { for(int i = x; i < N; i += (i&-i)) bit[i] += v; } int query(int x) { int sum = 0; for(int i = x; i > 0; i -= (i&-i)) sum += bit[i]; return sum; } struct line { int pos, id, tip; bool operator < (const line &ll) const { if(pos != ll.pos) return pos < ll.pos; return tip > ll.tip; } }; vector<line> sweep; bool cmp(pii a, pii b) { if(a.f != b.f) return a.f < b.f; return a.s > b.s; } bool intersect(int i, int j) { if(v[j].f < v[i].f) swap(i, j); if(v[i].f <= v[j].f && v[j].s <= v[i].s) return false; if(v[i].f < v[j].f && v[j].f < v[i].s) return true; return false; } void dfs_color(int x) { for(auto v: grafo[x]) { if(cor[v] == cor[x]) { nope = true; return; } if(cor[v] != -1) continue; cor[v] = (cor[x] + 1)%2; dfs_color(v); } } int main() { ios::sync_with_stdio(false); cin.tie(0); cin>>n; for(int i = 1; i <= n; i++) { cin>>v[i].f>>v[i].s; sweep.push_back( { v[i].f, i, 0 } ); sweep.push_back( { v[i].s, i, 1 } ); } sort(sweep.begin(), sweep.end()); set< pii > open; for(int i = 0; i < sweep.size(); i++) { int x = sweep[i].pos, id = sweep[i].id, tip = sweep[i].tip; if(edge > 2*n) { nope = true; break; } if(!tip) { //cout<<"INSERE "<<x<<"\n"; open.insert( {x, id} ); } else { open.erase( {v[id].f, id } ); //cout<<"REMOVE "<<v[id].f<<" "<<x<<"\n"; if(open.size()) { auto it = open.begin(); int ini = (*it).f, jd = (*it).s; //cout<<ini<<"\n"; if(edge > 2*n) { nope = true; break; } if(v[id].f < ini && ini < x) { edge ++; grafo[id].push_back(jd); grafo[jd].push_back(id); //cout<<"BLOCK "<<id<<" "<<jd<<"\n"; } } for(auto it = open.upper_bound( {x, 0} ); it != open.begin() ; it--) { int ini = (*it).f, jd = (*it).s; if(it == open.end()) continue; //cout<<ini<<"\n"; if(edge > 2*n) { nope = true; break; } if(v[id].f < ini && ini < x) { edge ++; grafo[id].push_back(jd); grafo[jd].push_back(id); //cout<<"BLOCK "<<id<<" "<<jd<<"\n"; } else break; } } } pot[0] = 1; for(int i = 1; i <= n; i++) pot[i] = (2*pot[i - 1])%mod; memset(cor, -1, sizeof cor); for(int i = 1; i <= n; i++) { if(cor[i] == -1) { qtd ++; cor[i] = 0; dfs_color(i); } } cout<<(nope ? 0 : pot[qtd])<<"\n"; }

Compilation message (stderr)

port_facility.cpp: In function 'int main()':
port_facility.cpp:101:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < sweep.size(); i++)
                   ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...