Submission #594871

# Submission time Handle Problem Language Result Execution time Memory
594871 2022-07-13T05:45:08 Z Do_you_copy Examination (JOI19_examination) C++17
100 / 100
456 ms 25776 KB
#include <bits/stdc++.h>
#define taskname "test"
#define fi first
#define se second
#define pb push_back
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
using ll = long long;
using pii = pair <int, int>;
using pil = pair <int, ll>;
using pli = pair <ll, int>;
using pll = pair <ll, ll>;
using ull = unsigned ll;
mt19937 Rand(chrono::steady_clock::now().time_since_epoch().count());

ll min(const ll &a, const ll &b){
    return (a < b) ? a : b;
}

ll max(const ll &a, const ll &b){
    return (a > b) ? a : b;
}

//const ll Mod = 1000000009;
//const ll Mod2 = 999999999989;
//only use when required
const int maxN = 1e5 + 1;

int n, qq;

struct bit2d{
    vector <int> nodex;
    vector <vector <int>> node, val;
    void pre_build(){
        sort(nodex.begin(), nodex.end());
        nodex.resize(unique(nodex.begin(), nodex.end()) - nodex.begin());
        node.resize(nodex.size() + 1);
        val.resize(nodex.size() + 1);
    }
    void fake_update(int xx, int yy){
        int x = upper_bound(nodex.begin(), nodex.end(), xx) - nodex.begin();
        for (; x < node.size(); x += x & -x){
            node[x].pb(yy);
        }
    }
    void build(){
        for (int i = 1; i < node.size(); ++i){
            sort(node[i].begin(), node[i].end());
            node[i].resize(unique(node[i].begin(), node[i].end()) - node[i].begin());
            val[i].resize(node[i].size() + 1);
        }
    }
    void update(int xx, int yy){
        int x = upper_bound(nodex.begin(), nodex.end(), xx) - nodex.begin();
        for (; x < node.size(); x += x & -x){
            int y = upper_bound(node[x].begin(), node[x].end(), yy) - node[x].begin();
            for (int j = y; j < val[x].size(); j += j & -j){
                ++val[x][j];
            }
        }
    }
    int get(int xx, int yy){
        int sum = 0;
        int x = upper_bound(nodex.begin(), nodex.end(), xx) - nodex.begin();
        for (; x; x -= x & -x){
            int y = upper_bound(node[x].begin(), node[x].end(), yy) - node[x].begin();
            for (int j = y; j; j -= j & -j){
                sum += val[x][j];
            }
        }
        return sum;
    }
}bit;

struct TPoint{
    int x, y, z;
};
TPoint a[maxN];

struct TQuery{
    int A, B, C, idx;
};
TQuery q[maxN];

int ans[maxN];

void Init(){
    cin >> n >> qq;
    for (int i = 1; i <= n; ++i){
        cin >> a[i].x >> a[i].y;
        a[i].z = a[i].x + a[i].y;
        bit.nodex.pb(-a[i].x);
    }
    bit.pre_build();
    sort(a + 1, a + n + 1,[](const auto &i, const auto &j){
        return i.z > j.z;
    });
    for (int i = 1; i <= n; ++i){
        bit.fake_update(-a[i].x, -a[i].y);
    }
    bit.build();
    for (int i = 1; i <= qq; ++i){
        cin >> q[i].A >> q[i].B >> q[i].C;
        q[i].idx = i;
    }
    sort(q + 1, q + qq + 1,[](const auto &i, const auto &j){
        return i.C > j.C;
    });
    int j = 1;
    for (int i = 1; i <= qq; ++i){
        while (j <= n && a[j].z >= q[i].C){
            //cerr << a[j].x << " " << a[j].y << "?\n";
            bit.update(-a[j].x, -a[j].y);
            ++j;
        }
        //cerr << q[i].A << " " << q[i].B << "\n";
        ans[q[i].idx] = bit.get(-q[i].A, -q[i].B);
    }
    for (int i = 1; i <= qq; ++i) cout << ans[i] << "\n";
}


int main(){
    if (fopen(taskname".inp", "r")){
        freopen(taskname".inp", "r", stdin);
        //freopen(taskname".out", "w", stdout);
    }
    faster;
    ll tt = 1;
    //cin >> tt;
    while (tt--){
        Init();
    }
}

Compilation message

