Submission #715882

# Submission time Handle Problem Language Result Execution time Memory
715882 2023-03-28T10:01:30 Z ismayil Examination (JOI19_examination) C++17
43 / 100
617 ms 75040 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAX = 2e5;
struct fenwick_tree{
    int bit[MAX + 1] = {0};
    void update(int pos, int val){
        for(int i = pos; i <= MAX; i = i | (i + 1)){
            bit[i] += val;
        }
    }
    int query(int pos){
        int res = 0;
        for(int i = pos; i >= 0; i = (i & (i + 1)) - 1){
            res += bit[i];
        }
        return res;
    }
    int query(int l, int r){
        if(l == 0) return query(r);
        return query(r) - query(l - 1);
    }
};
struct event{
    int x, y, z, idx, type;
    bool operator<(event other){
        if(z == other.z) return type < other.type;
        return z > other.z;
    }
};
int n, m;
void solve(){
    vector<event> events;
    map<int, int> mm;
    for(int i = 0; i < n; i++){
        int x, y;
        cin>>x>>y;
        mm[x]; mm[y];
        events.push_back({x, y, x + y, -1, 0});
    }
    for(int i = 0; i < m; i++){
        int x, y, z;
        cin>>x>>y>>z;
        mm[x]; mm[y];
        events.push_back({x, y, max(x + y, z), i, 1});
    }
    int idx = 0;
    for(auto& i : mm) i.second = idx++;
    sort(events.begin(), events.end());
    int ans[m];
    fenwick_tree X, Y;
    int cnt = 0;
    for (auto i : events)
    {
        if(i.type == 0){
            Y.update(mm[i.y], 1);
            X.update(mm[i.x], 1);
            cnt++;
        }else{
            ans[i.idx] = Y.query(mm[i.y], MAX) + X.query(mm[i.x], MAX) - cnt;
        }
    }
    for (int i = 0; i < m; i++) cout<<ans[i]<<endl;
}
signed main(){
    
    cin>>n>>m;
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 2 ms 3412 KB Output is correct
3 Correct 2 ms 3412 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Correct 2 ms 3412 KB Output is correct
6 Correct 2 ms 3428 KB Output is correct
7 Correct 19 ms 4464 KB Output is correct
8 Correct 19 ms 4416 KB Output is correct
9 Correct 21 ms 4400 KB Output is correct
10 Correct 12 ms 4056 KB Output is correct
11 Correct 14 ms 4028 KB Output is correct
12 Correct 9 ms 3892 KB Output is correct
13 Correct 18 ms 4380 KB Output is correct
14 Correct 17 ms 4468 KB Output is correct
15 Correct 18 ms 4400 KB Output is correct
16 Correct 12 ms 4016 KB Output is correct
17 Correct 16 ms 4056 KB Output is correct
18 Correct 8 ms 3764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 549 ms 19448 KB Output is correct
2 Correct 552 ms 19520 KB Output is correct
3 Correct 514 ms 19400 KB Output is correct
4 Correct 348 ms 18252 KB Output is correct
5 Correct 348 ms 18220 KB Output is correct
6 Correct 218 ms 13752 KB Output is correct
7 Correct 482 ms 19308 KB Output is correct
8 Correct 498 ms 19376 KB Output is correct
9 Correct 436 ms 19232 KB Output is correct
10 Correct 315 ms 18256 KB Output is correct
11 Correct 339 ms 18248 KB Output is correct
12 Correct 209 ms 13808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 549 ms 19448 KB Output is correct
2 Correct 552 ms 19520 KB Output is correct
3 Correct 514 ms 19400 KB Output is correct
4 Correct 348 ms 18252 KB Output is correct
5 Correct 348 ms 18220 KB Output is correct
6 Correct 218 ms 13752 KB Output is correct
7 Correct 482 ms 19308 KB Output is correct
8 Correct 498 ms 19376 KB Output is correct
9 Correct 436 ms 19232 KB Output is correct
10 Correct 315 ms 18256 KB Output is correct
11 Correct 339 ms 18248 KB Output is correct
12 Correct 209 ms 13808 KB Output is correct
13 Correct 543 ms 19376 KB Output is correct
14 Correct 525 ms 19424 KB Output is correct
15 Correct 508 ms 19416 KB Output is correct
16 Correct 369 ms 18236 KB Output is correct
17 Correct 364 ms 18236 KB Output is correct
18 Correct 221 ms 13744 KB Output is correct
19 Correct 505 ms 19484 KB Output is correct
20 Correct 560 ms 19388 KB Output is correct
21 Correct 617 ms 19276 KB Output is correct
22 Correct 353 ms 18188 KB Output is correct
23 Correct 385 ms 18320 KB Output is correct
24 Correct 213 ms 13740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 2 ms 3412 KB Output is correct
3 Correct 2 ms 3412 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Correct 2 ms 3412 KB Output is correct
6 Correct 2 ms 3428 KB Output is correct
7 Correct 19 ms 4464 KB Output is correct
8 Correct 19 ms 4416 KB Output is correct
9 Correct 21 ms 4400 KB Output is correct
10 Correct 12 ms 4056 KB Output is correct
11 Correct 14 ms 4028 KB Output is correct
12 Correct 9 ms 3892 KB Output is correct
13 Correct 18 ms 4380 KB Output is correct
14 Correct 17 ms 4468 KB Output is correct
15 Correct 18 ms 4400 KB Output is correct
16 Correct 12 ms 4016 KB Output is correct
17 Correct 16 ms 4056 KB Output is correct
18 Correct 8 ms 3764 KB Output is correct
19 Correct 549 ms 19448 KB Output is correct
20 Correct 552 ms 19520 KB Output is correct
21 Correct 514 ms 19400 KB Output is correct
22 Correct 348 ms 18252 KB Output is correct
23 Correct 348 ms 18220 KB Output is correct
24 Correct 218 ms 13752 KB Output is correct
25 Correct 482 ms 19308 KB Output is correct
26 Correct 498 ms 19376 KB Output is correct
27 Correct 436 ms 19232 KB Output is correct
28 Correct 315 ms 18256 KB Output is correct
29 Correct 339 ms 18248 KB Output is correct
30 Correct 209 ms 13808 KB Output is correct
31 Correct 543 ms 19376 KB Output is correct
32 Correct 525 ms 19424 KB Output is correct
33 Correct 508 ms 19416 KB Output is correct
34 Correct 369 ms 18236 KB Output is correct
35 Correct 364 ms 18236 KB Output is correct
36 Correct 221 ms 13744 KB Output is correct
37 Correct 505 ms 19484 KB Output is correct
38 Correct 560 ms 19388 KB Output is correct
39 Correct 617 ms 19276 KB Output is correct
40 Correct 353 ms 18188 KB Output is correct
41 Correct 385 ms 18320 KB Output is correct
42 Correct 213 ms 13740 KB Output is correct
43 Runtime error 551 ms 75040 KB Execution killed with signal 11
44 Halted 0 ms 0 KB -