Submission #839420

# Submission time Handle Problem Language Result Execution time Memory
839420 2023-08-30T02:38:33 Z vjudge1 Examination (JOI19_examination) C++17
100 / 100
216 ms 13564 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

struct point{
    int x, y, z, idx;
};
namespace BIT{
    const int OFFSET = 10;
    int p = 0;
    vector<pair<int, int>> s;
    void init(int n){
        s.resize(n + OFFSET*2);
    }
    int query(int pos){
        int r = 0;
        for (pos=s.size()-pos-OFFSET; pos; pos -= pos & (-pos))
            r += (s[pos].second == p) * s[pos].first;
        return r;
    }
    void update(int pos, int v){
        for (pos=s.size()-pos-OFFSET; pos < s.size(); pos += pos & (-pos)){
            if (s[pos].second != p) s[pos] = {0, p};
            s[pos].first += v;
        }
    }
    void reset(){
        p++;
    }
}
vector<point> a;
vector<int> result;
void cdq(int start, int end){
    if (start == end) return;
    int mid = (start+end)>>1;
    cdq(start, mid); cdq(mid+1, end);
    vector<pair<point, bool>> s;
    int lptr = start;
    for (int rptr=mid+1; rptr<=end; rptr++){
        while (lptr <= mid && pair<int, int> (a[lptr].y, -a[lptr].idx) >= pair<int, int> (a[rptr].y, -a[rptr].idx))
            s.emplace_back(a[lptr++], 0);
        s.emplace_back(a[rptr], 1);
    }
    while (lptr <= mid) s.emplace_back(a[lptr++], 0);
    BIT::reset();
    for (const pair<point, bool> &c: s){
        if (c.second && c.first.idx != -1)
            result[c.first.idx] += BIT::query(c.first.x);
        if (!c.second && c.first.idx == -1)
            BIT::update(c.first.x, 1);
    }
    for (int i=0; i<s.size(); i++)
        a[start+i] = s[i].first;
}
signed main(){
    cin.tie(0)->sync_with_stdio(0);
    int n, q; cin >> n >> q;
    for (int i=0; i<n; i++){
        int s, t; cin >> s >> t;
        a.push_back({s, t, s+t, -1});
    }
    for (int i=0; i<q; i++){
        int x, y, z; cin >> x >> y >> z;
        a.push_back({x, y, z, i});
    }
    sort(a.begin(), a.end(), [](const point &a, const point &b){
        return a.x < b.x;
    });
    for (int lptr=0, rptr=0; lptr<a.size(); lptr=rptr){
        int value = a[lptr].x;
        while (rptr<a.size() && value == a[rptr].x)
            a[rptr++].x = lptr;
    }
    BIT::init(n+q);
    sort(a.begin(), a.end(), [](const point &a, const point &b){
        return pair<int, int> (a.z, -a.idx) > pair<int, int> (b.z, -b.idx);
    });
    result.resize(q);
    cdq(0, a.size()-1);
    for (int v: result) cout << v << "\n";
}

Compilation message

