이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
const int TAILLEMAXI=100*1000+2,INFINI=1000*1000*1000+2,LOGMAXI=19;
int nbcercles,nbquestions,val,noeud,ajouter,contenance,numcercle;
int peres[TAILLEMAXI][LOGMAXI],cumu[TAILLEMAXI];
vector<int> enfant[TAILLEMAXI];
deque<pair<int,int>> encours;
set<pair<int,int>> atrouver;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>nbcercles>>nbquestions;
cumu[0]=INFINI;
for (int icercle=1;icercle<=nbcercles;icercle++){
cin>>val>>contenance;
atrouver.insert(make_pair(val,icercle));
while ((*(atrouver.begin())).first<val){
enfant[icercle].push_back((*(atrouver.begin())).second);
peres[(*(atrouver.begin())).second][0]=icercle;
atrouver.erase(atrouver.begin());
}
cumu[icercle]=contenance;
}
while ((int)atrouver.size()!=0){
peres[(*(atrouver.begin())).second][0]=0;
enfant[0].push_back((*(atrouver.begin())).second);
atrouver.erase(atrouver.begin());
}
encours.push_back(make_pair(0,0));
while ((int)encours.size()!=0){
noeud=encours.front().first;
ajouter=encours.front().second;
encours.pop_front();
cumu[noeud]+=ajouter;
for (int ienfant=0;ienfant<enfant[noeud].size();ienfant++){
encours.push_back(make_pair(enfant[noeud][ienfant],cumu[noeud]));
}
}
/*for (int isommet=1;isommet<=nbcercles;isommet++){
cout<<cumu[isommet]<<" "<<peres[isommet]<<endl;
}*/
for (int ilog=1;ilog<LOGMAXI;ilog++){
for (int isommet=1;isommet<=nbcercles;isommet++){
peres[isommet][ilog]=peres[peres[isommet][ilog-1]][ilog-1];
}
}
for (int iquestion=0;iquestion<nbquestions;iquestion++){
cin>>numcercle>>contenance;
for (int ilog=LOGMAXI-1;ilog>=0;ilog--){
if (cumu[numcercle]-cumu[peres[numcercle][ilog]]<contenance){
contenance-=cumu[numcercle]-cumu[peres[numcercle][ilog]];
numcercle=peres[numcercle][ilog];
}
}
cout<<numcercle<<endl;
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
fountain.cpp: In function 'int main()':
fountain.cpp:41:35: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for (int ienfant=0;ienfant<enfant[noeud].size();ienfant++){
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |