Submission #874337

# Submission time Handle Problem Language Result Execution time Memory
874337 2023-11-16T17:08:42 Z Macker trapezoid (balkan11_trapezoid) C++17
100 / 100
192 ms 11516 KB
#include <iostream> // #include <fstream>
#include <vector>
#include <list>
#include <algorithm>
#include <math.h>
#include <tuple>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <map>
#include <array>
#include <climits>
#include <cassert>

using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()

//ifstream cin("optmilk.in");
//ofstream cout("optmilk.out");

vector<pair<int, int>> st;
int len = 1;
int mod = 30013;

vector<int> xs;
int cx(int x) {
    return lower_bound(all(xs), x) - xs.begin();
}

pair<int, int> query(int f, int t, int i = 1, int s = 0, int e = len) {
    if (f >= e || t <= s) return { -1, -1 };
    if (f <= s && e <= t) return st[i];

    pair<int, int> a = query(f, t, i * 2, s, (s + e) / 2);
    pair<int, int> b = query(f, t, i * 2 + 1, (s + e) / 2, e);
    if (a.first > b.first) return a;
    if (a.first < b.first) return b;
    if (a.first == b.first) return { a.first, (a.second + b.second) % mod };
}

void add(int idx, int val, int cnt, int i = 1, int s = 0, int e = len) {
    if (s > idx || e <= idx) return;
    if (s == idx && s == e - 1) {
        if (st[i].first == val) st[i].second = (st[i].second + cnt) % mod;
        if (st[i].first < val) st[i] = { val, cnt % mod };
        return;
    }
    add(idx, val, cnt, i * 2, s, (s + e) / 2);
    add(idx, val, cnt, i * 2 + 1, (s + e) / 2, e);
    if (st[i * 2].first == st[i * 2 + 1].first) st[i] = { st[i * 2].first, st[i * 2].second + st[i * 2 + 1].second };
    if (st[i * 2].first > st[i * 2 + 1].first) st[i] = st[i * 2];
    if (st[i * 2].first < st[i * 2 + 1].first) st[i] = st[i * 2 + 1];
    st[i].second %= mod;
}

int main()
{
    int n; cin >> n;
    vector<array<int, 5>> ev; // y, t - 0add/1query, x1, -1/(val, val)
    for (int i = 0; i < n; i++) {
        int y, yy, x, xx; cin >> x >> xx >> y >> yy;
        ev.push_back({ y, 1, x, yy, -1 });
        ev.push_back({ yy, 0, xx, -1, -1 });
        xs.push_back(x);
        xs.push_back(xx);
    }
    sort(all(ev));
    sort(all(xs));
    while (len < xs.size()) len *= 2;
    st.resize(len * 2, { 0, 0 });
    
    for (int i = 0; i < ev.size(); i++) {
        int y = ev[i][0], t = ev[i][1], x = ev[i][2];
        if (t == 1) {
            pair<int, int> val = query(0, cx(x) + 1);
            if (val.first == 0) val.second = 1;
            array<int, 5>& tmp = *lower_bound(all(ev), array<int, 5>({ev[i][3], -1, -1, -1, -1 }));
            tmp[3] = val.first + 1; tmp[4] = val.second % mod;
        }
        else {
            int ans = ev[i][3], cnt = ev[i][4];
            add(cx(x), ans, cnt);
        }
    }

    cout << st[1].first << " " << st[1].second % mod << endl;
}

Compilation message

trapezoid.cpp: In function 'int main()':
trapezoid.cpp:71:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |     while (len < xs.size()) len *= 2;
      |            ~~~~^~~~~~~~~~~
trapezoid.cpp:74:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 5> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |     for (int i = 0; i < ev.size(); i++) {
      |                     ~~^~~~~~~~~~~
trapezoid.cpp:75:13: warning: unused variable 'y' [-Wunused-variable]
   75 |         int y = ev[i][0], t = ev[i][1], x = ev[i][2];
      |             ^
trapezoid.cpp: In function 'std::pair<int, int> query(int, int, int, int, int)':
trapezoid.cpp:41:1: warning: control reaches end of non-void function [-Wreturn-type]
   41 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 3 ms 604 KB Output is correct
6 Correct 5 ms 844 KB Output is correct
7 Correct 6 ms 860 KB Output is correct
8 Correct 8 ms 948 KB Output is correct
9 Correct 16 ms 1476 KB Output is correct
10 Correct 31 ms 2544 KB Output is correct
11 Correct 43 ms 2788 KB Output is correct
12 Correct 99 ms 5268 KB Output is correct
13 Correct 108 ms 5592 KB Output is correct
14 Correct 126 ms 9488 KB Output is correct
15 Correct 136 ms 9432 KB Output is correct
16 Correct 153 ms 9644 KB Output is correct
17 Correct 158 ms 10976 KB Output is correct
18 Correct 149 ms 11516 KB Output is correct
19 Correct 173 ms 10024 KB Output is correct
20 Correct 192 ms 11224 KB Output is correct