examination.cpp: In function 'void BIT::update(int, int)':
examination.cpp:22:43: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |         for (pos=s.size()-pos-OFFSET; pos < s.size(); pos += pos & (-pos)){
      |                                       ~~~~^~~~~~~~~~
examination.cpp: In function 'void cdq(int, int)':
examination.cpp:52:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<point, bool> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     for (int i=0; i<s.size(); i++)
      |                   ~^~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:69:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |     for (int lptr=0, rptr=0; lptr<a.size(); lptr=rptr){
      |                              ~~~~^~~~~~~~~
examination.cpp:71:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |         while (rptr<a.size() && value == a[rptr].x)
      |                ~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 5 ms 724 KB Output is correct
8 Correct 5 ms 704 KB Output is correct
9 Correct 5 ms 684 KB Output is correct
10 Correct 4 ms 724 KB Output is correct
11 Correct 4 ms 724 KB Output is correct
12 Correct 4 ms 772 KB Output is correct
13 Correct 5 ms 852 KB Output is correct
14 Correct 5 ms 808 KB Output is correct
15 Correct 5 ms 852 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 4 ms 876 KB Output is correct
18 Correct 3 ms 800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 182 ms 13108 KB Output is correct
2 Correct 178 ms 13100 KB Output is correct
3 Correct 172 ms 13004 KB Output is correct
4 Correct 148 ms 13100 KB Output is correct
5 Correct 136 ms 13004 KB Output is correct
6 Correct 120 ms 13104 KB Output is correct
7 Correct 173 ms 13456 KB Output is correct
8 Correct 182 ms 13564 KB Output is correct
9 Correct 170 ms 13500 KB Output is correct
10 Correct 119 ms 13428 KB Output is correct
11 Correct 134 ms 13500 KB Output is correct
12 Correct 94 ms 13528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 182 ms 13108 KB Output is correct
2 Correct 178 ms 13100 KB Output is correct
3 Correct 172 ms 13004 KB Output is correct
4 Correct 148 ms 13100 KB Output is correct
5 Correct 136 ms 13004 KB Output is correct
6 Correct 120 ms 13104 KB Output is correct
7 Correct 173 ms 13456 KB Output is correct
8 Correct 182 ms 13564 KB Output is correct
9 Correct 170 ms 13500 KB Output is correct
10 Correct 119 ms 13428 KB Output is correct
11 Correct 134 ms 13500 KB Output is correct
12 Correct 94 ms 13528 KB Output is correct
13 Correct 198 ms 13440 KB Output is correct
14 Correct 196 ms 13516 KB Output is correct
15 Correct 186 ms 13484 KB Output is correct
16 Correct 172 ms 13420 KB Output is correct
17 Correct 156 ms 13428 KB Output is correct
18 Correct 128 ms 13488 KB Output is correct
19 Correct 216 ms 13460 KB Output is correct
20 Correct 201 ms 13496 KB Output is correct
21 Correct 193 ms 13508 KB Output is correct
22 Correct 117 ms 13444 KB Output is correct
23 Correct 137 ms 13416 KB Output is correct
24 Correct 93 ms 13480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 5 ms 724 KB Output is correct
8 Correct 5 ms 704 KB Output is correct
9 Correct 5 ms 684 KB Output is correct
10 Correct 4 ms 724 KB Output is correct
11 Correct 4 ms 724 KB Output is correct
12 Correct 4 ms 772 KB Output is correct
13 Correct 5 ms 852 KB Output is correct
14 Correct 5 ms 808 KB Output is correct
15 Correct 5 ms 852 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 4 ms 876 KB Output is correct
18 Correct 3 ms 800 KB Output is correct
19 Correct 182 ms 13108 KB Output is correct
20 Correct 178 ms 13100 KB Output is correct
21 Correct 172 ms 13004 KB Output is correct
22 Correct 148 ms 13100 KB Output is correct
23 Correct 136 ms 13004 KB Output is correct
24 Correct 120 ms 13104 KB Output is correct
25 Correct 173 ms 13456 KB Output is correct
26 Correct 182 ms 13564 KB Output is correct
27 Correct 170 ms 13500 KB Output is correct
28 Correct 119 ms 13428 KB Output is correct
29 Correct 134 ms 13500 KB Output is correct
30 Correct 94 ms 13528 KB Output is correct
31 Correct 198 ms 13440 KB Output is correct
32 Correct 196 ms 13516 KB Output is correct
33 Correct 186 ms 13484 KB Output is correct
34 Correct 172 ms 13420 KB Output is correct
35 Correct 156 ms 13428 KB Output is correct
36 Correct 128 ms 13488 KB Output is correct
37 Correct 216 ms 13460 KB Output is correct
38 Correct 201 ms 13496 KB Output is correct
39 Correct 193 ms 13508 KB Output is correct
40 Correct 117 ms 13444 KB Output is correct
41 Correct 137 ms 13416 KB Output is correct
42 Correct 93 ms 13480 KB Output is correct
43 Correct 208 ms 13416 KB Output is correct
44 Correct 206 ms 13448 KB Output is correct
45 Correct 202 ms 13444 KB Output is correct
46 Correct 178 ms 13376 KB Output is correct
47 Correct 153 ms 13556 KB Output is correct
48 Correct 122 ms 13448 KB Output is correct
49 Correct 204 ms 13452 KB Output is correct
50 Correct 193 ms 13488 KB Output is correct
51 Correct 190 ms 13396 KB Output is correct
52 Correct 131 ms 13516 KB Output is correct
53 Correct 137 ms 13484 KB Output is correct