Submission #155544

#TimeUsernameProblemLanguageResultExecution timeMemory
15554412tqianPort Facility (JOI17_port_facility)C++14
0 / 100
15 ms16888 KiB
#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

const double PI = 4 * atan(1);

#define sz(x) (int)(x).size()
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair <int, int>
#define vi vector<int>
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define vpi vector<pair<int, int>>
#define vpd vector<pair<double, double>>
#define pd pair<double, double>

#define f0r(i,a) for(int i=0;i<a;i++)
#define f1r(i,a,b) for(int i=a;i<b;i++)
#define trav(a, x) for (auto& a : x)

template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
  cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}

void fast_io(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
void io(string taskname){
    string fin = taskname + ".in";
    string fout = taskname + ".out";
    const char* FIN = fin.c_str();
    const char* FOUT = fout.c_str();
    freopen(FIN, "r", stdin);
    freopen(FOUT, "w", stdout);
    fast_io();
}
const int MAX = 1e6 + 6;
template<class T, int SZ> struct Seg { // SZ doesn't have to be power of 2
    const T ID = 0; // comb(ID,b) must equal b
    T comb(T a, T b) { return a+b; } // easily change this to min or max

    T seg[2*SZ];
    Seg() { memset(seg,0,sizeof seg); }

    void pull(int p) { seg[p] = comb(seg[2*p],seg[2*p+1]); }
    void reset(){ f0r(i, 2*SZ) seg[i] = 0;}
    void upd(int p, T value) {  // set value at position p
        seg[p += SZ] = value;
        for (p /= 2; p; p /= 2) pull(p);
    }

    T query(int l, int r) {  // sum on interval [l, r]
        T resl = ID, resr = ID; // make sure non-commutative operations work
        for (l += SZ, r += SZ+1; l < r; l /= 2, r /= 2) {
            if (l&1) resl = comb(resl,seg[l++]);
            if (r&1) resr = comb(seg[--r],resr);
        }
        return comb(resl,resr);
    }
};
const ll MOD = 1e9 + 7;
vpi v;
Seg<int, (1<<21)> seg;

int main(){
    fast_io();
    int n;
    cin >> n;
    f0r(i, n){
        int ai;
        int bi;
        cin >> ai >> bi;
        v.eb(mp(ai, bi));
    }
    sort(all(v));
    deque<int> a;
    deque<int> b;
    f0r(i, n){
        if(sz(a) == 0){
            a.push_back(v[i].s);
            continue;
        }
        else if(sz(b) == 0){
            b.push_back(v[i].s);
            continue;
        }
        while(a.front() < v[i].f){
            a.pop_front();
        }
        while(b.front() < v[i].f){
            b.pop_front();
        }
        if(a.front() > v[i].s){
            a.push_front(v[i].s);
        }
        else if(b.front() > v[i].s){
            b.push_front(v[i].s);
        }
        else{
            cout << 0 << endl;
            return 0;
        }
    }
    int cnt = 0;
    for(auto p: v){
        int l = p.f;
        int r = p.s;
        if(seg.query(l, r) == 0){
            cnt++;
        }
        seg.upd(r, 1);
    }
    ll ans = 1;
    f0r(i, cnt){
        ans *= 2;
        if(ans >= MOD) ans -= MOD;
    }
    cout << ans << endl;
    return 0;
}

Compilation message (stderr)

port_facility.cpp:1:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
 #pragma comment(linker, "/stack:200000000")
 
port_facility.cpp: In function 'void io(std::__cxx11::string)':
port_facility.cpp:52:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen(FIN, "r", stdin);
     ~~~~~~~^~~~~~~~~~~~~~~~~
port_facility.cpp:53:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen(FOUT, "w", stdout);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...