Submission #958355

# Submission time Handle Problem Language Result Execution time Memory
958355 2024-04-05T14:00:34 Z hariaakas646 trapezoid (balkan11_trapezoid) C++17
100 / 100
204 ms 35920 KB
#include <bits/stdc++.h>

using namespace std;

#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define forr(i, j, k) for (int i = j; i < k; i++)
#define frange(i, j) forr(i, 0, j)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<lli> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long double ld;

void usaco()
{
    freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
//    freopen("problem.out", "w", stdout);
}

const lli mod = 30013;

struct Data {
    int v = 0;
    lli cnt = 0;
};

template <class T>
struct SegTree
{
    int size = 1, n;
    vector<T> segtree;
    vector<T> vec;

    T def; // Assign a value

    void init(int l, T defv)
    {
        n = l;
        def = defv;

        while (size < n)
            size *= 2;

        segtree.assign(2 * size, def);
        vec.assign(size, def);
    }

    T operation(T x, T y)
    {   T out;
        if(x.v > y.v) {
            out = x;
        }
        else if(y.v > x.v) {
            out = y;
        }
        else {
            out = x;
            out.cnt += y.cnt;
            out.cnt %= mod;
        }
        return out;
    }

    void recalculate(int x)
    {
        segtree[x] = operation(segtree[2 * x + 1], segtree[2 * x + 2]);
    }

    void build(int x, int l, int r)
    {
        if (l == r)
        {
            segtree[x] = vec[l];
            return;
        }
        int mid = (l + r) / 2;
        build(2 * x + 1, l, mid);
        build(2 * x + 2, mid + 1, r);
        recalculate(x);
    }

    void build()
    {
        build(0, 0, size - 1);
    }

    void set(int id, T val)
    {
        vec[id] = val;
    }

    void update(int x, int l, int r, int id, T val)
    {
        if (l == r)
        {
            segtree[x] = val;
            return;
        }
        int mid = (l + r) / 2;
        if (id <= mid)
        {
            update(2 * x + 1, l, mid, id, val);
        }
        else
        {
            update(2 * x + 2, mid + 1, r, id, val);
        }
        recalculate(x);
    }

    void update(int id, T val)
    {
        update(0, 0, size - 1, id, val);
    }

    T query(int x, int l, int r, int lx, int rx)
    {
        if (lx > r || rx < l)
        {
            return def;
        }
        if (lx <= l && r <= rx)
        {
            return segtree[x];
        }
        int mid = (l + r) / 2;
        T v1 = query(2 * x + 1, l, mid, lx, rx);
        T v2 = query(2 * x + 2, mid + 1, r, lx, rx);
        return operation(v1, v2);
    }

    T query(int lx, int rx)
    {
        return query(0, 0, size - 1, lx, rx);
    }
};


int main() {
    // usaco();
    int n;
    scd(n);

    vector<pair<pii, pii>> vec(n);
    seti st;
    frange(i, n) {
        scd(vec[i].f.f);
        scd(vec[i].f.s);
        scd(vec[i].s.f);
        scd(vec[i].s.s);
        st.insert(vec[i].s.f);
        st.insert(vec[i].s.s);
    }   

    mpii mv;
    int id = 1;

    for(auto e : st) mv[e] = id++;

    sort(all(vec));
    priority_queue<pair<pii, pair<int, lli>>> pq;
    SegTree<Data> segtree;
    Data tmp;
    segtree.init(id, tmp);
    segtree.build();
    tmp.cnt = 1;
    segtree.update(0, tmp);

    for(auto p : vec) {
        while(pq.size() && -pq.top().f.f < p.f.f) {
            auto p1 = pq.top();
            pq.pop();
            tmp.v = p1.s.f;
            tmp.cnt = p1.s.s;
            segtree.update(p1.f.s, tmp);
        }
        Data out = segtree.query(0, mv[p.s.f]);
        out.v++;
        pq.push(mp(mp(-p.f.s, mv[p.s.s]), mp(out.v, out.cnt)));
    }

    while(pq.size()) {
        auto p1 = pq.top();
        pq.pop();
        tmp.v = p1.s.f;
        tmp.cnt = p1.s.s;
        segtree.update(p1.f.s, tmp);
    }

    Data out = segtree.query(0, id-1);

    printf("%d %lld\n", out.v, out.cnt % mod);



}

Compilation message

trapezoid.cpp: In function 'void usaco()':
trapezoid.cpp:29:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
trapezoid.cpp: In function 'int main()':
trapezoid.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
trapezoid.cpp:155:5: note: in expansion of macro 'scd'
  155 |     scd(n);
      |     ^~~
trapezoid.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
trapezoid.cpp:160:9: note: in expansion of macro 'scd'
  160 |         scd(vec[i].f.f);
      |         ^~~
trapezoid.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
trapezoid.cpp:161:9: note: in expansion of macro 'scd'
  161 |         scd(vec[i].f.s);
      |         ^~~
trapezoid.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
trapezoid.cpp:162:9: note: in expansion of macro 'scd'
  162 |         scd(vec[i].s.f);
      |         ^~~
trapezoid.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
trapezoid.cpp:163:9: note: in expansion of macro 'scd'
  163 |         scd(vec[i].s.s);
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 3 ms 860 KB Output is correct
6 Correct 4 ms 1368 KB Output is correct
7 Correct 5 ms 1628 KB Output is correct
8 Correct 8 ms 2648 KB Output is correct
9 Correct 16 ms 4188 KB Output is correct
10 Correct 31 ms 8028 KB Output is correct
11 Correct 44 ms 9260 KB Output is correct
12 Correct 92 ms 18248 KB Output is correct
13 Correct 109 ms 20544 KB Output is correct
14 Correct 130 ms 28952 KB Output is correct
15 Correct 158 ms 30744 KB Output is correct
16 Correct 169 ms 31504 KB Output is correct
17 Correct 167 ms 32868 KB Output is correct
18 Correct 151 ms 33616 KB Output is correct
19 Correct 170 ms 34900 KB Output is correct
20 Correct 204 ms 35920 KB Output is correct