답안 #964445

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
964445 2024-04-16T22:18:28 Z Unforgettablepl Examination (JOI19_examination) C++17
100 / 100
256 ms 27528 KB
#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<pair<int,int>,null_type,less<>,rb_tree_tag,tree_order_statistics_node_update> orderedset;

#define int long long

struct fenwick{
    int n;vector<int> tree;
    fenwick(int n):n(n+1),tree(n+2){}
    int get(int x){
        int ans = 0;
        x++;
        while(x){
            ans+=tree[x];
            x-=x&-x;
        }
        return ans;
    }
    void add(int x){
        x++;
        while(x<=n){
            tree[x]++;
            x+=x&-x;
        }
    }
};

int ans[100001];

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,q;
    cin >> n >> q;
    vector<pair<int,int>> students1;
    vector<tuple<int,int,int>> students2;
    for(int i=1;i<=n;i++){
        int x,y;cin>>x>>y;
        students1.emplace_back(x,y);
        students2.emplace_back(x+y,x,y);
    }
    vector<tuple<int,int,int>> queries1;
    vector<tuple<int,int,int,int>> queries2;
    for(int i=1;i<=q;i++){
        int a,b,c;cin>>a>>b>>c;
        if(a+b>=c)queries1.emplace_back(a,b,i);
        else queries2.emplace_back(c,a,b,i);
    }
    sort(queries1.rbegin(),queries1.rend());
    sort(queries2.rbegin(),queries2.rend());
    sort(students1.rbegin(),students1.rend());
    sort(students2.rbegin(),students2.rend());
    auto iter = students1.begin();
    orderedset f1;
    orderedset f2;
    int uid = 0;
    int curradded = 0;
    for(auto[a,b,idx]:queries1){
        while(iter!=students1.end() and iter->first>=a){
            f1.insert({iter->second,++uid});
            iter++;
            curradded++;
        }
        ans[idx] = curradded-f1.order_of_key({b,0});
    }
    f1.clear();
    auto iter2 = students2.begin();
    curradded=0;
    for(auto[c,a,b,idx]:queries2){
        while(iter2!=students2.end() and get<0>(*iter2)>=c){
            f1.insert({get<1>(*iter2),++uid});
            f2.insert({get<2>(*iter2),++uid});
            iter2++;
            curradded++;
        }
        ans[idx] = curradded-f1.order_of_key({a,0})-f2.order_of_key({b,0});
    }
    for(int i=1;i<=q;i++)cout<<ans[i]<<'\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 4 ms 1020 KB Output is correct
8 Correct 4 ms 860 KB Output is correct
9 Correct 6 ms 860 KB Output is correct
10 Correct 4 ms 860 KB Output is correct
11 Correct 4 ms 1116 KB Output is correct
12 Correct 4 ms 984 KB Output is correct
13 Correct 3 ms 860 KB Output is correct
14 Correct 3 ms 860 KB Output is correct
15 Correct 3 ms 856 KB Output is correct
16 Correct 3 ms 920 KB Output is correct
17 Correct 4 ms 1116 KB Output is correct
18 Correct 2 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 119 ms 14628 KB Output is correct
2 Correct 114 ms 14272 KB Output is correct
3 Correct 109 ms 14268 KB Output is correct
4 Correct 96 ms 14296 KB Output is correct
5 Correct 87 ms 14244 KB Output is correct
6 Correct 77 ms 14268 KB Output is correct
7 Correct 123 ms 14304 KB Output is correct
8 Correct 105 ms 14696 KB Output is correct
9 Correct 103 ms 14980 KB Output is correct
10 Correct 79 ms 14492 KB Output is correct
11 Correct 147 ms 13916 KB Output is correct
12 Correct 125 ms 14264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 119 ms 14628 KB Output is correct
2 Correct 114 ms 14272 KB Output is correct
3 Correct 109 ms 14268 KB Output is correct
4 Correct 96 ms 14296 KB Output is correct
5 Correct 87 ms 14244 KB Output is correct
6 Correct 77 ms 14268 KB Output is correct
7 Correct 123 ms 14304 KB Output is correct
8 Correct 105 ms 14696 KB Output is correct
9 Correct 103 ms 14980 KB Output is correct
10 Correct 79 ms 14492 KB Output is correct
11 Correct 147 ms 13916 KB Output is correct
12 Correct 125 ms 14264 KB Output is correct
13 Correct 212 ms 20808 KB Output is correct
14 Correct 203 ms 21120 KB Output is correct
15 Correct 115 ms 14284 KB Output is correct
16 Correct 181 ms 20800 KB Output is correct
17 Correct 159 ms 21072 KB Output is correct
18 Correct 148 ms 21220 KB Output is correct
19 Correct 197 ms 21636 KB Output is correct
20 Correct 216 ms 21664 KB Output is correct
21 Correct 210 ms 21520 KB Output is correct
22 Correct 86 ms 14040 KB Output is correct
23 Correct 148 ms 14032 KB Output is correct
24 Correct 114 ms 14052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 4 ms 1020 KB Output is correct
8 Correct 4 ms 860 KB Output is correct
9 Correct 6 ms 860 KB Output is correct
10 Correct 4 ms 860 KB Output is correct
11 Correct 4 ms 1116 KB Output is correct
12 Correct 4 ms 984 KB Output is correct
13 Correct 3 ms 860 KB Output is correct
14 Correct 3 ms 860 KB Output is correct
15 Correct 3 ms 856 KB Output is correct
16 Correct 3 ms 920 KB Output is correct
17 Correct 4 ms 1116 KB Output is correct
18 Correct 2 ms 768 KB Output is correct
19 Correct 119 ms 14628 KB Output is correct
20 Correct 114 ms 14272 KB Output is correct
21 Correct 109 ms 14268 KB Output is correct
22 Correct 96 ms 14296 KB Output is correct
23 Correct 87 ms 14244 KB Output is correct
24 Correct 77 ms 14268 KB Output is correct
25 Correct 123 ms 14304 KB Output is correct
26 Correct 105 ms 14696 KB Output is correct
27 Correct 103 ms 14980 KB Output is correct
28 Correct 79 ms 14492 KB Output is correct
29 Correct 147 ms 13916 KB Output is correct
30 Correct 125 ms 14264 KB Output is correct
31 Correct 212 ms 20808 KB Output is correct
32 Correct 203 ms 21120 KB Output is correct
33 Correct 115 ms 14284 KB Output is correct
34 Correct 181 ms 20800 KB Output is correct
35 Correct 159 ms 21072 KB Output is correct
36 Correct 148 ms 21220 KB Output is correct
37 Correct 197 ms 21636 KB Output is correct
38 Correct 216 ms 21664 KB Output is correct
39 Correct 210 ms 21520 KB Output is correct
40 Correct 86 ms 14040 KB Output is correct
41 Correct 148 ms 14032 KB Output is correct
42 Correct 114 ms 14052 KB Output is correct
43 Correct 256 ms 25992 KB Output is correct
44 Correct 202 ms 25992 KB Output is correct
45 Correct 212 ms 26656 KB Output is correct
46 Correct 211 ms 24680 KB Output is correct
47 Correct 200 ms 24312 KB Output is correct
48 Correct 159 ms 22900 KB Output is correct
49 Correct 239 ms 26336 KB Output is correct
50 Correct 242 ms 27528 KB Output is correct
51 Correct 235 ms 26032 KB Output is correct
52 Correct 255 ms 24032 KB Output is correct
53 Correct 155 ms 17092 KB Output is correct