Submission #997844

# Submission time Handle Problem Language Result Execution time Memory
997844 2024-06-13T02:52:50 Z khanhphucscratch Examination (JOI19_examination) C++14
100 / 100
2530 ms 77516 KB
#include<bits/stdc++.h>
using namespace std;
struct Point
{
    vector<int> coordinate;
    int idx; //idx = 0: no query
};
int m = 2e5, bit[200005], ans[100005];
void update(int p, int v)
{
    for(int i = p; i <= m; i += i & (-i)) bit[i] += v;
}
int query(int p)
{
    if(p <= 0) return 0;
    return bit[p] + query(p - (p & (-p)));
}
bool cmp(Point x, Point y)
{
    for(int i = x.coordinate.size()-1; i >= 0; i--) if(x.coordinate[i] != y.coordinate[i]) return x.coordinate[i] < y.coordinate[i];
    return x.idx < y.idx;
}
void solve(vector<Point> p, int k)
{
    if(p.size() == 1) return;
    sort(p.begin(), p.end(), cmp);
    while(k > 2 && p[0].coordinate[k-1] == p[p.size()-1].coordinate[k-1]){
        for(int i = 0; i < p.size(); i++) p[i].coordinate.pop_back();
        k--;
    }
    /*cout<<"A"<<k<<endl;
    for(Point i : p){
        cout<<i.idx<<" ";
        for(int j = 0; j < k; j++) cout<<i.coordinate[j]<<" ";
        cout<<endl;
    }*/
    if(k == 2){ //Solve in O(n log n)
        for(Point i : p){
            if(i.idx == 0) update(i.coordinate[0], 1);
            else{
                ans[i.idx] += query(i.coordinate[0]);
                //cout<<"+"<<i.idx<<" "<<query(i.coordinate[0])<<endl;
            }
        }
        for(Point i : p) if(i.idx == 0) update(i.coordinate[0], -1);
        return;
    }
    int mid = ((int)p.size()+1)/2 - 1;
    vector<Point> le, ri;
    for(int i = 0; i <= mid; i++) le.push_back(p[i]);
    for(int i = mid+1; i < p.size(); i++) ri.push_back(p[i]);
    solve(le, k); solve(ri, k);
    vector<Point> newp;
    for(int i = 0; i <= mid; i++) if(p[i].idx == 0){
        p[i].coordinate.pop_back();
        newp.push_back(p[i]);
    }
    for(int i = mid+1; i < p.size(); i++) if(p[i].idx > 0){
        p[i].coordinate.pop_back();
        newp.push_back(p[i]);
    }
    solve(newp, k-1);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, q;
    cin>>n>>q;
    vector<Point> p(n+q);
    for(int i = 0; i < n; i++){
        int x, y;
        cin>>x>>y;
        x = 1000000000-x; y = 1000000000-y;
        p[i].coordinate = {x, y, x+y};
        p[i].idx = 0;
    }
    for(int i = 0; i < q; i++){
        int x, y, z;
        cin>>x>>y>>z;
        x = 1000000000-x; y = 1000000000-y; z = 2000000000 - z;
        p[n+i].coordinate = {x, y, z};
        p[n+i].idx = i+1;
    }
    for(int j = 0; j < 3; j++){
        set<int> wtf; int sz = 0;
        unordered_map<int, int> f;
        for(int i = 0; i < p.size(); i++) wtf.insert(p[i].coordinate[j]);
        for(int i : wtf) f[i] = ++sz;
        for(int i = 0; i < p.size(); i++) p[i].coordinate[j] = f[p[i].coordinate[j]];
    }
    solve(p, 3);
    for(int i = 1; i <= q; i++) cout<<ans[i]<<'\n';
}

Compilation message

examination.cpp: In function 'void solve(std::vector<Point>, int)':
examination.cpp:28:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |         for(int i = 0; i < p.size(); i++) p[i].coordinate.pop_back();
      |                        ~~^~~~~~~~~~
examination.cpp:51:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     for(int i = mid+1; i < p.size(); i++) ri.push_back(p[i]);
      |                        ~~^~~~~~~~~~
