Submission #1062755

#TimeUsernameProblemLanguageResultExecution timeMemory
1062755UnforgettableplPort Facility (JOI17_port_facility)C++17
0 / 100
0 ms344 KiB
#include <bits/stdc++.h> using namespace std; // #define int long long const long long modulo = 1e9+7; const int LIMIT = 1e9; int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector<pair<int,int>> ships(N); for(auto&[a,b]:ships)cin>>a>>b; vector<vector<pair<int,int>>> adj(N); sort(ships.begin(), ships.end()); set<pair<int,int>> active; for(int i=0;i<N;i++) { auto [a,b] = ships[i]; while(!active.empty() and active.begin()->first<a)active.erase(active.begin()); auto final = active.emplace(b,i).first; if(final==active.begin())continue; --final; while(active.begin()!=final) { adj[active.begin()->second].emplace_back(final->second,0); adj[final->second].emplace_back(active.begin()->second,0); active.erase(active.begin()); } adj[final->second].emplace_back(i,1); adj[i].emplace_back(final->second,1); } long long ans = 1; vector visited(N,-1); bool works = true; function<void(int,int)> dfs = [&](int x,int colour) { if(visited[x]!=-1) { if(visited[x]!=colour)works=false; return; } visited[x]=colour; for(auto&[v,wt]:adj[x])dfs(v,colour^wt); }; for(int i=0;i<N;i++)if(visited[i]==-1){ ans<<=1; ans%=modulo; dfs(i,0); } if(!works)ans=0; cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...