Submission #961147

#TimeUsernameProblemLanguageResultExecution timeMemory
961147abczzPort Facility (JOI17_port_facility)C++14
0 / 100
1 ms6488 KiB
#include <iostream> #include <vector> #include <array> #include <map> #define ll long long using namespace std; ll n, s, f = 1, X[1000000], P[1000000], M = 1e9 + 7; vector <ll> V, U; map <ll, ll> mp; bool B[1000000]; array <ll, 2> A[1000000], R[1000000]; ll dsu(ll u) { if (u == P[u]) return u; else return P[u] = dsu(P[u]); } int main() { cin.tie(0); ios::sync_with_stdio(0); cin >> n; for (int i=0; i<n; ++i) { P[i] = i; cin >> R[i][0] >> R[i][1]; --R[i][0], --R[i][1]; A[R[i][0]] = {i, 0}, A[R[i][1]] = {i, 1}; } for (int i=0; i<2*n; ++i) { if (!A[i][1]) { auto it = mp.lower_bound(R[A[i][0]][1]); if (it != mp.begin()) { it = prev(it); X[A[i][0]] = it->first; } else X[A[i][0]] = -1e18; ++mp[R[A[i][0]][1]]; } } mp.clear(); for (int i=2*n-1; i>=0; --i) { if (A[i][1]) { auto it = mp.lower_bound(R[A[i][0]][0]); if (it != mp.end() && X[A[i][0]] != -1e18 && it->first < X[A[i][0]]) { cout << "0\n"; return 0; } ++mp[R[A[i][0]][0]]; } } for (int i=0; i<2*n; ++i) { if (A[i][1]) { while (!V.empty()) { auto u = V.back(); if (u < R[A[i][0]][0]) break; V.pop_back(); if (!B[u]) { U.push_back(u); P[dsu(u)] = dsu(A[i][0]); } } while (!U.empty()) { auto u = U.back(); U.pop_back(); V.push_back(u); } B[A[i][0]] = 1; } else V.push_back(A[i][0]); } mp.clear(); for (int i=0; i<n; ++i) { ++mp[dsu(i)]; } for (int i=0; i<mp.size(); ++i) { f *= 2; f %= M; } cout << f << '\n'; }

Compilation message (stderr)

port_facility.cpp: In function 'int main()':
port_facility.cpp:74:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::map<long long int, long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |   for (int i=0; i<mp.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...