Submission #1108134

# Submission time Handle Problem Language Result Execution time Memory
1108134 2024-11-03T00:47:22 Z Zero_OP trapezoid (balkan11_trapezoid) C++14
0 / 100
70 ms 10216 KB
#include <bits/stdc++.h>

using namespace std;

const int mod = 30013;

void add(int& x, int y){
    x += y;
    if(x >= mod) x -= mod;
}

struct Node{
    int mx, ways;
    Node(int mx = 0, int ways = 0) : mx(mx), ways(ways) {}

    friend Node operator + (const Node& a, const Node& b){
        Node c(max(a.mx, b.mx), 0);
        if(a.mx == c.mx) add(c.ways, a.ways);
        if(b.mx == c.mx) add(c.ways, b.ways);
        return c;
    }

    Node& operator += (const Node& oth){
        if(mx == oth.mx) add(ways, oth.ways);
        else if(mx < oth.mx) mx = oth.mx, ways = oth.ways;
        return *this;
    }
};

struct Fenwick{
    vector<Node> bit;
    Fenwick(int n) : bit(n + 1, Node()) {}

    void update(int id, Node v){
        for(; id < (int)bit.size(); id += id & (-id)){
            bit[id] += v;
        }
    }

    Node query(int id){
        Node ret(0, 0);
        for(; id > 0; id -= id & (-id)){
            ret += bit[id];
        }
        return ret;
    }
};

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

#ifdef LOCAL
    freopen("task.inp", "r", stdin);
    freopen("task.out", "w", stdout);
#endif // LOCAL

    int N;
    cin >> N;

    vector<int> v;
    vector<tuple<int, int, int, int>> E;
    for(int i = 0; i < N; ++i){
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        v.emplace_back(c);
        v.emplace_back(d);
        E.emplace_back(a, 0, c, i);
        E.emplace_back(b, 1, d, i);
    }

    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    sort(E.begin(), E.end());

    auto findPos = [&](int i){
        return lower_bound(v.begin(), v.end(), i) - v.begin() + 1;
    };

    for(auto& [x, type, pos, id] : E){
        pos = findPos(pos);
    }

    Fenwick ft(N);
    Node res(0, 0);
    vector<Node> f(N, Node(0, 0));
    for(auto [x, type, pos, id] : E){
        if(type == 0){
            Node cur = ft.query(pos - 1);
            ++cur.mx;
            cur += Node(1, 1);

            f[id] = cur;
        } else{
            ft.update(pos, f[id]);
        }
    }

    for(int i = 0; i < N; ++i){
        res += f[i];
    }

    cout << res.mx << ' ' << res.ways << '\n';

    return 0;
}

Compilation message

trapezoid.cpp: In function 'int main()':
trapezoid.cpp:79:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   79 |     for(auto& [x, type, pos, id] : E){
      |               ^
trapezoid.cpp:86:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   86 |     for(auto [x, type, pos, id] : E){
      |              ^
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Incorrect 1 ms 336 KB Output isn't correct
4 Incorrect 1 ms 336 KB Output isn't correct
5 Incorrect 2 ms 592 KB Output isn't correct
6 Incorrect 3 ms 592 KB Output isn't correct
7 Incorrect 3 ms 592 KB Output isn't correct
8 Incorrect 5 ms 848 KB Output isn't correct
9 Incorrect 8 ms 1460 KB Output isn't correct
10 Incorrect 14 ms 2332 KB Output isn't correct
11 Incorrect 18 ms 2448 KB Output isn't correct
12 Incorrect 37 ms 5192 KB Output isn't correct
13 Incorrect 43 ms 5340 KB Output isn't correct
14 Incorrect 60 ms 10052 KB Output isn't correct
15 Incorrect 54 ms 10044 KB Output isn't correct
16 Incorrect 57 ms 10216 KB Output isn't correct
17 Incorrect 62 ms 10160 KB Output isn't correct
18 Incorrect 68 ms 9888 KB Output isn't correct
19 Incorrect 64 ms 10044 KB Output isn't correct
20 Incorrect 70 ms 10052 KB Output isn't correct