답안 #1060705

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1060705 2024-08-15T20:59:56 Z oscar1f Examination (JOI19_examination) C++17
100 / 100
1602 ms 142860 KB
#include<bits/stdc++.h>
using namespace std;

#define int long long

const int TAILLE_MAX=100*1000+5,DECA=(1<<18);
int nbPers,nbReq,idRes1;
vector<tuple<int,int,int,int>> ordreParc;
set<int> listeRes1;
unordered_map<int,int> corres1;
vector<pair<int,int>> listeEvent[2*DECA];
int interCouv[2*DECA][2];
int arbreSom[2*DECA];
int rep[TAILLE_MAX];

void ajout(int pos,int val) {
    pos+=DECA;
    while (pos>0) {
        listeEvent[pos].push_back({val,TAILLE_MAX});
        pos/=2;
    }
}

void quest(int pos,int posQuest,int valQuest,int idQuest) {
    if (interCouv[pos][0]>=idRes1 or interCouv[pos][1]<posQuest) {
        return;
    }
    else if (interCouv[pos][0]>=posQuest and interCouv[pos][1]<idRes1) {
        listeEvent[pos].push_back({valQuest,idQuest});
        //cout<<pos<<" ";
    }
    else {
        quest(2*pos,posQuest,valQuest,idQuest);
        quest(2*pos+1,posQuest,valQuest,idQuest);
    }
}

void ajoutSom(int pos) {
    while (pos>0) {
        arbreSom[pos]++;
        pos/=2;
    }
}

int calcSom(int deb,int fin) {
    if (deb==fin) {
        return arbreSom[deb];
    }
    if (deb%2==1) {
        return arbreSom[deb]+calcSom(deb+1,fin);
    }
    if (fin%2==0) {
        return arbreSom[fin]+calcSom(deb,fin-1);
    }
    return calcSom(deb/2,fin/2);
}