examination.cpp:58:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |     for(int i = mid+1; i < p.size(); i++) if(p[i].idx > 0){
      |                        ~~^~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:88:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |         for(int i = 0; i < p.size(); i++) wtf.insert(p[i].coordinate[j]);
      |                        ~~^~~~~~~~~~
examination.cpp:90:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |         for(int i = 0; i < p.size(); i++) p[i].coordinate[j] = f[p[i].coordinate[j]];
      |                        ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 40 ms 2552 KB Output is correct
8 Correct 40 ms 2616 KB Output is correct
9 Correct 40 ms 2588 KB Output is correct
10 Correct 39 ms 2368 KB Output is correct
11 Correct 38 ms 2624 KB Output is correct
12 Correct 26 ms 2396 KB Output is correct
13 Correct 28 ms 2536 KB Output is correct
14 Correct 29 ms 2536 KB Output is correct
15 Correct 29 ms 2592 KB Output is correct
16 Correct 30 ms 2484 KB Output is correct
17 Correct 38 ms 2612 KB Output is correct
18 Correct 13 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1483 ms 70624 KB Output is correct
2 Correct 1493 ms 70712 KB Output is correct
3 Correct 1425 ms 68160 KB Output is correct
4 Correct 1410 ms 70204 KB Output is correct
5 Correct 1522 ms 71224 KB Output is correct
6 Correct 854 ms 70024 KB Output is correct
7 Correct 1424 ms 67636 KB Output is correct
8 Correct 1462 ms 70712 KB Output is correct
9 Correct 1481 ms 67452 KB Output is correct
10 Correct 1547 ms 69180 KB Output is correct
11 Correct 1416 ms 69952 KB Output is correct
12 Correct 174 ms 26824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1483 ms 70624 KB Output is correct
2 Correct 1493 ms 70712 KB Output is correct
3 Correct 1425 ms 68160 KB Output is correct
4 Correct 1410 ms 70204 KB Output is correct
5 Correct 1522 ms 71224 KB Output is correct
6 Correct 854 ms 70024 KB Output is correct
7 Correct 1424 ms 67636 KB Output is correct
8 Correct 1462 ms 70712 KB Output is correct
9 Correct 1481 ms 67452 KB Output is correct
10 Correct 1547 ms 69180 KB Output is correct
11 Correct 1416 ms 69952 KB Output is correct
12 Correct 174 ms 26824 KB Output is correct
13 Correct 2319 ms 69112 KB Output is correct
14 Correct 2341 ms 76192 KB Output is correct
15 Correct 1427 ms 68916 KB Output is correct
16 Correct 2177 ms 68548 KB Output is correct
17 Correct 2167 ms 67512 KB Output is correct
18 Correct 1216 ms 66428 KB Output is correct
19 Correct 2225 ms 68664 KB Output is correct
20 Correct 2373 ms 68484 KB Output is correct
21 Correct 2272 ms 68916 KB Output is correct
22 Correct 1460 ms 70704 KB Output is correct
23 Correct 1356 ms 70196 KB Output is correct
24 Correct 174 ms 26708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 40 ms 2552 KB Output is correct
8 Correct 40 ms 2616 KB Output is correct
9 Correct 40 ms 2588 KB Output is correct
10 Correct 39 ms 2368 KB Output is correct
11 Correct 38 ms 2624 KB Output is correct
12 Correct 26 ms 2396 KB Output is correct
13 Correct 28 ms 2536 KB Output is correct
14 Correct 29 ms 2536 KB Output is correct
15 Correct 29 ms 2592 KB Output is correct
16 Correct 30 ms 2484 KB Output is correct
17 Correct 38 ms 2612 KB Output is correct
18 Correct 13 ms 2396 KB Output is correct
19 Correct 1483 ms 70624 KB Output is correct
20 Correct 1493 ms 70712 KB Output is correct
21 Correct 1425 ms 68160 KB Output is correct
22 Correct 1410 ms 70204 KB Output is correct
23 Correct 1522 ms 71224 KB Output is correct
24 Correct 854 ms 70024 KB Output is correct
25 Correct 1424 ms 67636 KB Output is correct
26 Correct 1462 ms 70712 KB Output is correct
27 Correct 1481 ms 67452 KB Output is correct
28 Correct 1547 ms 69180 KB Output is correct
29 Correct 1416 ms 69952 KB Output is correct
30 Correct 174 ms 26824 KB Output is correct
31 Correct 2319 ms 69112 KB Output is correct
32 Correct 2341 ms 76192 KB Output is correct
33 Correct 1427 ms 68916 KB Output is correct
34 Correct 2177 ms 68548 KB Output is correct
35 Correct 2167 ms 67512 KB Output is correct
36 Correct 1216 ms 66428 KB Output is correct
37 Correct 2225 ms 68664 KB Output is correct
38 Correct 2373 ms 68484 KB Output is correct
39 Correct 2272 ms 68916 KB Output is correct
40 Correct 1460 ms 70704 KB Output is correct
41 Correct 1356 ms 70196 KB Output is correct
42 Correct 174 ms 26708 KB Output is correct
43 Correct 2332 ms 72428 KB Output is correct
44 Correct 2388 ms 71040 KB Output is correct
45 Correct 2425 ms 77300 KB Output is correct
46 Correct 2381 ms 69764 KB Output is correct
47 Correct 2333 ms 69760 KB Output is correct
48 Correct 1301 ms 67460 KB Output is correct
49 Correct 2530 ms 77516 KB Output is correct
50 Correct 2420 ms 72232 KB Output is correct
51 Correct 2520 ms 76788 KB Output is correct
52 Correct 2324 ms 70444 KB Output is correct
53 Correct 1486 ms 72152 KB Output is correct