제출 #481038

#제출 시각아이디문제언어결과실행 시간메모리
481038KalashnikovPort Facility (JOI17_port_facility)C++17
22 / 100
6090 ms8164 KiB
#include <bits/stdc++.h> #define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout) #define all(a) a.begin() , a.end() #define F first #define S second using namespace std; using ll = long long; const int N = 1e6+5 , inf = 2e9 + 7; const ll INF = 1e18 , mod = 1e9+7 , P = 6547; int u[N]; int p[N] , sz[N] , col[N] , q[N]; int get(int v) { if(v == p[v]) return v; return get(p[v]); } int getc(int v) { if(v == p[v]) return q[v]; return getc(p[v])^1^q[v]; } int merge(int a , int b) { int tb = b , ta = a; a = get(a); b = get(b); if(a == b) return 0; if(sz[a] < sz[b]) swap(a , b); if(getc(tb)%2 != getc(ta)%2) { q[b] ^= 1; } sz[a] += sz[b]; p[b] = a; // cout << ta << ' ' << tb << '\n'; return 1; } void solve(int tc) { int n; cin >> n; vector<pair<int,int>> v; for(int i = 1; i <= n; i ++) { int a , b; cin >> a >> b; v.push_back({a , b}); p[i] = i; sz[i] = 1; col[i] = 1; } sort(all(v)); set<pair<int,int>> st; int cnt = n; for(int i = 0; i < v.size(); i ++) { pair<int,int> to = v[i]; int last = 2*n; while(st.size() && st.begin()->F < v[i].F) { st.erase(*st.begin()); } auto it = st.begin(); // cout << i << '\n'; while(it != st.end() && it->F < to.S) { if(v[it->S - 1].F >= last) { cout << 0; return; } if(merge(it->S , i+1)) cnt --; else { // cout << it->S << ' ' << i+1 << '\n'; // cout << getc(it->S) << ' ' << getc(i+1) << '\n'; if((getc(it->S) + getc(i+1)) % 2 == 0) { cout << 0; return; } } // if(i == 3) { // for(int j = 1; j <= n; j ++) { // cout << getc(j) << ' '; // }cout << '\n'; // } last = v[it->S - 1].F; it ++; } st.insert({to.S , i+1}); } ll ans = 1; for(int i = 1; i <= cnt; i ++) { ans *= 2; ans %= mod; } cout << ans; } /* 5 1 9 2 4 3 7 5 10 6 8 4 1 4 2 7 3 6 5 8 */ main() { ios; int tt = 1 , tc = 0; // cin >> tt; while(tt --) { solve(++tc); } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

port_facility.cpp: In function 'void solve(int)':
port_facility.cpp:59:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |  for(int i = 0; i < v.size(); i ++) {
      |                 ~~^~~~~~~~~~
port_facility.cpp: At global scope:
port_facility.cpp:115:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  115 | main() {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...