Submission #535277

# Submission time Handle Problem Language Result Execution time Memory
535277 2022-03-09T21:38:06 Z Evang trapezoid (balkan11_trapezoid) C++17
4 / 100
146 ms 18372 KB
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;

#ifdef _DEBUG
#define dout(x) clog << "Line " << __LINE__ << ": " << #x << "=" << (x) << el
#else
#define dout(x)
#endif

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define uid(a,b) uniform_int_distribution<int>(a,b)(rng)

#define ins insert
#define ssize(x) (int((x).size()))
#define bs(args...) binary_search(args)
#define lb(args...) lower_bound(args)
#define ub(args...) upper_bound(args)
#define all(x) (x).begin(),(x).end()
#define mp(a, b) make_pair(a, b)
#define mt(args...) make_tuple(args)
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define die exit(0)

template<typename T>
using vc = vector<T>;
template<typename T>
using uset = unordered_set<T>;
template<typename A, typename B>
using umap = unordered_map<A, B>;
template<typename T, typename Comp>
using pq = std::priority_queue<T, vc<T>, Comp>;
template<typename T>
using maxpq = pq<T, less<T>>;
template<typename T>
using minpq = pq<T, greater<T>>;
template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

using db = double;
using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vc<int>;
using vll = vc<ll>;
using vpi = vc<pi>;
using vpll = vc<pll>;
using str = string;

constexpr char el = '\n';
constexpr char sp = ' ';
constexpr int inf = 0x3f3f3f3f;
constexpr ll llinf = 0x3f3f3f3f3f3f3f3fLL;
// ---------------------------------------------------------------------


const int N = 1e5+5;
const int MM = 4e5+5;
const int mod = 30013;
int n, dp[N], dp2[N];
struct evan {
    int a, b, c, d;
} a[N];
struct node {
    int max = 0, cnt = 0;
} seg[MM];
vi qs[N];
map<pi, pi> mp;

void pull(int i){
    if(seg[2*i].max==seg[2*i+1].max){
        seg[i].max = seg[2*i].max;
        seg[i].cnt = (seg[2*i].cnt + seg[2*i+1].cnt)%mod;
    }else if(seg[2*i].max<seg[2*i+1].max) {
        seg[i].max = seg[2*i+1].max;
        seg[i].cnt = seg[2*i+1].cnt;
    }else {
        seg[i].max = seg[2*i].max;
        seg[i].cnt = seg[2*i].cnt;
//        seg[i] = seg[2 * i];
    }
}

void upd(int i, int x, int y){
    // i is 0-indexed
    assert(0 <= i && i < 2*n);
    i += 2*n;
    if(x==seg[i].max)
        seg[i].cnt += y;
    else if(x>seg[i].max){
        seg[i].max = x;
        seg[i].cnt = y;
    }

    for(i /= 2; i > 0; i /= 2)
        pull(i);
}

pi qry(int r){
    // r is 0-indexed
    assert(r < 2*n);
    r += 2*n;
    int l = 2*n;
    int car = 0, cnt = 0;
    while(l<=r){
        if(l&1){
            if(seg[l].max>car){
                car = seg[l].max;
                cnt = seg[l].cnt;
            }else if(seg[l].max==car)
                cnt = (cnt+seg[l].cnt)%mod;
            ++l;
        }
        if(r&1^1){
            if(seg[r].max>car){
                car = seg[r].max;
                cnt = seg[r].cnt;
            }else if(seg[r].max==car)
                cnt = (cnt+seg[r].cnt)%mod;
            --r;
        }
        l /= 2; r /= 2;
    }
    return mp(car, cnt);
}

void unik(vi &v){
    sort(all(v));
    vi u{v[0]};
    for(int i = 1; i < ssize(v); ++i)
        if(v[i]^v[i-1])
            u.pb(v[i]);
    swap(u, v);
}

signed main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cout << fixed; clog << fixed; clog << unitbuf;
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#else
    //freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);
