Submission #69291

#TimeUsernameProblemLanguageResultExecution timeMemory
69291InovakPort Facility (JOI17_port_facility)C++14
0 / 100
2 ms248 KiB
#include <bits/stdc++.h>

#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define ll long long
#define OK puts("OK");
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()

using namespace std;

const int N = 2e6+10;
const int mod = 1e9+7;

int n;
pair <int, int> p[N];
stack <int> a, b;
ll ans = 1;
bool u[N];

bool go (stack <int> a, stack <int> b, int k) {
    for(int i = k; i <= n; i++) {
        while(a.top() < p[i].fr) a.pop();
        while(b.top() < p[i].fr) b.pop();
        if(a.top() < b.top()) {
            if(a.top() > p[i].sc) a.push(p[i].sc);
            else if(b.top() > p[i].sc) b.push(p[i].sc);
            else return 0;
        }
        else {
            if(b.top() > p[i].sc) b.push(p[i].sc);
            else if(a.top() > p[i].sc) a.push(p[i].sc);
            else return 0;
        }
    }
    return 1;
}
int pa[N];

int f_s(int a) {
    return pa[a] == a ? a : pa[a] = f_s(pa[a]);
}

void un_s(int a, int b) {
    a = f_s(a);
    b = f_s(b);
    if(a != b) {
        pa[b] = a;
    }
}

int main() {
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        scanf("%d%d", &p[i].fr, &p[i].sc);
        pa[i] = i;
    }
    a.push(mod);
    b.push(mod);
    sort(p + 1, p + n + 1);

    if(!go(a, b, 1)) {puts("0");return 0;}

    for(int i = 1; i <= n; i++) {
        for(int j = 1; j < i; j++) {
            if(p[i].sc > p[j].sc && p[i].fr < p[j].sc) un_s(i, j);
        }
    }
    ll cnt = 0;
    for(int i = 1; i <= n; i++) {
        if(!u[f_s(i)]) {
            u[f_s(i)] = 1;
            cnt++;
        }
    }
    ll ans = 1;
    while(cnt--) {
        ans = ans * 2 % mod;
    }
    cout << ans << endl;


}

Compilation message (stderr)

port_facility.cpp: In function 'int main()':
port_facility.cpp:55:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
port_facility.cpp:57:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &p[i].fr, &p[i].sc);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...