이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
int nbEleves, nbReqs;
struct Req {
int lig, col, id;
bool type;
Req(int _lig = 0, int _col = 0, int _id = 0, bool _type = false) {
lig = _lig;
col = _col;
id = _id;
type = _type;
}
};
bool operator < (const Req& a, const Req &b) {
if(a.col == b.col)
return a.type < b.type;
return a.col > b.col;
}
vector<int> arbre;
void ajoute(int pos, int val) {
pos += (1 << 17);
while(pos != 0) {
arbre[pos] += val;
pos /= 2;
}
}
int nbInter(int deb, int fin) {
deb += (1 << 17);
fin += (1 << 17);
int somme = 0;
while(deb < fin) {
if(deb % 2 == 1) {
somme += arbre[deb];
deb++;
}
if(fin % 2 == 1) {
fin--;
somme += arbre[fin];
}
deb /= 2;
fin /= 2;
}
return somme;
}
vector<int> nombreHautDroite(vector<Req> reqs) {
sort(reqs.begin(), reqs.end());
map<int, int> indexes;
for(Req& req : reqs) {
indexes[req.lig] = 0;
}
int id = 0;
for(auto it = indexes.begin();it != indexes.end();it++) {
it->second = id;
id++;
}
for(Req& req : reqs) {
req.lig = indexes[req.lig];
}
vector<int> reponses(nbReqs, 0);
arbre = vector<int>((1 << 18), 0);
for(Req& req : reqs) {
if(req.type) {
reponses[req.id] = nbInter(req.lig, (1 << 17) - 1);
}
else {
ajoute(req.lig, 1);
}
}
return reponses;
}
int main() {
ios_base::sync_with_stdio(false);
cin >> nbEleves >> nbReqs;
vector<Req> ajoutes, enleves, quarts;
for(int iEleve = 0;iEleve < nbEleves;iEleve++) {
int maths, info;
cin >> maths >> info;
ajoutes.push_back(Req(maths, maths + info, iEleve, false));
enleves.push_back(Req(-info, maths + info, iEleve, false));
quarts.push_back(Req(maths, info, iEleve, false));
}
for(int iReq = 0;iReq < nbReqs;iReq++) {
int maths, info, total;
cin >> maths >> info >> total;
if(maths + info < total) {
ajoutes.push_back(Req(maths, total, iReq, true));
enleves.push_back(Req(-info + 1, total, iReq, true));
}
else {
quarts.push_back(Req(maths, info, iReq, true));
}
}
vector<int> positifs = nombreHautDroite(ajoutes);
vector<int> negatifs = nombreHautDroite(enleves);
vector<int> autres = nombreHautDroite(quarts);
for(int iReq = 0;iReq < nbReqs;iReq++) {
cout << autres[iReq] + positifs[iReq] - negatifs[iReq] << endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |