답안 #964441

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

#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();
    fenwick f1(100000);
    fenwick f2(100000);
    int curradded = 0;
    for(auto[a,b,idx]:queries1){
        while(iter!=students1.end() and iter->first>=a){
            f1.add(iter->second);
            iter++;
            curradded++;
        }
        ans[idx] = curradded-f1.get(b-1);
    }
    for(int&i:f1.tree)i=0;
    auto iter2 = students2.begin();
    curradded=0;
    for(auto[c,a,b,idx]:queries2){
        while(iter2!=students2.end() and get<0>(*iter2)>=c){
            f1.add(get<1>(*iter2));
            f2.add(get<2>(*iter2));
            iter2++;
            curradded++;
        }
        ans[idx] = curradded-f1.get(a-1)-f2.get(b-1);
    }
    for(int i=1;i<=q;i++)cout<<ans[i]<<'\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1884 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Runtime error 2 ms 3676 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 9976 KB Output is correct
2 Correct 62 ms 9668 KB Output is correct
3 Correct 73 ms 9924 KB Output is correct
4 Correct 59 ms 9636 KB Output is correct
5 Correct 68 ms 10668 KB Output is correct
6 Correct 59 ms 9396 KB Output is correct
7 Correct 73 ms 9812 KB Output is correct
8 Correct 61 ms 10160 KB Output is correct
9 Correct 64 ms 9860 KB Output is correct
10 Correct 58 ms 10068 KB Output is correct
11 Correct 58 ms 9284 KB Output is correct
12 Correct 44 ms 9556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 9976 KB Output is correct
2 Correct 62 ms 9668 KB Output is correct
3 Correct 73 ms 9924 KB Output is correct
4 Correct 59 ms 9636 KB Output is correct
5 Correct 68 ms 10668 KB Output is correct
6 Correct 59 ms 9396 KB Output is correct
7 Correct 73 ms 9812 KB Output is correct
8 Correct 61 ms 10160 KB Output is correct
9 Correct 64 ms 9860 KB Output is correct
10 Correct 58 ms 10068 KB Output is correct
11 Correct 58 ms 9284 KB Output is correct
12 Correct 44 ms 9556 KB Output is correct
13 Correct 77 ms 10820 KB Output is correct
14 Correct 71 ms 10868 KB Output is correct
15 Correct 62 ms 9924 KB Output is correct
16 Correct 68 ms 10236 KB Output is correct
17 Correct 72 ms 10660 KB Output is correct
18 Correct 65 ms 11024 KB Output is correct
19 Correct 85 ms 11768 KB Output is correct
20 Correct 74 ms 11528 KB Output is correct
21 Correct 74 ms 11384 KB Output is correct
22 Correct 59 ms 9408 KB Output is correct
23 Correct 58 ms 9660 KB Output is correct
24 Correct 44 ms 9356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1884 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Runtime error 2 ms 3676 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -