답안 #1097992

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1097992 2024-10-08T18:28:40 Z baodeptrai Examination (JOI19_examination) C++14
100 / 100
299 ms 21632 KB
#include <bits/stdc++.h>
// #ifndef ONLINE_JUDGE
// #include "/Users/quocbaonguyentran/Documents/VOI25/template/debug.cpp"
// #else
// #define debug(...) ;
// #endif
using namespace std;
#define endl "\n"
#define ll long long
struct Fenwick
{
    vector<int> bit;
    Fenwick() {};
    Fenwick(int n) : bit(n + 1, 0) {}

    void update(int id, int val)
    {
        for (; id < int(bit.size()); id += id & (-id))
        {
            bit[id] += val;
        }
    }
    int sum(int id)
    {
        int sum = 0;
        for (; id > 0; id -= id & (-id))
        {
            sum += bit[id];
        }
        return sum;
    }
    int query(int l, int r)
    {
        return sum(r) - sum(l - 1);
    }
} tree;
vector<int> d;
int res[200005];
int n, s[100005], t[100005], q;
int qe[200005];
int ans[200005];
vector<tuple<int, int, int, int, char>> p;
vector<tuple<int, int, char>> query;
bool cmp(tuple<int, int, int, char> &a, tuple<int, int, int, char> &b)
{
    int l1 = get<0>(a);
    int l2 = get<0>(b);
    char v1 = get<3>(a);
    char v2 = get<3>(b);
    return l1 > l2 || l1 == l2 && v1 < v2;
}
bool cmp2(tuple<int, int, int, int, char> &a, tuple<int, int, int, int, char> &b)
{
    int l1 = get<0>(a);
    int l2 = get<0>(b);
    char v1 = get<4>(a);
    char v2 = get<4>(b);
    return l1 > l2 || l1 == l2 && v1 < v2;
}
void Cal(int l, int r)
{
    if (l >= r)
        return;
    int mid = (l + r) / 2;
    vector<tuple<int, int, int, char>> c;
    for (int i = l; i <= mid; i++)
    {
        auto [l, r, w] = query[i];
        if (w == '+')
        {
            c.push_back(make_tuple(l, r, i, w));
        }
    }
    for (int i = mid + 1; i <= r; i++)
    {
        auto [l, r, w] = query[i];
        if (w == '?')
        {
            c.push_back(make_tuple(l, r, i, w));
        }
    }
    sort(c.begin(), c.end(), cmp);
    vector<int> t;
    for (auto [l, r, i, w] : c)
    {
        if (w == '+')
        {
            t.push_back(r);
            tree.update(r, 1);
        }
        else
        {
            int val = tree.query(r, int(d.size()));
            res[i] += val;
        }
    }
    for (int i : t)
    {
        tree.update(i, -1);
    }
    Cal(l, mid);
    Cal(mid + 1, r);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> q;
    for (int i = 1; i <= n; i++)
    {
        cin >> s[i] >> t[i];
        p.push_back({s[i] + t[i], s[i], t[i], i, '+'});
    }
    for (int i = 1; i <= q; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        p.push_back({c, a, b, i, '?'});
    }
    sort(p.begin(), p.end(), cmp2);
    query.push_back({0, 0, '0'});
    d.push_back(1);
    d.push_back(1e9);
    for (auto [w, l, r, id, type] : p)
    {
        query.push_back({l, r, type});
        if (type == '?')
            qe[query.size() - 1] = id;
        d.push_back(r);
    }
    sort(d.begin(), d.end());
    d.erase(unique(d.begin(), d.end()), d.end());
    for (auto &[l, r, w] : query)
    {
        r = lower_bound(d.begin(), d.end(), r) - d.begin() + 1;
    }
    tree = Fenwick(int(d.size()));
    Cal(1, n + q);
    for (int i = 1; i <= n + q; i++)
    {
        auto [l, r, w] = query[i];
        if (w == '?')
        {
            ans[qe[i]] = res[i];
        }
    }
    for (int i = 1; i <= q; i++)
    {
        cout << ans[i] << endl;
    }
}

Compilation message

examination.cpp: In function 'bool cmp(std::tuple<int, int, int, char>&, std::tuple<int, int, int, char>&)':
examination.cpp:50:32: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   50 |     return l1 > l2 || l1 == l2 && v1 < v2;
      |                       ~~~~~~~~~^~~~~~~~~~
examination.cpp: In function 'bool cmp2(std::tuple<int, int, int, int, char>&, std::tuple<int, int, int, int, char>&)':
examination.cpp:58:32: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   58 |     return l1 > l2 || l1 == l2 && v1 < v2;
      |                       ~~~~~~~~~^~~~~~~~~~
examination.cpp: In function 'void Cal(int, int)':
examination.cpp:68:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   68 |         auto [l, r, w] = query[i];
      |              ^
examination.cpp:76:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   76 |         auto [l, r, w] = query[i];
      |              ^
examination.cpp:84:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   84 |     for (auto [l, r, i, w] : c)
      |               ^
examination.cpp: In function 'int main()':
examination.cpp:124:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  124 |     for (auto [w, l, r, id, type] : p)
      |               ^
examination.cpp:133:16: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  133 |     for (auto &[l, r, w] : query)
      |                ^
examination.cpp:141:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  141 |         auto [l, r, w] = query[i];
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 472 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 6 ms 1068 KB Output is correct
8 Correct 6 ms 1084 KB Output is correct
9 Correct 6 ms 1092 KB Output is correct
10 Correct 5 ms 828 KB Output is correct
11 Correct 6 ms 1084 KB Output is correct
12 Correct 4 ms 976 KB Output is correct
13 Correct 7 ms 1084 KB Output is correct
14 Correct 6 ms 1084 KB Output is correct
15 Correct 7 ms 1160 KB Output is correct
16 Correct 5 ms 1084 KB Output is correct
17 Correct 5 ms 1044 KB Output is correct
18 Correct 3 ms 828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 263 ms 19408 KB Output is correct
2 Correct 267 ms 19632 KB Output is correct
3 Correct 262 ms 19376 KB Output is correct
4 Correct 210 ms 18096 KB Output is correct
5 Correct 221 ms 18596 KB Output is correct
6 Correct 154 ms 17336 KB Output is correct
7 Correct 257 ms 19120 KB Output is correct
8 Correct 260 ms 19384 KB Output is correct
9 Correct 250 ms 19188 KB Output is correct
10 Correct 182 ms 18616 KB Output is correct
11 Correct 169 ms 18096 KB Output is correct
12 Correct 128 ms 17332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 263 ms 19408 KB Output is correct
2 Correct 267 ms 19632 KB Output is correct
3 Correct 262 ms 19376 KB Output is correct
4 Correct 210 ms 18096 KB Output is correct
5 Correct 221 ms 18596 KB Output is correct
6 Correct 154 ms 17336 KB Output is correct
7 Correct 257 ms 19120 KB Output is correct
8 Correct 260 ms 19384 KB Output is correct
9 Correct 250 ms 19188 KB Output is correct
10 Correct 182 ms 18616 KB Output is correct
11 Correct 169 ms 18096 KB Output is correct
12 Correct 128 ms 17332 KB Output is correct
13 Correct 293 ms 18936 KB Output is correct
14 Correct 284 ms 19172 KB Output is correct
15 Correct 276 ms 19312 KB Output is correct
16 Correct 210 ms 17584 KB Output is correct
17 Correct 237 ms 17848 KB Output is correct
18 Correct 172 ms 16568 KB Output is correct
19 Correct 269 ms 18928 KB Output is correct
20 Correct 295 ms 19380 KB Output is correct
21 Correct 267 ms 18864 KB Output is correct
22 Correct 194 ms 18616 KB Output is correct
23 Correct 162 ms 18284 KB Output is correct
24 Correct 132 ms 17596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 472 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 6 ms 1068 KB Output is correct
8 Correct 6 ms 1084 KB Output is correct
9 Correct 6 ms 1092 KB Output is correct
10 Correct 5 ms 828 KB Output is correct
11 Correct 6 ms 1084 KB Output is correct
12 Correct 4 ms 976 KB Output is correct
13 Correct 7 ms 1084 KB Output is correct
14 Correct 6 ms 1084 KB Output is correct
15 Correct 7 ms 1160 KB Output is correct
16 Correct 5 ms 1084 KB Output is correct
17 Correct 5 ms 1044 KB Output is correct
18 Correct 3 ms 828 KB Output is correct
19 Correct 263 ms 19408 KB Output is correct
20 Correct 267 ms 19632 KB Output is correct
21 Correct 262 ms 19376 KB Output is correct
22 Correct 210 ms 18096 KB Output is correct
23 Correct 221 ms 18596 KB Output is correct
24 Correct 154 ms 17336 KB Output is correct
25 Correct 257 ms 19120 KB Output is correct
26 Correct 260 ms 19384 KB Output is correct
27 Correct 250 ms 19188 KB Output is correct
28 Correct 182 ms 18616 KB Output is correct
29 Correct 169 ms 18096 KB Output is correct
30 Correct 128 ms 17332 KB Output is correct
31 Correct 293 ms 18936 KB Output is correct
32 Correct 284 ms 19172 KB Output is correct
33 Correct 276 ms 19312 KB Output is correct
34 Correct 210 ms 17584 KB Output is correct
35 Correct 237 ms 17848 KB Output is correct
36 Correct 172 ms 16568 KB Output is correct
37 Correct 269 ms 18928 KB Output is correct
38 Correct 295 ms 19380 KB Output is correct
39 Correct 267 ms 18864 KB Output is correct
40 Correct 194 ms 18616 KB Output is correct
41 Correct 162 ms 18284 KB Output is correct
42 Correct 132 ms 17596 KB Output is correct
43 Correct 287 ms 21168 KB Output is correct
44 Correct 292 ms 21176 KB Output is correct
45 Correct 292 ms 21632 KB Output is correct
46 Correct 209 ms 18764 KB Output is correct
47 Correct 263 ms 19340 KB Output is correct
48 Correct 146 ms 15024 KB Output is correct
49 Correct 299 ms 21428 KB Output is correct
50 Correct 286 ms 21224 KB Output is correct
51 Correct 282 ms 21424 KB Output is correct
52 Correct 222 ms 19380 KB Output is correct
53 Correct 170 ms 18872 KB Output is correct