examination.cpp: In member function 'void bit2d::fake_update(int, int)':
examination.cpp:42:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         for (; x < node.size(); x += x & -x){
      |                ~~^~~~~~~~~~~~~
examination.cpp: In member function 'void bit2d::build()':
examination.cpp:47:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         for (int i = 1; i < node.size(); ++i){
      |                         ~~^~~~~~~~~~~~~
examination.cpp: In member function 'void bit2d::update(int, int)':
examination.cpp:55:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         for (; x < node.size(); x += x & -x){
      |                ~~^~~~~~~~~~~~~
examination.cpp:57:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |             for (int j = y; j < val[x].size(); j += j & -j){
      |                             ~~^~~~~~~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:125:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  125 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 7 ms 1108 KB Output is correct
8 Correct 6 ms 980 KB Output is correct
9 Correct 6 ms 980 KB Output is correct
10 Correct 5 ms 856 KB Output is correct
11 Correct 4 ms 596 KB Output is correct
12 Correct 2 ms 480 KB Output is correct
13 Correct 6 ms 980 KB Output is correct
14 Correct 6 ms 1004 KB Output is correct
15 Correct 6 ms 984 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 4 ms 852 KB Output is correct
18 Correct 2 ms 472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 327 ms 19456 KB Output is correct
2 Correct 323 ms 19340 KB Output is correct
3 Correct 363 ms 19424 KB Output is correct
4 Correct 162 ms 16528 KB Output is correct
5 Correct 101 ms 8144 KB Output is correct
6 Correct 56 ms 6780 KB Output is correct
7 Correct 326 ms 19308 KB Output is correct
8 Correct 289 ms 19376 KB Output is correct
9 Correct 283 ms 19308 KB Output is correct
10 Correct 67 ms 6548 KB Output is correct
11 Correct 122 ms 16012 KB Output is correct
12 Correct 48 ms 5500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 327 ms 19456 KB Output is correct
2 Correct 323 ms 19340 KB Output is correct
3 Correct 363 ms 19424 KB Output is correct
4 Correct 162 ms 16528 KB Output is correct
5 Correct 101 ms 8144 KB Output is correct
6 Correct 56 ms 6780 KB Output is correct
7 Correct 326 ms 19308 KB Output is correct
8 Correct 289 ms 19376 KB Output is correct
9 Correct 283 ms 19308 KB Output is correct
10 Correct 67 ms 6548 KB Output is correct
11 Correct 122 ms 16012 KB Output is correct
12 Correct 48 ms 5500 KB Output is correct
13 Correct 366 ms 19856 KB Output is correct
14 Correct 357 ms 19792 KB Output is correct
15 Correct 347 ms 19388 KB Output is correct
16 Correct 165 ms 16860 KB Output is correct
17 Correct 121 ms 8596 KB Output is correct
18 Correct 59 ms 6760 KB Output is correct
19 Correct 419 ms 19848 KB Output is correct
20 Correct 346 ms 19848 KB Output is correct
21 Correct 344 ms 19860 KB Output is correct
22 Correct 64 ms 6608 KB Output is correct
23 Correct 110 ms 15964 KB Output is correct
24 Correct 40 ms 5540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 7 ms 1108 KB Output is correct
8 Correct 6 ms 980 KB Output is correct
9 Correct 6 ms 980 KB Output is correct
10 Correct 5 ms 856 KB Output is correct
11 Correct 4 ms 596 KB Output is correct
12 Correct 2 ms 480 KB Output is correct
13 Correct 6 ms 980 KB Output is correct
14 Correct 6 ms 1004 KB Output is correct
15 Correct 6 ms 984 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 4 ms 852 KB Output is correct
18 Correct 2 ms 472 KB Output is correct
19 Correct 327 ms 19456 KB Output is correct
20 Correct 323 ms 19340 KB Output is correct
21 Correct 363 ms 19424 KB Output is correct
22 Correct 162 ms 16528 KB Output is correct
23 Correct 101 ms 8144 KB Output is correct
24 Correct 56 ms 6780 KB Output is correct
25 Correct 326 ms 19308 KB Output is correct
26 Correct 289 ms 19376 KB Output is correct
27 Correct 283 ms 19308 KB Output is correct
28 Correct 67 ms 6548 KB Output is correct
29 Correct 122 ms 16012 KB Output is correct
30 Correct 48 ms 5500 KB Output is correct
31 Correct 366 ms 19856 KB Output is correct
32 Correct 357 ms 19792 KB Output is correct
33 Correct 347 ms 19388 KB Output is correct
34 Correct 165 ms 16860 KB Output is correct
35 Correct 121 ms 8596 KB Output is correct
36 Correct 59 ms 6760 KB Output is correct
37 Correct 419 ms 19848 KB Output is correct
38 Correct 346 ms 19848 KB Output is correct
39 Correct 344 ms 19860 KB Output is correct
40 Correct 64 ms 6608 KB Output is correct
41 Correct 110 ms 15964 KB Output is correct
42 Correct 40 ms 5540 KB Output is correct
43 Correct 456 ms 25776 KB Output is correct
44 Correct 410 ms 25604 KB Output is correct
45 Correct 388 ms 25664 KB Output is correct
46 Correct 186 ms 21632 KB Output is correct
47 Correct 114 ms 9812 KB Output is correct
48 Correct 58 ms 6612 KB Output is correct
49 Correct 345 ms 25532 KB Output is correct
50 Correct 378 ms 25576 KB Output is correct
51 Correct 345 ms 25368 KB Output is correct
52 Correct 81 ms 8460 KB Output is correct
53 Correct 142 ms 20348 KB Output is correct