#endif

    cin >> n;
    vi cct, ccb;
    for(int i = 1; i <= n; ++i){
        cin >> a[i].a >> a[i].b >> a[i].c >> a[i].d;
        cct.pb(a[i].a);
        cct.pb(a[i].b);
        ccb.pb(a[i].c);
        ccb.pb(a[i].d);
    }

    unik(cct);
    unik(ccb);
    assert(ssize(cct)==2*n);
    assert(ssize(ccb)==2*n);
    for(int i = 1; i <= n; ++i){
        a[i].a = lb(all(cct), a[i].a)-cct.begin();
        a[i].b = lb(all(cct), a[i].b)-cct.begin();
        a[i].c = lb(all(ccb), a[i].c)-ccb.begin();
        a[i].d = lb(all(ccb), a[i].d)-ccb.begin();
    }
    sort(a+1, a+1+n, [](evan x, evan y){
        return x.b < y.b;
    });

#ifdef _DEBUG
    clog << "Line " << __LINE__ << ":\n";
    for(int i = 1; i <= n; ++i)
        clog << a[i].a << sp << a[i].b << sp << a[i].c << sp << a[i].d << el;
    clog << el;
#endif

    int p = 0;
    for(int i = 1; i <= n; ++i){
        while(a[p+1].b<a[i].a)
            ++p;

        qs[p].pb(a[i].c-1);
    }

    p = 0;
    for(int i = 1; i <= n; ++i){
        while(a[p+1].b<a[i].a)
            ++p;

        if(p==0)
            dp[i] = dp2[i] = 1;
        else {
            auto [car, cnt] = mp[mp(p, a[i].c - 1)];
            if (dp[i - 1] > car + 1) {
                dp[i] = dp[i - 1];
                dp2[i] = dp2[i - 1];
            } else {
                dp[i] = car + 1;
                dp2[i] = max(1, cnt);
                upd(a[i].d, dp[i], dp2[i]);
                if (dp[i - 1] == dp[i]) {
                    dp2[i] += dp2[i - 1];
                    dp2[i] %= mod;
                }
            }
        }

        for(int j: qs[i])
            mp[mp(i, j)] = qry(j);
    }

    cout << dp[n] << sp << dp2[n] << el;

//    auto[car, cnt] = qry(2*n-1);
//    cout << car << sp << cnt%mod << el;

#ifdef _DEBUG
    clog << "Line " << __LINE__ << ":\n";
    for(int i = 0; i <= n; ++i)
        clog << dp[i] << sp << dp2[i] << el;
    clog << el;
#endif
}

Compilation message

trapezoid.cpp: In function 'pi qry(int)':
trapezoid.cpp:119:13: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
  119 |         if(r&1^1){
      |            ~^~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2772 KB Output isn't correct
2 Incorrect 1 ms 2644 KB Output isn't correct
3 Partially correct 2 ms 2700 KB Partially correct
4 Incorrect 3 ms 2772 KB Output isn't correct
5 Incorrect 4 ms 3028 KB Output isn't correct
6 Incorrect 5 ms 3156 KB Output isn't correct
7 Incorrect 6 ms 3340 KB Output isn't correct
8 Partially correct 8 ms 3412 KB Partially correct
9 Incorrect 14 ms 4212 KB Output isn't correct
10 Incorrect 27 ms 5892 KB Output isn't correct
11 Incorrect 36 ms 6600 KB Output isn't correct
12 Incorrect 69 ms 10824 KB Output isn't correct
13 Incorrect 85 ms 12308 KB Output isn't correct
14 Incorrect 101 ms 14028 KB Output isn't correct
15 Incorrect 111 ms 14660 KB Output isn't correct
16 Incorrect 118 ms 15320 KB Output isn't correct
17 Incorrect 124 ms 16380 KB Output isn't correct
18 Incorrect 125 ms 17464 KB Output isn't correct
19 Incorrect 139 ms 17332 KB Output isn't correct
20 Incorrect 146 ms 18372 KB Output isn't correct