Submission #997847

# Submission time Handle Problem Language Result Execution time Memory
997847 2024-06-13T03:16:22 Z vjudge1 Examination (JOI19_examination) C++17
100 / 100
2742 ms 73732 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 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 356 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 344 KB Output is correct
7 Correct 43 ms 2344 KB Output is correct
8 Correct 40 ms 2336 KB Output is correct
9 Correct 41 ms 2512 KB Output is correct
10 Correct 40 ms 2500 KB Output is correct
11 Correct 38 ms 2364 KB Output is correct
12 Correct 26 ms 2316 KB Output is correct
13 Correct 29 ms 2280 KB Output is correct
14 Correct 28 ms 2476 KB Output is correct
15 Correct 29 ms 2280 KB Output is correct
16 Correct 28 ms 2428 KB Output is correct
17 Correct 38 ms 2368 KB Output is correct
18 Correct 13 ms 2252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1519 ms 68240 KB Output is correct
2 Correct 1535 ms 68408 KB Output is correct
3 Correct 1535 ms 65704 KB Output is correct
4 Correct 1501 ms 68412 KB Output is correct
5 Correct 1525 ms 69176 KB Output is correct
6 Correct 890 ms 67904 KB Output is correct
7 Correct 1477 ms 66356 KB Output is correct
8 Correct 1496 ms 68404 KB Output is correct
9 Correct 1527 ms 65996 KB Output is correct
10 Correct 1499 ms 67504 KB Output is correct
11 Correct 1493 ms 69688 KB Output is correct
12 Correct 175 ms 25756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1519 ms 68240 KB Output is correct
2 Correct 1535 ms 68408 KB Output is correct
3 Correct 1535 ms 65704 KB Output is correct
4 Correct 1501 ms 68412 KB Output is correct
5 Correct 1525 ms 69176 KB Output is correct
6 Correct 890 ms 67904 KB Output is correct
7 Correct 1477 ms 66356 KB Output is correct
8 Correct 1496 ms 68404 KB Output is correct
9 Correct 1527 ms 65996 KB Output is correct
10 Correct 1499 ms 67504 KB Output is correct
11 Correct 1493 ms 69688 KB Output is correct
12 Correct 175 ms 25756 KB Output is correct
13 Correct 2742 ms 65720 KB Output is correct
14 Correct 2455 ms 70652 KB Output is correct
15 Correct 1425 ms 65716 KB Output is correct
16 Correct 2232 ms 65680 KB Output is correct
17 Correct 2206 ms 65248 KB Output is correct
18 Correct 1244 ms 65424 KB Output is correct
19 Correct 2335 ms 67160 KB Output is correct
20 Correct 2366 ms 67548 KB Output is correct
21 Correct 2376 ms 66148 KB Output is correct
22 Correct 1537 ms 67896 KB Output is correct
23 Correct 1410 ms 69176 KB Output is correct
24 Correct 210 ms 25756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 356 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 344 KB Output is correct
7 Correct 43 ms 2344 KB Output is correct
8 Correct 40 ms 2336 KB Output is correct
9 Correct 41 ms 2512 KB Output is correct
10 Correct 40 ms 2500 KB Output is correct
11 Correct 38 ms 2364 KB Output is correct
12 Correct 26 ms 2316 KB Output is correct
13 Correct 29 ms 2280 KB Output is correct
14 Correct 28 ms 2476 KB Output is correct
15 Correct 29 ms 2280 KB Output is correct
16 Correct 28 ms 2428 KB Output is correct
17 Correct 38 ms 2368 KB Output is correct
18 Correct 13 ms 2252 KB Output is correct
19 Correct 1519 ms 68240 KB Output is correct
20 Correct 1535 ms 68408 KB Output is correct
21 Correct 1535 ms 65704 KB Output is correct
22 Correct 1501 ms 68412 KB Output is correct
23 Correct 1525 ms 69176 KB Output is correct
24 Correct 890 ms 67904 KB Output is correct
25 Correct 1477 ms 66356 KB Output is correct
26 Correct 1496 ms 68404 KB Output is correct
27 Correct 1527 ms 65996 KB Output is correct
28 Correct 1499 ms 67504 KB Output is correct
29 Correct 1493 ms 69688 KB Output is correct
30 Correct 175 ms 25756 KB Output is correct
31 Correct 2742 ms 65720 KB Output is correct
32 Correct 2455 ms 70652 KB Output is correct
33 Correct 1425 ms 65716 KB Output is correct
34 Correct 2232 ms 65680 KB Output is correct
35 Correct 2206 ms 65248 KB Output is correct
36 Correct 1244 ms 65424 KB Output is correct
37 Correct 2335 ms 67160 KB Output is correct
38 Correct 2366 ms 67548 KB Output is correct
39 Correct 2376 ms 66148 KB Output is correct
40 Correct 1537 ms 67896 KB Output is correct
41 Correct 1410 ms 69176 KB Output is correct
42 Correct 210 ms 25756 KB Output is correct
43 Correct 2460 ms 66056 KB Output is correct
44 Correct 2462 ms 65996 KB Output is correct
45 Correct 2610 ms 73732 KB Output is correct
46 Correct 2385 ms 67352 KB Output is correct
47 Correct 2383 ms 66408 KB Output is correct
48 Correct 1325 ms 65436 KB Output is correct
49 Correct 2580 ms 72236 KB Output is correct
50 Correct 2432 ms 66228 KB Output is correct
51 Correct 2609 ms 71156 KB Output is correct
52 Correct 2327 ms 66268 KB Output is correct
53 Correct 1394 ms 69212 KB Output is correct