void calc(int pos) {
    if (listeEvent[pos].empty()) {
        return;
    }
    set<int> listeRes2;
    unordered_map<int,int> corres2;
    int idRes2=0,decal=1;
    //cout<<pos<<endl;
    for (auto i:listeEvent[pos]) {
        //cout<<i.first<<" "<<i.second<<endl;
        listeRes2.insert(i.first);
    }
    for (int i:listeRes2) {
        corres2[i]=idRes2;
        idRes2++;
    }
    while (decal<idRes2) {
        decal*=2;
    }
    for (int i=1;i<2*decal;i++) {
        arbreSom[i]=0;
    }
    for (auto i:listeEvent[pos]) {
        if (i.second==TAILLE_MAX) {
            ajoutSom(corres2[i.first]+decal);
        }
        else {
            //cout<<"!"<<i.first<<" "<<i.second<<" : "<<calcSom(decal+corres2[i.first],decal+idRes2-1)<<endl;
            rep[i.second]+=calcSom(decal+corres2[i.first],decal+idRes2-1);
        }
    }
    //cout<<endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    for (int i=0;i<DECA;i++) {
        interCouv[DECA+i][0]=i;
        interCouv[DECA+i][1]=i;
    }
    for (int i=DECA-1;i>0;i--) {
        interCouv[i][0]=interCouv[2*i][0];
        interCouv[i][1]=interCouv[2*i+1][1];
    }
    cin>>nbPers>>nbReq;
    int res1,res2,resTot,typeReq;
    for (int i=0;i<nbPers;i++) {
        cin>>res1>>res2;
        ordreParc.push_back(make_tuple(res1+res2,TAILLE_MAX,res1,res2));
        listeRes1.insert(res1);
    }    
    for (int i=0;i<nbReq;i++) {
        cin>>res1>>res2>>resTot;
        ordreParc.push_back(make_tuple(resTot,i,res1,res2));
        listeRes1.insert(res1);
    }
    sort(ordreParc.begin(),ordreParc.end());
    reverse(ordreParc.begin(),ordreParc.end());
    for (int i:listeRes1) {
        corres1[i]=idRes1;
        //cout<<i<<" "<<idRes1<<endl;
        idRes1++;
    }
    /*for (int i=1;i<2*DECA;i++) {
        cout<<i<<" : "<<interCouv[i][0]<<" "<<interCouv[i][1]<<endl;
    }*/
    for (auto i:ordreParc) {
        resTot=get<0>(i);
        typeReq=get<1>(i);
        res1=get<2>(i);
        res2=get<3>(i);
        //cout<<resTot<<" "<<typeReq<<" "<<res1<<" "<<res2<<" : ";
        if (typeReq==TAILLE_MAX) {
            ajout(corres1[res1],res2);
        }
        else {
            //cout<<"?"<<corres1[res1]<<" ";
            quest(1,corres1[res1],res2,typeReq);
        }
        //cout<<endl;
    }
    for (int i=0;i<2*DECA;i++) {
        calc(i);
    }
    for (int i=0;i<nbReq;i++) {
        cout<<rep[i]<<"\n";
    }
    return 0;
}
 
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 23644 KB Output is correct
2 Correct 5 ms 23632 KB Output is correct
3 Correct 5 ms 23892 KB Output is correct
4 Correct 5 ms 23644 KB Output is correct
5 Correct 5 ms 23660 KB Output is correct
6 Correct 5 ms 23644 KB Output is correct
7 Correct 28 ms 26764 KB Output is correct
8 Correct 28 ms 26584 KB Output is correct
9 Correct 30 ms 26584 KB Output is correct
10 Correct 17 ms 26328 KB Output is correct
11 Correct 19 ms 25520 KB Output is correct
12 Correct 9 ms 25056 KB Output is correct
13 Correct 27 ms 26596 KB Output is correct
14 Correct 28 ms 26580 KB Output is correct
15 Correct 28 ms 26580 KB Output is correct
16 Correct 18 ms 25308 KB Output is correct
17 Correct 14 ms 26324 KB Output is correct
18 Correct 9 ms 25056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1102 ms 116204 KB Output is correct
2 Correct 1110 ms 116592 KB Output is correct
3 Correct 1095 ms 113332 KB Output is correct
4 Correct 437 ms 114828 KB Output is correct
5 Correct 481 ms 87220 KB Output is correct
6 Correct 122 ms 78008 KB Output is correct
7 Correct 1218 ms 113840 KB Output is correct
8 Correct 1014 ms 115780 KB Output is correct
9 Correct 1040 ms 112556 KB Output is correct
10 Correct 418 ms 79616 KB Output is correct
11 Correct 318 ms 111020 KB Output is correct
12 Correct 93 ms 78008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1102 ms 116204 KB Output is correct
2 Correct 1110 ms 116592 KB Output is correct
3 Correct 1095 ms 113332 KB Output is correct
4 Correct 437 ms 114828 KB Output is correct
5 Correct 481 ms 87220 KB Output is correct
6 Correct 122 ms 78008 KB Output is correct
7 Correct 1218 ms 113840 KB Output is correct
8 Correct 1014 ms 115780 KB Output is correct
9 Correct 1040 ms 112556 KB Output is correct
10 Correct 418 ms 79616 KB Output is correct
11 Correct 318 ms 111020 KB Output is correct
12 Correct 93 ms 78008 KB Output is correct
13 Correct 1234 ms 118960 KB Output is correct
14 Correct 1326 ms 121040 KB Output is correct
15 Correct 1112 ms 118540 KB Output is correct
16 Correct 426 ms 114604 KB Output is correct
17 Correct 527 ms 83892 KB Output is correct
18 Correct 128 ms 75448 KB Output is correct
19 Correct 1090 ms 114088 KB Output is correct
20 Correct 1158 ms 117272 KB Output is correct
21 Correct 1155 ms 113548 KB Output is correct
22 Correct 417 ms 79288 KB Output is correct
23 Correct 304 ms 112560 KB Output is correct
24 Correct 96 ms 72116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 23644 KB Output is correct
2 Correct 5 ms 23632 KB Output is correct
3 Correct 5 ms 23892 KB Output is correct
4 Correct 5 ms 23644 KB Output is correct
5 Correct 5 ms 23660 KB Output is correct
6 Correct 5 ms 23644 KB Output is correct
7 Correct 28 ms 26764 KB Output is correct
8 Correct 28 ms 26584 KB Output is correct
9 Correct 30 ms 26584 KB Output is correct
10 Correct 17 ms 26328 KB Output is correct
11 Correct 19 ms 25520 KB Output is correct
12 Correct 9 ms 25056 KB Output is correct
13 Correct 27 ms 26596 KB Output is correct
14 Correct 28 ms 26580 KB Output is correct
15 Correct 28 ms 26580 KB Output is correct
16 Correct 18 ms 25308 KB Output is correct
17 Correct 14 ms 26324 KB Output is correct
18 Correct 9 ms 25056 KB Output is correct
19 Correct 1102 ms 116204 KB Output is correct
20 Correct 1110 ms 116592 KB Output is correct
21 Correct 1095 ms 113332 KB Output is correct
22 Correct 437 ms 114828 KB Output is correct
23 Correct 481 ms 87220 KB Output is correct
24 Correct 122 ms 78008 KB Output is correct
25 Correct 1218 ms 113840 KB Output is correct
26 Correct 1014 ms 115780 KB Output is correct
27 Correct 1040 ms 112556 KB Output is correct
28 Correct 418 ms 79616 KB Output is correct
29 Correct 318 ms 111020 KB Output is correct
30 Correct 93 ms 78008 KB Output is correct
31 Correct 1234 ms 118960 KB Output is correct
32 Correct 1326 ms 121040 KB Output is correct
33 Correct 1112 ms 118540 KB Output is correct
34 Correct 426 ms 114604 KB Output is correct
35 Correct 527 ms 83892 KB Output is correct
36 Correct 128 ms 75448 KB Output is correct
37 Correct 1090 ms 114088 KB Output is correct
38 Correct 1158 ms 117272 KB Output is correct
39 Correct 1155 ms 113548 KB Output is correct
40 Correct 417 ms 79288 KB Output is correct
41 Correct 304 ms 112560 KB Output is correct
42 Correct 96 ms 72116 KB Output is correct
43 Correct 1399 ms 135068 KB Output is correct
44 Correct 1419 ms 136876 KB Output is correct
45 Correct 1382 ms 138160 KB Output is correct
46 Correct 565 ms 125104 KB Output is correct
47 Correct 782 ms 88244 KB Output is correct
48 Correct 133 ms 75036 KB Output is correct
49 Correct 1602 ms 142860 KB Output is correct
50 Correct 1336 ms 135596 KB Output is correct
51 Correct 1579 ms 142216 KB Output is correct
52 Correct 678 ms 86736 KB Output is correct
53 Correct 443 ms 126124 KB Output is correct